def get_yes_or_no(msg): while True: response = gclient_utils.AskForData(msg + ' yes/no [no] ') if response == 'y' or response == 'yes': return True elif not response or response == 'n' or response == 'no': return False
def _confirm(message): """Show a confirmation prompt with the given message. Returns: A bool representing whether the user wishes to continue. """ result = '' while result not in ('y', 'n'): try: result = gclient_utils.AskForData('%s Continue (y/n)? ' % message) except EOFError: result = 'n' return result == 'y'
def run(self): self.reset() while self.owners_queue and self.unreviewed_files: owner = self.owners_queue[0] if (owner in self.selected_owners) or (owner in self.deselected_owners): continue if not any((file_name in self.unreviewed_files) for file_name in self.owners_to_files[owner]): self.deselect_owner(owner) continue self.print_info(owner) while True: inp = self.input_command(owner) if inp == 'y' or inp == 'yes': self.select_owner(owner) break elif inp == 'n' or inp == 'no': self.deselect_owner(owner) break elif inp == '' or inp == 'd' or inp == 'defer': self.owners_queue.append(self.owners_queue.pop(0)) break elif inp == 'f' or inp == 'files': self.list_files() break elif inp == 'o' or inp == 'owners': self.list_owners(self.owners_queue) break elif inp == 'p' or inp == 'pick': self.pick_owner( gclient_utils.AskForData('Pick an owner: ')) break elif inp.startswith('p ') or inp.startswith('pick '): self.pick_owner(inp.split(' ', 2)[1].strip()) break elif inp == 'r' or inp == 'restart': self.reset() break elif inp == 'q' or inp == 'quit': # Exit with error return 1 self.print_result() return 0
def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run, cq_dry_run, enable_auto_submit, repository_root): """"Splits a branch into smaller branches and uploads CLs. Args: description_file: File containing the description of uploaded CLs. comment_file: File containing the comment of uploaded CLs. changelist: The Changelist class. cmd_upload: The function associated with the git cl upload command. dry_run: Whether this is a dry run (no branches or CLs created). cq_dry_run: If CL uploads should also do a cq dry run. enable_auto_submit: If CL uploads should also enable auto submit. Returns: 0 in case of success. 1 in case of error. """ description = AddUploadedByGitClSplitToDescription( gclient_utils.FileRead(description_file)) comment = gclient_utils.FileRead(comment_file) if comment_file else None try: EnsureInGitRepository() cl = changelist() upstream = cl.GetCommonAncestorWithUpstream() files = [ (action.strip(), f) for action, f in scm.GIT.CaptureStatus(repository_root, upstream) ] if not files: print('Cannot split an empty CL.') return 1 author = git.run('config', 'user.email').strip() or None refactor_branch = git.current_branch() assert refactor_branch, "Can't run from detached branch." refactor_branch_upstream = git.upstream(refactor_branch) assert refactor_branch_upstream, \ "Branch %s must have an upstream." % refactor_branch files_split_by_owners = GetFilesSplitByOwners(files) num_cls = len(files_split_by_owners) print('Will split current branch (' + refactor_branch + ') into ' + str(num_cls) + ' CLs.\n') if cq_dry_run and num_cls > CL_SPLIT_FORCE_LIMIT: print( 'This will generate "%r" CLs. This many CLs can potentially generate' ' too much load on the build infrastructure. Please email' ' [email protected] to ensure that this won\'t break anything.' ' The infra team reserves the right to cancel your jobs if they are' ' overloading the CQ.' % num_cls) answer = gclient_utils.AskForData('Proceed? (y/n):') if answer.lower() != 'y': return 0 # Verify that the description contains a bug link. bug_pattern = re.compile(r"^Bug:\s*[0-9]+", re.MULTILINE) matches = re.findall(bug_pattern, description) answer = 'y' if not matches: answer = gclient_utils.AskForData( 'Description does not include a bug link. Proceed? (y/n):') if answer.lower() != 'y': return 0 for cl_index, (directory, files) in \ enumerate(files_split_by_owners.items(), 1): # Use '/' as a path separator in the branch name and the CL description # and comment. directory = directory.replace(os.path.sep, '/') file_paths = [f for _, f in files] reviewers = cl.owners_client.SuggestOwners( file_paths, exclude=[author, cl.owners_client.EVERYONE]) if dry_run: PrintClInfo(cl_index, num_cls, directory, file_paths, description, reviewers) else: UploadCl(refactor_branch, refactor_branch_upstream, directory, files, description, comment, reviewers, changelist, cmd_upload, cq_dry_run, enable_auto_submit, repository_root) # Go back to the original branch. git.run('checkout', refactor_branch) except subprocess2.CalledProcessError as cpe: sys.stderr.write(cpe.stderr) return 1 return 0
def input_command(self, owner): self.writeln('Add ' + self.bold_name(owner) + ' as your reviewer? ') return gclient_utils.AskForData( '[yes/no/Defer/pick/files/owners/quit/restart]: ').lower()