From 014551e786da2f3dc240e5e5a36b81ce2e67accf Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 25 Feb 2014 16:51:39 +0100 Subject: [PATCH] Move the user interaction for linked package into commandline.py --- osc/commandline.py | 12 +++++++++++- osc/core.py | 28 +++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index b9167c37..3a124c28 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -4325,6 +4325,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. prj = Project(arg) if not msg and not opts.no_message: msg = edit_message() + prj.commit(msg=msg, skip_local_service_run=skip_local_service_run, verbose=opts.verbose) except oscerr.ExtRuntimeError as e: print("ERROR: service run failed", e, file=sys.stderr) @@ -4357,7 +4358,16 @@ Please submit there instead, or use --nodevelproject to force direct submission. prj = Project(prj_path) if not msg and not opts.no_message: msg = get_commit_msg(prj.absdir, pac_objs[prj_path]) - prj.commit(packages, msg=msg, files=files, skip_local_service_run=skip_local_service_run, verbose=opts.verbose) + + # check any of the packages is a link, if so, as for branching + can_branch = False + if any(pac.is_link_to_different_project() for pac in pacs): + repl = raw_input('Some of the packages are links to a different project!\n' \ + 'Create a local branch before commit? (y|N) ') + if repl in('y', 'Y'): + can_branch = True + + prj.commit(packages, msg=msg, files=files, skip_local_service_run=skip_local_service_run, verbose=opts.verbose, can_branch=can_branch) store_unlink_file(prj.absdir, '_commit_msg') for pac in single_paths: p = Package(pac) diff --git a/osc/core.py b/osc/core.py index 8dcee236..4d94438f 100644 --- a/osc/core.py +++ b/osc/core.py @@ -860,7 +860,7 @@ class Project: finally: self.write_packages() - def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False): + def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False, can_branch=False): if len(pacs): try: for pac in pacs: @@ -879,7 +879,7 @@ class Project: else: p = Package(os.path.join(self.dir, pac)) p.todo = todo - p.commit(msg, verbose=verbose, skip_local_service_run=skip_local_service_run) + p.commit(msg, verbose=verbose, skip_local_service_run=skip_local_service_run, can_branch=can_branch) elif pac in self.pacs_unvers and not is_package_dir(os.path.join(self.dir, pac)): print('osc: \'%s\' is not under version control' % pac) elif pac in self.pacs_broken: @@ -1297,7 +1297,7 @@ class Package: todo.append(n.get('name')) return todo - def commit(self, msg='', verbose=False, skip_local_service_run=False): + def commit(self, msg='', verbose=False, skip_local_service_run=False, can_branch=False): # commit only if the upstream revision is the same as the working copy's upstream_rev = self.latest_rev() if self.rev != upstream_rev: @@ -1310,22 +1310,19 @@ class Package: # information (like which service/command failed) raise oscerr.ServiceRuntimeError('A service failed with error: %d' % r) - # FIXME: get rid of the user interaction # check if it is a link, if so, branch the package - orgprj = self.get_local_origin_project() - if self.prjname != orgprj: - print('Current project:', self.prjname) - print('Linked project:', orgprj) - repl = raw_input('The package is linked from a different project.' \ - ' Create a local branch before commit? (y|N) ') - if repl in('y', 'Y'): - exists, targetprj, targetpkg, srcprj, srcpkg = branch_pkg(self.apiurl, orgprj, self.name, - target_project=self.prjname) + if self.is_link_to_different_project(): + if can_branch: + orgprj = self.get_local_origin_project() + print("Branching {} from {} to {}".format(self.name, orgprj, self.prjname)) + exists, targetprj, targetpkg, srcprj, srcpkg = branch_pkg( + self.apiurl, orgprj, self.name, target_project=self.prjname) # update _meta and _files to sychronize the local package # to the new branched one in OBS self.update_local_pacmeta() self.update_local_filesmeta() else: + print("{} Not commited because is link to a different project".format(self.name)) return 1 if not self.todo: @@ -1566,6 +1563,11 @@ class Package: root = ET.fromstring(self.get_local_meta()) return root.get('project') + def is_link_to_different_project(self): + """Check if the package is a link to a different project.""" + orgprj = self.get_local_origin_project() + return self.prjname != orgprj + def update_datastructs(self): """ Update the internal data structures if the local _files