def main(self, args, jira, path, parser, **kwargs): search_term = ' '.join(args.terms) try: tf = TicketFolder(path, jira) jira_client = tf.jira except IOError: jira_client = jira(utils.get_default_jira_server()) users = jira_client.search_users(search_term) if args.json: print(json.dumps([u.raw for u in users])) return if not users: return CommandResult('No matching users were found', return_code=1) table = PrettyTable(['Name', 'Username', 'Email Address', 'Time Zone']) table.align = 'l' for user in users: table.add_row([ user.displayName, user.name, user.emailAddress, user.timeZone ]) return CommandResult(unicode(table))
def handle(self, args, jira, path, parser, **kwargs): if args.global_config: config = utils.get_config() else: try: folder = TicketFolder(path, jira) config = folder.get_config() except NotTicketFolderException: config = utils.get_config() return_value = None if args.list: if len(args.params) != 0: parser.error( "--list requires no parameters." ) return_value = self.list(config) elif args.get: if len(args.params) != 1: parser.error( "--get requires exactly one parameter, the configuration " "value to display." ) section, key = self.get_section_and_key(args.params[0]) return_value = self.get(config, section, key) elif args.set: if len(args.params) != 2: parser.error( "--set requires exactly two parameters, the configuration " "key, and the configuration value." ) section, key = self.get_section_and_key(args.params[0]) value = args.params[1] if args.global_config: return_value = self.set_global(section, key, value) else: try: folder = TicketFolder(path, jira) return_value = self.set_local(folder, section, key, value) except NotTicketFolderException: parser.error( "Not currently within a ticket folder. To set a " "global configuration value, use the --global option." ) return return_value
def get_ticket_folder_for_path(self, path): return TicketFolder( path, self.get_jira, )
def clone_from_git_repository(self, url, path, jira): temp_dir = tempfile.mkdtemp() subprocess.check_call( ['git', 'clone', url, temp_dir], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) for branch in ['jira', 'master']: subprocess.check_call( [ 'git', 'checkout', branch, ], cwd=temp_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) issue_url_path = os.path.join(temp_dir, constants.METADATA_DIR, 'issue_url') with open(issue_url_path, 'r') as issue_url_file: issue_url = issue_url_file.read() match = self.TICKET_RE.match(issue_url) if not match: shutil.rmtree(temp_dir) raise exceptions.NotTicketFolderException( "The git repository at %s is not a Jirafs backup." % (url, )) if path: path = os.path.realpath(path) else: # This will create a subdirectory of the cwd named after # the ticket's number path = os.path.realpath(match.group(1)) # Move the temporary clone into the proper place os.rename(temp_dir, path) # Re-clone the shadow repository shadow_path = os.path.join(path, constants.METADATA_DIR, 'shadow') subprocess.check_call( [ 'git', 'clone', path, shadow_path, ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) # Move the .git directory to where we hide it os.rename(os.path.join(path, '.git'), os.path.join(path, constants.METADATA_DIR, 'git')) # Reset the shadow's URL to use a relative path subprocess.check_call( [ 'git', 'remote', 'set-url', 'origin', '../git', ], cwd=shadow_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) subprocess.check_call( ['git', 'checkout', 'jira'], cwd=shadow_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) folder = TicketFolder( path, jira, ) folder.run_git_command( 'config', '--file=%s' % folder.get_metadata_path( 'git', 'config', ), 'core.excludesfile', '.jirafs/gitignore', ) folder.log("Cloned Jirafs ticket folder for %s at %s; on hash %s", (folder.issue_url, folder.path, folder.run_git_command( 'rev-parse', 'master', ))) return folder