def _ask_for_mapping_details(self, mapping_id): old_mapping = self._get_mapping_by_id(mapping_id) old_group = self._server.get_group_by_id(old_mapping["group_id"]) new_pattern = prompt_user("Pattern:", old_mapping["pattern"]) new_pattern = self._guess_and_verify_pattern(new_pattern) new_group_name = prompt_user("Group:", old_group["name"]) new_group = self._get_group_by_name(new_group_name) while True: new_triggers_katt2 = prompt_user( "Triggers KATT2:", old_mapping["triggers_katt2"]).strip().lower() if new_triggers_katt2 in ["true", "false"]: break print "Invalid value. Expected true or false." new_mapping = old_mapping.copy() new_mapping["pattern"] = new_pattern new_mapping["group_id"] = new_group["id"] new_mapping["triggers_katt2"] = new_triggers_katt2 return old_mapping, old_group, new_mapping, new_group
def _select_revision_and_lineno(revision, diffs): for diff_rev, diff_content in diffs.items(): print "=" * 18, " r%s vs. r%s " % (diff_rev, revision), "=" * 18 print '\n'.join(diff_content) print "=" * 58 if not options.assume_yes: answer = prompt_user("Continue [Y/n]", ('y', 'n'), default_answer='y') if answer == 'n': return None, None if len(diffs) > 1: selected_revision = prompt_user( "Please choose which revision to continue [%s]:" % ('/'.join(diffs.keys())), diffs.keys()) else: selected_revision = diffs.keys()[0] selected_line = "" while not selected_line.isdigit(): selected_line = prompt_user( "Please choose which line in r%s to trace:" % selected_revision) return selected_revision, int(selected_line)
def cmd_group_merge(self, name1, name2): self._output("This will:\n") self._output("* Transfer {0}'s mappings to {1}.".format(name1, name2)) self._output("* Delete {0}.\n".format(name1)) answer = prompt_user( "Are you sure you want to merge {0} into {1} [y/n]?".format( name1, name2)) if is_affirmative(answer): self._merge_groups(name1, name2) self._output("Group {0} merged into {1}.".format(name1, name2)) else: self._output("No changes were made.")
def cmd_delete(self, mapping_id): mapping = self._get_mapping_by_id(mapping_id) group = self._server.get_group_by_id(mapping["group_id"]) self._output("Mapping to delete:\n") self._output("Pattern: {0}".format(mapping["pattern"])) self._output("Group: {0}".format(group["name"])) self._output("Triggers KATT2: {0}\n".format(mapping["triggers_katt2"])) answer = prompt_user( "Are you sure you want to remove this mapping [y/n]?") do_delete = is_affirmative(answer) if do_delete: self._server.delete_mapping(mapping_id) self._output("Mapping {0}{1} deleted.".format( mapping_id, "" if do_delete else " not"))
def _query_user_for_branch_parent(): print('Could not determine the parent of the branch "{0}".'.format( repo.branch_name)) while True: response = prompt_user('Please input parent:') parent = refname.RefName(response) if parent.path_depth() == 1: parent = refname.RefName('origin/{0}'.format(parent)) if parent.exists(): break else: print('Could not find parent branch: {0}'.format(parent)) return parent
def _guess_pattern(self, pattern, ask_for_confirmation=True): pattern = pattern.rstrip("/") svn_base_url = self._svn.get_base_url() m = re.match( "{0}/(?P<repo>[^/]+)/(?P<path>.*)".format(re.escape(svn_base_url)), pattern) if m: # The pattern is in URL form. return ":".join(m.group("repo", "path")) if ":" in pattern: # The pattern is fully specified already. return pattern local_matches = glob(pattern) if not local_matches: self._output( "The pattern does not match a local file or directory -" " assuming that it refers to a project in the repository.\n") return "dev:" + pattern # It's a local pattern. if isdir(pattern): pattern += "/*" wc_info = self._svn.get_wc_path_info(".") if not wc_info: error("Could not deduce SVN URL from working copy info") guessed_pattern = "{0}:{1}/ANYBRANCH/{2}/{3}".format( wc_info.repository, wc_info.project, wc_info.path_in_wc, pattern) guessed_pattern = re.sub(r"/+", "/", guessed_pattern) guessed_pattern = re.sub(r"/(\./)+", "/", guessed_pattern) guessed_pattern = re.sub(r"(/\*)+", "/*", guessed_pattern) self._output( "The pattern matches local files and/or directories - assuming" " that it refers to a local path.") self._output("\nGuessed full pattern: {0}\n".format(guessed_pattern)) if ask_for_confirmation: answer = prompt_user( "OK to use {0} as the pattern [y/n]?".format(guessed_pattern)) if not is_affirmative(answer): error("Creation of mapping cancelled") return guessed_pattern
def get_username(self): if self._explicit_username: return self._explicit_username config = read_config() if "username" in config: return config["username"] username = prompt_user( "Please provide your {0} username:"******"action": "get_user", "coreid": username}) response = urlopen(BUILDUSER_API_URL + "?" + parameters) if response.getcode() != 200 or response.read() == "null": error("No such username: {0}".format(username)) config["username"] = username write_config(config) print "Username saved in {0}".format(CONFIG_FILE) return username
def _user_choose_review_config(): config_path = _get_config_path() if isfile(config_path): print "Found previous review configuration %s." % config_path choice_use_existing = prompt_user( "Use it and send review update [y/n]?", ('y', 'n')) if choice_use_existing == 'y': return ReviewFileSet(config_path) print '''\ (1) Load other existing review configuration? (2) Create a NEW review request for all COMMITTED changes on the branch? (3) Create a NEW review request for all UNCOMMITTED changes on the branch?\ ''' choice_of_action = prompt_user("Answer:", ('1', '2', '3')) config_path = prompt_user("Enter path of review configuration file:") if choice_of_action == '1': if not isfile(config_path): error("%s does not exist" % config_path) return ReviewFileSet(config_path) elif choice_of_action in ['2', '3']: if isfile(config_path): choice_overwrite = prompt_user( "Overwrite %s [y/n]?" % config_path, ('y', 'n')) if choice_overwrite == 'n': return None os.unlink(config_path) uncommitted = (choice_of_action == '3') return _init_default_review_config_file(config_path, None, uncommitted) else: print '''\ Could not find a previous review configuration for this branch. (1) Create a NEW review request for all COMMITTED changes on the branch? (2) Create a NEW review request for all UNCOMMITTED changes on the branch? (3) Update an EXISTING review request with all COMMITTED changes on the \ branch? (4) Update an EXISTING review request with all UNCOMMITTED changes on the \ branch?\ ''' choice_of_action = prompt_user("Answer:", ('1', '2', '3', '4')) if choice_of_action in ['3', '4']: review_id = prompt_user("Give review ID:") if not review_id.isdigit(): error("invalid review ID given") else: review_id = None uncommitted = choice_of_action in ['2', '4'] return _init_default_review_config_file(config_path, review_id, uncommitted)
def _execute_file_trace(svn_path, revision): print "Path was changed (move, copy or add operation) in the following" \ " commits:" path = svn_path original_path, rev = get_original_path(path, revision) if original_path is None: print " %s@%s" % (path.full_url, revision if revision else path.revision) return while original_path is not None: print " %s/%s@%s" % (original_path.branch_url, path.file_path, rev) if (original_path.file_path != path.file_path and not options.assume_yes): answer = prompt_user("Continue [Y/n]", ('y', 'n'), default_answer='y') if answer == 'n': break path = original_path original_path, rev = get_original_path(path)
def _user_choose_review_config(): config_path = _get_config_path() if isfile(config_path): print('Found previous review configuration {0}'.format(config_path)) choice_use_existing = prompt_user( 'Use it and send review update [y/n]?', ('y', 'n')) if choice_use_existing == 'y': return ReviewFileSet(config_path) print('''\ (1) Load other existing review configuration? (2) Create a NEW review request for all PUSHED changes on the branch? (3) Create a NEW review request for all UNPUSHED changes on the branch?\ ''') choice_of_action = prompt_user('Answer:', ('1', '2', '3')) config_path = prompt_user('Enter path of review configuration file:') if choice_of_action == '1': if not isfile(config_path): error('{0} does not exist'.format(config_path)) review_file_set = ReviewFileSet(config_path) if review_file_set.review_state.get_branch_parent() is None: review_file_set.review_state.set_branch_parent( _get_branch_parent(unpushed=False, query_user=True)) return review_file_set elif choice_of_action in ['2', '3']: if isfile(config_path): choice_overwrite = prompt_user( 'Overwrite {0} [y/n]?'.format(config_path), ('y', 'n')) if choice_overwrite == 'n': return None os.unlink(config_path) unpushed = choice_of_action == '3' parent = _get_branch_parent(unpushed, query_user=True) return _init_default_review_config_file(config_path, None, unpushed, parent) else: print('''\ Could not find a previous review configuration for this branch. (1) Create a NEW review request for all PUSHED changes on the branch? (2) Create a NEW review request for all UNPUSHED changes on the branch? (3) Update an EXISTING review request with all PUSHED changes on the \ branch? (4) Update an EXISTING review request with all UNPUSHED changes on the branch? ''') choice_of_action = prompt_user('Answer:', ('1', '2', '3', '4')) if choice_of_action in ['3', '4']: review_id = prompt_user('Give review ID:') if not review_id.isdigit(): error('invalid review ID given') else: review_id = None unpushed = choice_of_action in ['2', '4'] parent = _get_branch_parent(unpushed, query_user=True) return _init_default_review_config_file(config_path, review_id, unpushed, parent)