def new_project(name): # 拷贝一份并重命名project_name if os.path.exists(name): print(name + ' folder already exists') return False subprocess_run("cp -rf %s/template/project %s" % (SCRIPT_LOCATION, name)) subprocess_run("mv %s/project %s/%s" % (name, name, name)) current = os.path.abspath('.') os.chdir(name) # command="cp -ir %s/template/project/*.* ./"%(SCRIPT_LOCATION) # subprocess_shell(command) with open('config.yml', 'r') as f: s = f.read() name_pattern = re.compile(r'(name\s*:\s*).*?(\n)') s = re.sub(name_pattern, '\\1%s\\2' % name, s) with open('config.yml', 'w') as f: f.write(s) update_project() print( "Finished. If you want to specify more details, please edit the config.yml file and then run \"ly up \"to update the project init." ) os.chdir(current) return
def reset(): # to1do: implement the reset ''' :return: ''' subprocess_run("git reset") pass
def build(): ''' hello :return: ''' command = 'python setup.py sdist' subprocess_run(command)
def new_project2(): # 拷贝一份并重命名project_name if os.path.exists(project['name']): print(project['name'] + ' folder already exists') return False subprocess_run("cp -rf %s/template/project %s" % (SCRIPT_LOCATION, project['name'])) subprocess_run("mv %s/project %s/%s" % (project['name'], project['name'], project['name'])) # 对于新的拷贝 project_path = os.path.join(project['name']) alowed_pattern = re.compile(r'.*\.(?:txt|cfg|ini|rst|md)$') for root, dirs, files in os.walk(project_path): print root, dirs, files, '\n\n' files[:] = [f for f in files if alowed_pattern.match(f)] for file in files: with open(os.path.join(root, file), 'r') as f: # print(cummutils_to_jinja(f.read())) s = Template(cummutils_to_jinja( f.read())).render(project=project) # print(s) with open(os.path.join(root, file), 'w') as f: f.write(s)
def merge(to_branch='master'): ''' 本地开发的小branch 直接merge进master, 不去远程merge了. :return: ''' branch_name = find_branch_name() commit() sync() rebase() # subprocess_run("git merge "+to_branch) subprocess_run("git checkout " + to_branch) # print("git merge --no-ff "+branch_name) # print( shlex.split("git merge --no-ff "+branch_name)) subprocess_run("git merge --no-ff " + branch_name)
def upload(test=False): if test: command = 'python setup.py register -r testpypi' subprocess_run(command) command = 'python setup.py sdist upload -r testpypi ' subprocess_run(command) else: command = 'python setup.py register -r pypi' subprocess_run(command) command = 'python setup.py sdist upload -r pypi ' subprocess_run(command)
def project_gen(): # 拷贝一份并重命名project_name subprocess_run("rm -rf target") subprocess_run("mkdir target") subprocess_run("cp -rf template/project target/") subprocess_run("mv target/project/project target/project/%s" % project['name']) subprocess_run("mv target/project target/%s" % project['name']) # 对于新的拷贝 project_path = os.path.join("target", project['name']) for root, dirs, files in os.walk(project_path): # print root,dirs,files, '\n\n' for file in files: with open(os.path.join(root, file), 'r') as f: s = Template(f.read()).render(project=project) with open(os.path.join(root, file), 'w') as f: f.write(s)
def log(): ''' 彩图显示全局的分支和commit图 :return: ''' subprocess_run("git log --graph --oneline --all")
def reset_tree(): # todo: subprocess_run("git checkout -f HEAD")
def pull(): ''' wrapper for git pull :return: ''' subprocess_run('git pull')
def detox(r=False): if not r: command = 'detox' else: command = 'detox -r' subprocess_run(command)
def pip_install(test=False): command = "pip install -i https://pypi.python.org/pypi commutils --user --upgrade" subprocess_run(command)
def install(): build() command = 'python setup.py install --prefix=~/.local' subprocess_run(command)
def self_update(): current = os.path.abspath('.') os.chdir("/Users/lhr/_action/python/projects/commutils") commit() subprocess_run("bin/ly install") os.chdir(current)