Rev 55: Some minor refactoring to get less duplicated code in __init__.py. in http://people.canonical.com/~robertc/baz2.0/plugins/builder/bug469874
Robert Collins
robertc at robertcollins.net
Tue Nov 10 06:02:38 GMT 2009
At http://people.canonical.com/~robertc/baz2.0/plugins/builder/bug469874
------------------------------------------------------------
revno: 55
revision-id: robertc at robertcollins.net-20091110060237-e49nxqojmkq03nzm
parent: robertc at robertcollins.net-20091110054956-8pnc9e95r38paipj
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bug469874
timestamp: Tue 2009-11-10 17:02:37 +1100
message:
Some minor refactoring to get less duplicated code in __init__.py.
=== modified file '__init__.py'
--- a/__init__.py 2009-09-25 19:50:30 +0000
+++ b/__init__.py 2009-11-10 06:02:37 +0000
@@ -200,18 +200,30 @@
filename=if_changed_from).parse()
return old_recipe
+ def _substitute_stuff(self, recipe_file, if_changed_from):
+ """Common code to substitute stuff
+
+ :return: A tuple with (retcode, base_branch). If retcode is None
+ then the command execution should continue.
+ """
+ base_branch = self._get_branch_from_recipe_file(recipe_file)
+ time = datetime.datetime.utcnow()
+ base_branch.substitute_time(time)
+ old_recipe = None
+ if if_changed_from is not None:
+ old_recipe = self._get_old_recipe(if_changed_from)
+ changed = resolve_revisions(base_branch, if_changed_from=old_recipe)
+ if not changed:
+ trace.note("Unchanged")
+ return 0, base_branch
+ return None, base_branch
+
def run(self, recipe_file, working_directory, manifest=None,
if_changed_from=None):
- base_branch = self._get_branch_from_recipe_file(recipe_file)
- time = datetime.datetime.utcnow()
- base_branch.substitute_time(time)
- old_recipe = None
- if if_changed_from is not None:
- old_recipe = self._get_old_recipe(if_changed_from)
- changed = resolve_revisions(base_branch, if_changed_from=old_recipe)
- if not changed:
- trace.note("Unchanged")
- return 0
+ result, base_branch = self._substitute_stuff(recipe_file,
+ if_changed_from)
+ if result is not None:
+ return result
build_tree(base_branch, working_directory)
if manifest is not None:
self._write_manifest_to_path(manifest, base_branch)
@@ -260,17 +272,10 @@
if dput is not None and key_id is None:
raise errors.BzrCommandError("You must specify --key-id if you "
"specify --dput.")
-
- base_branch = self._get_branch_from_recipe_file(recipe_file)
- time = datetime.datetime.utcnow()
- base_branch.substitute_time(time)
- old_recipe = None
- if if_changed_from is not None:
- old_recipe = self._get_old_recipe(if_changed_from)
- changed = resolve_revisions(base_branch, if_changed_from=old_recipe)
- if not changed:
- trace.note("Unchanged")
- return 0
+ result, base_branch = self._substitute_stuff(recipe_file,
+ if_changed_from)
+ if result is not None:
+ return result
recipe_name = os.path.basename(recipe_file)
if recipe_name.endswith(".recipe"):
recipe_name = recipe_name[:-len(".recipe")]
More information about the bazaar-commits
mailing list