From af7aa23ce01fc8e1af0ac5f66bd575f3e5f8f32c Mon Sep 17 00:00:00 2001 From: David Ferguson Date: Wed, 5 Jun 2013 11:21:30 -0400 Subject: repopick: handle additional error cases around subprocesses * gracefully error if the project path cannot be found * poll() was not a reliable determination of EOF on my Darwin-Python 2.7 system. Change-Id: I203c2a75820f8acc079a5c9751d1c04daf6f3a16 --- tools/repopick.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/repopick.py b/tools/repopick.py index 3dd580b..039f122 100755 --- a/tools/repopick.py +++ b/tools/repopick.py @@ -129,16 +129,15 @@ if args.abandon_first: plist = subprocess.Popen([repo_bin,"info"], stdout=subprocess.PIPE) needs_abandon = False while(True): - retcode = plist.poll() pline = plist.stdout.readline().rstrip() + if not pline: + break matchObj = re.match(r'Local Branches.*\[(.*)\]', pline.decode()) if matchObj: local_branches = re.split('\s*,\s*', matchObj.group(1)) if any(args.start_branch[0] in s for s in local_branches): needs_abandon = True break - if(retcode is not None): - break if needs_abandon: # Perform the abandon only if the branch already exists @@ -191,14 +190,16 @@ for change in args.change_number: # - convert the project name to a project path plist = subprocess.Popen([repo_bin,"list"], stdout=subprocess.PIPE) while(True): - retcode = plist.poll() pline = plist.stdout.readline().rstrip() + if not pline: + break ppaths = re.split('\s*:\s*', pline.decode()) if ppaths[1] == project_name: project_path = ppaths[0] break - if(retcode is not None): - break + if 'project_path' not in locals(): + sys.stderr.write('ERROR: Could not determine the project path for project %s\n' % project_name) + sys.exit(1) # Check that the project path exists if not os.path.isdir(project_path): -- cgit v1.1