def create_branch(branch_name, config=None, unstable=True): ''' Create a branch with name branch_name to all the repositories that don't contain a branch with the same name. WARNING: This will clear all the uncommited changes in order to not add this changes to the new branch. ''' if not branch_name: print >> sys.stderr, t.red("Missing required branch parameter") return patches._pop() print t.bold('Cleaning all changes...') Config = read_config_file(config, unstable=unstable) update(config, unstable=True, clean=True, no_quilt=True) Config = read_config_file(config, unstable=unstable) processes = [] p = None for section in Config.sections(): repo = Config.get(section, 'repo') path = Config.get(section, 'path') if repo == 'git': continue if repo != 'hg': print >> sys.stderr, "Not developed yet" continue p = Process(target=hg_create_branch, args=(section, path, branch_name)) p.start() processes.append(p) wait_processes(processes) print t.bold('Applying patches...') patches._pop()
def branch(branch, clean=False, config=None, unstable=True): if not branch: print >> sys.stderr, t.red("Missing required branch parameter") return patches._pop() Config = read_config_file(config, unstable=unstable) processes = [] p = None for section in Config.sections(): repo = get_repo(section, Config) if repo['type'] == 'git': continue if repo['type'] != 'hg': print >> sys.stderr, "Not developed yet" continue p = Process(target=hg_update, args=(section, repo['path'], clean, branch)) p.start() processes.append(p) wait_processes(processes) wait_processes(processes, 0) print t.bold('Applying patches...') patches._push()
def prefetch(force=False): """ Ensures clean enviroment """ unknown(unstable=True, status=False, show=False, remove=True) clean(force=force) Config = read_config_file() patches._pop() for section in Config.sections(): repo = get_repo(section, Config, 'status') files = repo['function'](section, repo['path'], verbose=False, url=repo['url']) if files == {}: continue remove_files = [ os.path.join(repo['path'], x) for x in files.get('?', []) ] if force or _ask_ok( 'Answer "yes" to remove untracked files "%s" of "%s" repository ' 'in "%s" directory. [y/N] ' % (" ".join(remove_files), section, repo['path']), 'n'): for f in remove_files: os.remove(f) patches._push()
def update(config=None, unstable=True, clean=False, development=True, no_quilt=False): if not no_quilt: patches._pop() Config = read_config_file(config, unstable=unstable) processes = [] p = None for section in Config.sections(): repo = get_repo(section, Config, 'update') branch = None if clean: # Force branch only when clean is set branch = repo['branch'] revision = repo['revision'] p = Process(target=repo['function'], args=(section, repo['path'], clean, branch, revision)) p.start() processes.append(p) wait_processes(processes) wait_processes(processes, 0) if not no_quilt: patches._push()
def clean(force=False, config=None, unstable=True): patches._pop() p = Pool(MAX_PROCESSES) Config = read_config_file(config, unstable=unstable) repos = [] for section in Config.sections(): repo = get_repo(section, Config, 'clean') repo['force'] = force if os.path.exists(repo['path']): repos.append(repo) p.map(_clean, repos)
def branches(config=None, modules=None): patches._pop() Config = read_config_file(config, unstable=True) for section in Config.sections(): if modules and section not in modules: continue repo = get_repo(section, Config) _hg_branches(section, repo['path'], repo['branch']) patches._push()
def status(config=None, unstable=True, no_quilt=False, verbose=False): if not no_quilt: patches._pop() p = Pool(MAX_PROCESSES) Config = read_config_file(config, unstable=unstable) repos = [] for section in Config.sections(): repo = get_repo(section, Config, 'status') if not os.path.exists(repo['path']): print >> sys.stderr, t.red("Missing repositori: ") + \ t.bold(repo['path']) continue repos.append(repo) repo['verbose'] = verbose p.map(_status, repos) if not no_quilt: patches._push()
def pull(config=None, unstable=True, update=True, development=False, ignore_missing=False, no_quilt=False): if not no_quilt: patches._pop() Config = read_config_file(config, unstable=unstable) p = Pool(MAX_PROCESSES) repos = [] for section in Config.sections(): # TODO: provably it could be done with a wrapper if config.get(section, 'exclude'): continue repo = get_repo(section, Config, 'pull', development) repo['update'] = update repo['ignore_missing'] = ignore_missing repos.append(repo) exit_codes = p.map(_pull, repos) if not no_quilt: patches._push() return sum(exit_codes)
def fetch(): print t.bold('Pulling and updating local repository...') # Replace by a "hg_pull" call bashCommand = ['hg', 'pull', '-u'] execBashCommand(bashCommand, '', "It's not possible to pull the local repostory. Err:") patches._pop() print t.bold('Pulling...') pull(update=True, ignore_missing=True, no_quilt=True) print t.bold('Cloning...') clone() patches._push() print t.bold('Updating requirements...') bashCommand = [ 'pip', 'install', '-r', 'config/requirements.txt', '--exists-action', 's' ] execBashCommand(bashCommand, 'Config Requirements Installed Succesfully', "It's not possible to apply patche(es)") bashCommand = [ 'pip', 'install', '-r', 'tasks/requirements.txt', '--exists-action', 's' ] execBashCommand(bashCommand, 'Tasks Requirements Installed Succesfully', "It's not possible to apply patche(es)") if os.path.isfile('requirements.txt'): bashCommand = [ 'pip', 'install', '-r', 'requirements.txt', '--exists-action', 's' ] execBashCommand(bashCommand, 'Root Requirements Installed Succesfully', "It's not possible to apply patche(es)") print t.bold('Fetched.')