python小工具——下载更新代码工具

来源:互联网 发布:故宫淘宝有没有app 编辑:程序博客网 时间:2024/05/16 15:57

在用到大型代码库, 而且它是用repo  git 等工具来维护的代码库的时候, 我们下载同步代码,一般使用

repo sync -c .  

这种方式来同步整个代码, 但当我们下载或者同步某个单独的分支的时候,往往不是这样的

我们需要单独的找到这个库的分支名称,找分支这个工作往往需要多走几部,

当然也可以使用 

cat  .repo/manifest.xlm | grep '关键词'

来找到分支名字,然后再执行同步命令

但是为什么不重新组织一下,自己写一个脚本小工具来实现这个功能呢

这里是一个python版本的工具,当然使用shell 写成这个工具,也能实现这个功能。


好吧, 这是练习python使用时的一个产物。

功能上来说可以提升那么一点点的效率。



#!/usr/bin/python#coding:utf-8from sys import argvimport commandsdef repo_new_project(keywords):with open('.repo/manifest.xml','r') as f:for line in f.readlines():line= line.strip()if keywords in line:my_command='repo sync -c '+ line.split('name="')[1].split('"')[0]print my_commandcommands.getstatusoutput(my_command)if __name__ == '__main__':  print u'''**************************************************  **    Welcome to pyhon for  code download       **  **         Created on 2017-05-03                **  **         @author: Jimy_Fengqi            **  **************************************************     '''  print u'''使用说明:直接使用关键词做参数即可比如:python test.py framework    就可以把framework 分支下载下来                  '''  script,first = argvprint "the script is called:", scriptprint "the first variable is:", firstrepo_new_project(first)


1 0