Skip to content

Commit

Permalink
Fix --overwrite option for project cli command when updating TP from TP
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2-1 committed Apr 10, 2017
1 parent 557ba14 commit 786746c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def handle(self, *args, **options):

for source_tp in tp_query:
target_tps = self.tp_tool.get_tps(target_project)
resolve_conflict = SOURCE_WINS if options['overwrite'] else POOTLE_WINS
target_language_code = source_tp.language.code
if options['target_language']:
target_language_code = options['target_language']
Expand All @@ -262,7 +261,7 @@ def handle(self, *args, **options):
source_tp,
target_tp,
allow_add_and_obsolete=not options['translations'],
resolve_conflict=resolve_conflict,
overwrite=options['overwrite'],
)
except TranslationProject.DoesNotExist:
logging.warning(
Expand Down
20 changes: 12 additions & 8 deletions pootle/apps/pootle_translationproject/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ def set_parents(self, directory, parent, project=None):
self.set_parents(subdir, subdir, project)

def update_children(self, source_dir, target_dir,
allow_add_and_obsolete=True,
resolve_conflict=SOURCE_WINS):
allow_add_and_obsolete=True, overwrite=False):
"""Update a target Directory and its children from a given
source Directory
"""
Expand All @@ -242,7 +241,7 @@ def update_children(self, source_dir, target_dir,
"filetype__extension",
"filetype__template_extension").get(name=store.name),
allow_add_and_obsolete=allow_add_and_obsolete,
resolve_conflict=resolve_conflict)
overwrite=overwrite)
except target_dir.child_stores.model.DoesNotExist:
if allow_add_and_obsolete:
self.clone_store(store, target_dir)
Expand All @@ -254,6 +253,7 @@ def update_children(self, source_dir, target_dir,
subdir,
target_dir.child_dirs.get(name=subdir.name),
allow_add_and_obsolete=allow_add_and_obsolete,
overwrite=overwrite,
)
except target_dir.child_dirs.model.DoesNotExist:
self.clone_directory(subdir, target_dir)
Expand All @@ -263,19 +263,23 @@ def update_children(self, source_dir, target_dir,
store.makeobsolete()

def update_from_tp(self, source, target, allow_add_and_obsolete=True,
resolve_conflict=SOURCE_WINS):
overwrite=False):
"""Update one TP from another"""
self.check_tp(source)
self.update_children(
source.directory, target.directory,
allow_add_and_obsolete=allow_add_and_obsolete,
resolve_conflict=resolve_conflict
overwrite=overwrite,
)

def update_store(self, source, target, allow_add_and_obsolete=True,
resolve_conflict=SOURCE_WINS):
overwrite=False):
"""Update a target Store from a given source Store"""
source_revision = target.data.max_unit_revision + 1
if overwrite:
source_revision = target.data.max_unit_revision + 1
else:
source_revision = 0

differ = StoreDiff(target, source, source_revision)
diff = differ.diff()
if diff is not None:
Expand All @@ -289,6 +293,6 @@ def update_store(self, source, target, allow_add_and_obsolete=True,
update_revision,
system,
SubmissionTypes.SYSTEM,
resolve_conflict,
SOURCE_WINS,
allow_add_and_obsolete)
self.update_muted_checks(source, target, check_target_translation=True)

0 comments on commit 786746c

Please sign in to comment.