本文整理汇总了Python中pootle.core.models.Revision.get方法的典型用法代码示例。如果您正苦于以下问题:Python Revision.get方法的具体用法?Python Revision.get怎么用?Python Revision.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pootle.core.models.Revision
的用法示例。
在下文中一共展示了Revision.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_set_last_sync_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_set_last_sync_revision(project0_nongnu, tp0, store0, test_fs):
"""Tests setting last_sync_revision after store creation.
"""
unit = store0.units.first()
unit.target = "UPDATED TARGET"
unit.save()
store0.sync()
# Store is already parsed and store.last_sync_revision should be equal to
# max unit revision
assert store0.last_sync_revision == store0.get_max_unit_revision()
# store.last_sync_revision is not changed after empty update
saved_last_sync_revision = store0.last_sync_revision
store0.updater.update_from_disk()
assert store0.last_sync_revision == saved_last_sync_revision
orig = str(store0)
update_file = test_fs.open(
"data/po/tutorial/ru/update_set_last_sync_revision_updated.po",
"r")
with update_file as sourcef:
with open(store0.file.path, "wb") as targetf:
targetf.write(sourcef.read())
# any non-empty update sets last_sync_revision to next global revision
next_revision = Revision.get() + 1
store0.updater.update_from_disk()
assert store0.last_sync_revision == next_revision
# store.last_sync_revision is not changed after empty update (even if it
# has unsynced units)
item_index = 0
next_unit_revision = Revision.get() + 1
dbunit = store0.units.first()
dbunit.target = "ANOTHER DB TARGET UPDATE"
dbunit.save()
assert dbunit.revision == next_unit_revision
store0.updater.update_from_disk()
assert store0.last_sync_revision == next_revision
# Non-empty update sets store.last_sync_revision to next global revision
# (even the store has unsynced units). There is only one unsynced unit in
# this case so its revision should be set next to store.last_sync_revision
next_revision = Revision.get() + 1
with open(store0.file.path, "wb") as targetf:
targetf.write(orig)
store0.updater.update_from_disk()
assert store0.last_sync_revision == next_revision
# Get unsynced unit in DB. Its revision should be greater
# than store.last_sync_revision to allow to keep this change during
# update from a file
dbunit = store0.units[item_index]
assert dbunit.revision == store0.last_sync_revision + 1
示例2: test_update_set_last_sync_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
"""Tests setting last_sync_revision after store creation.
"""
store = ru_update_set_last_sync_revision_po
# Store is already parsed and store.last_sync_revision should be equal to
# max unit revision
assert store.last_sync_revision == store.get_max_unit_revision()
# store.last_sync_revision is not changed after empty update
saved_last_sync_revision = store.last_sync_revision
store.update_from_disk()
assert store.last_sync_revision == saved_last_sync_revision
dir_path = os.path.join(store.translation_project.project.get_real_path(),
store.translation_project.language.code)
copied_initial_filepath = os.path.join(
dir_path,
'update_set_last_sync_revision.po.temp'
)
shutil.copy(store.file.path, copied_initial_filepath)
updated_filepath = os.path.join(
dir_path,
'update_set_last_sync_revision_updated.po'
)
shutil.copy(updated_filepath, store.file.path)
# any non-empty update sets last_sync_revision to next global revision
next_revision = Revision.get() + 1
store.update_from_disk()
assert store.last_sync_revision == next_revision
# store.last_sync_revision is not changed after empty update (even if it
# has unsynced units)
item_index = 0
next_unit_revision = Revision.get() + 1
dbunit = _update_translation(store, item_index, {'target': u'first'},
sync=False)
assert dbunit.revision == next_unit_revision
store.update_from_disk()
assert store.last_sync_revision == next_revision
# Non-empty update sets store.last_sync_revision to next global revision
# (even the store has unsynced units). There is only one unsynced unit in
# this case so its revision should be set next to store.last_sync_revision
next_revision = Revision.get() + 1
shutil.move(copied_initial_filepath, store.file.path)
store.update_from_disk()
assert store.last_sync_revision == next_revision
# Get unsynced unit in DB. Its revision should be greater
# than store.last_sync_revision to allow to keep this change during
# update from a file
dbunit = store.getitem(item_index)
assert dbunit.revision == store.last_sync_revision + 1
示例3: test_update_upload_member_user
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_member_user(en_tutorial_po, member):
update_store(
en_tutorial_po,
[("Hello, world", "Hello, world UPDATED")],
user=member,
store_revision=Revision.get() + 1)
assert en_tutorial_po.units[0].submitted_by == member
示例4: handle_noargs
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def handle_noargs(self, **options):
if options["restore"]:
from pootle_store.models import Unit
Revision.set(Unit.max_revision())
self.stdout.write("%s" % Revision.get())
示例5: handle
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def handle(self, **options):
last_known_revision = Revision.get()
if options["after_revision"] is not None:
after_revision = int(options["after_revision"])
else:
after_revision = Store.objects.all().aggregate(Max("last_sync_revision"))["last_sync_revision__max"] or -1
self.stderr.write(
"Will show languages changed between revisions %s (exclusive) "
"and %s (inclusive)" % (after_revision, last_known_revision)
)
# if the requested revision is the same or is greater than the last
# known one, return nothing
if after_revision >= last_known_revision:
self.stderr.write("(no known changes)")
return
q = (
Unit.objects.filter(revision__gt=after_revision)
.values("store__translation_project__language__code")
.order_by("store__translation_project__language__code")
.distinct()
)
languages = q.values_list("store__translation_project__language__code", flat=True)
# list languages separated by comma for easy parsing
self.stdout.write(",".join(languages))
示例6: handle
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def handle(self, **options):
last_known_revision = Revision.get()
if options['after_revision'] is not None:
after_revision = int(options['after_revision'])
else:
after_revision = Store.objects.all().aggregate(
Max('last_sync_revision'))['last_sync_revision__max'] or -1
self.stderr.write(
'Will show languages changed between revisions %s (exclusive) '
'and %s (inclusive)' %
(after_revision, last_known_revision)
)
# if the requested revision is the same or is greater than the last
# known one, return nothing
if after_revision >= last_known_revision:
self.stderr.write('(no known changes)')
return
q = Unit.objects.filter(
revision__gt=after_revision
).values(
'store__translation_project__language__code',
).order_by(
'store__translation_project__language__code',
).distinct()
languages = q.values_list('store__translation_project__language__code',
flat=True)
# list languages separated by comma for easy parsing
print ','.join(languages)
示例7: test_update_upload_new_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_new_revision(en_tutorial_po):
update_store(
en_tutorial_po,
[("Hello, world", "Hello, world UPDATED")],
submission_type=SubmissionTypes.UPLOAD,
store_revision=Revision.get() + 1)
assert en_tutorial_po.units[0].target == "Hello, world UPDATED"
示例8: _sync_to_pootle
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def _sync_to_pootle(self, merge=False, pootle_wins=None):
"""
Update Pootle ``Store`` with the parsed FS file.
"""
tmp_store = self.deserialize()
if not tmp_store:
logger.warn("File staged for sync has disappeared: %s", self.path)
return
if pootle_wins is None:
resolve_conflict = (
self.store_fs.resolve_conflict or SOURCE_WINS)
elif pootle_wins:
resolve_conflict = POOTLE_WINS
else:
resolve_conflict = SOURCE_WINS
if merge:
revision = self.store_fs.last_sync_revision or 0
else:
# We set the revision to *anything* higher than the Store's
# This is analogous to the `overwrite` option in
# Store.update_from_disk
revision = Revision.get() + 1
update_revision, __ = self.store.update(
tmp_store,
submission_type=SubmissionTypes.SYSTEM,
user=self.latest_user,
store_revision=revision,
resolve_conflict=resolve_conflict)
logger.debug("Pulled file: %s", self.path)
return update_revision
示例9: test_update_upload_submission_type
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_submission_type(en_tutorial_po):
update_store(
en_tutorial_po,
[("Hello, world", "Hello, world UPDATED")],
submission_type=SubmissionTypes.UPLOAD,
store_revision=Revision.get() + 1)
assert (en_tutorial_po.units[0].submission_set.first().type
== SubmissionTypes.UPLOAD)
示例10: test_update_upload_defaults
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_defaults(en_tutorial_po, system):
update_store(
en_tutorial_po,
[("Hello, world", "Hello, world UPDATED")],
user=system,
store_revision=Revision.get() + 1)
assert en_tutorial_po.units[0].submitted_by == system
assert (en_tutorial_po.units[0].submission_set.first().type
== SubmissionTypes.SYSTEM)
示例11: test_update_upload_member_user
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_member_user(store0, member):
store0.state = PARSED
unit_source = store0.units.first().source
update_store(
store0,
[(unit_source, "%s UPDATED" % unit_source)],
user=member,
store_revision=Revision.get() + 1)
assert store0.units[0].submitted_by == member
示例12: __test_update_set_last_sync_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def __test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
"""Tests setting last_sync_revision after store creation.
"""
store = ru_update_set_last_sync_revision_po
# Parse a store during first update
# store.last_sync_revision is set to the next global revision
next_revision = Revision.get() + 1
store.update(store.file.store)
assert store.last_sync_revision == next_revision
assert store.get_max_unit_revision() == next_revision
# store.last_sync_revision is not changed after empty update
store.update(store.file.store)
assert store.last_sync_revision == next_revision
# any non-empty update sets last_sync_revision to next global revision
store.file = 'tutorial/ru/update_set_last_sync_revision_updated.po'
next_revision = Revision.get() + 1
store.update(store.file.store)
assert store.last_sync_revision == next_revision
# store.last_sync_revision is not changed after empty update
# (even if it has unsynced units)
item_index = 0
next_unit_revision = Revision.get() + 1
dbunit = _update_translation(store, item_index, {'target': u'first'},
sync=False)
assert dbunit.revision == next_unit_revision
store.update(store.file.store, store_revision=0)
assert store.last_sync_revision == next_revision
# Non-empty update sets store.last_sync_revision to next global revision
# (even the store has unsynced units)
# There is only one unsynced unit in this case so its revision should be set
# next to store.last_sync_revision
next_revision = Revision.get() + 1
store.file = 'tutorial/ru/update_set_last_sync_revision.po'
store.update(store.file.store,
store_revision=store.get_max_unit_revision())
assert store.last_sync_revision == next_revision
unit = store.getitem(item_index)
# not sure why this was store.last_sync_revision + 1 - but no longer works
assert unit.revision == store.last_sync_revision
示例13: test_update_upload_again_new_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_update_upload_again_new_revision(en_tutorial_po_no_file):
store = en_tutorial_po_no_file
assert store.state == NEW
update_store(
store,
[("Hello, world", "Hello, world UPDATED")],
submission_type=SubmissionTypes.UPLOAD,
store_revision=Revision.get() + 1)
store = Store.objects.get(pk=store.pk)
assert store.state == PARSED
assert store.units[0].target == "Hello, world UPDATED"
update_store(
store,
[("Hello, world", "Hello, world UPDATED AGAIN")],
submission_type=SubmissionTypes.UPLOAD,
store_revision=Revision.get() + 1)
store = Store.objects.get(pk=store.pk)
assert store.state == PARSED
assert store.units[0].target == "Hello, world UPDATED AGAIN"
示例14: test_changed_languages_noargs
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_changed_languages_noargs(capfd):
"""Get changed languages since last sync."""
revision = Revision.get()
call_command('changed_languages')
out, err = capfd.readouterr()
assert out == u'language0,language1,templates\n'
assert (
("Will show languages changed between revisions -1 (exclusive) and "
"%d (inclusive)"
% (revision))
in err)
示例15: test_max_revision
# 需要导入模块: from pootle.core.models import Revision [as 别名]
# 或者: from pootle.core.models.Revision import get [as 别名]
def test_max_revision(af_tutorial_po):
"""Tests `max_revision()` gets the latest revision."""
initial_max_revision = Unit.max_revision()
initial_revision = Revision.get()
assert initial_max_revision == initial_revision
assert initial_max_revision == 0
# Let's make 10 translation updates, this must also update their
# revision numbers
for i in range(10):
_update_translation(af_tutorial_po, 0, {'target': str(i)},
sync=False)
end_max_revision = Unit.max_revision()
end_revision = Revision.get()
assert end_max_revision == end_revision
assert end_max_revision != initial_max_revision
assert end_revision != initial_revision
assert end_revision == 10