def test_get_project_dir(monkeypatch): def mock_get_root(name): return 'path/to' monkeypatch.setattr(settings, 'get_project_root', mock_get_root) monkeypatch.setattr(settings, 'private_repos', {'name': 'private_name'}) monkeypatch.setattr(settings.os.path, 'exists', lambda x: True) assert settings.get_project_dir('project') == 'path/to/project' assert settings.get_project_dir('name') == 'path/to/private_name' monkeypatch.setattr(settings.os.path, 'exists', lambda x: False) assert settings.get_project_dir('project') == '' assert settings.get_project_dir('name') == ''
def open_docs(self): "open project documentatie (treedocs bestandje)" if len(sys.argv) == 1 or sys.argv[1] == '.': where = os.getcwd() else: where = settings.get_project_dir(sys.argv[1]) self.run_and_continue(['treedocs', '{}/projdocs.trd'.format(where)])
def check_and_run_for_project(c, name, command): "run only if called for a valid project" if name: where = get_project_dir(name) if where: with c.cd(where): c.run(command) else: print('{} is not a known project'.format(name)) else: where = os.getcwd() name = os.path.basename(where) if get_project_dir(name) == where: with c.cd(where): c.run(command) else: print('you are not in a known project directory')
def prep(c, ticket): """check before pulling changes made for ticket into project """ project = get_project_name(ticket) pull_dest = get_project_dir(project) pull_src = os.path.join(DEVEL, '_' + ticket) with c.cd(pull_dest): c.run('hg incoming -v {}'.format(pull_src))
def pull(c, ticket): """pull changes made for ticket into project """ project = get_project_name(ticket) pull_dest = get_project_dir(project) pull_src = os.path.join(DEVEL, '_' + ticket) with c.cd(pull_dest): c.run('hg pull {}'.format(pull_src)) c.run('hg up')
def get_repofiles(c, reponame): """get all files from manifest """ path = '' if reponame == '.': path = os.getcwd() reponame = os.path.basename(path) else: path = get_project_dir(reponame) if not path: print('not a code repository') return '', [] use_git = True # if reponame in git_repos else False with c.cd(path): command = 'git ls-tree -r --name-only master' if use_git else 'hg manifest' result = c.run(command, hide=True) files = [ x for x in result.stdout.split('\n') if os.path.splitext(x)[1] == '.py' ] return path, files
def newticket(c, ticket, project): """set up handling of a ticket for a given project clones the project repository and builds a session file """ print('building new directory') root = '_' + ticket with c.cd(DEVEL): c.run('hg clone {} {}'.format(get_project_dir(project), root)) dest = os.path.join(SESSIONS, ticket) settings = os.path.join(DEVEL, root, '.hg', 'hgrc') with open(settings) as _in: in_section = False for line in _in: if line.startswith('[paths]'): in_section = True elif in_section and line.startswith('default'): origin = line.split('=')[1].strip() break else: origin = '' if origin: origin = os.path.basename(origin) with open(dest, 'w') as _out: first = True with open(os.path.join(SESSIONS, origin)) as _in: for line in _in: if line.startswith('cd ') and first: line = 'cd {}\n'.format(os.path.join(DEVEL, root)) first = False _out.write(line) _out.write("a-propos -n 'Mee Bezig' -f mee_bezig.pck &") # finally: create a reminder that we have a ticket version of this repo regfile = get_regfile_name(project) mode = 'a' if os.path.exists(regfile) else 'w' with open(regfile, mode) as f: print(ticket, file=f)
def get_regfile_name(name): "return standard path for ticket registration file" test = get_project_dir(name) if not test: return '' return os.path.join(test, '.tickets')