我的第一个python脚本
这是我写的第一个python脚本,将从芯片厂商得到的android4.0代码按source.android.com的项目划分方式传到本地服务器中。a.py内容:from __future__ import print_function#!/usr/bin/pythonBaseIcsPath = "/home/chuangyi/hi3716c/HiSTBAndroidV400R001C00
·
这是我写的第一个python脚本,将从芯片厂商得到的android4.0代码按source.android.com的项目划分方式传到本地服务器中。
a.py内容:
from __future__ import print_function
#!/usr/bin/python
BaseIcsPath = "/home/chuangyi/hi3716c/HiSTBAndroidV400R001C00SPC050/software/HiSTBAndroidV400R001C00SPC050B012/"
BaseRemotePath = "git@192.168.1.12:"
GIT = 'git'
from xml.dom.minidom import parse
import xml.dom.minidom
import optparse
import sys
import os
import stat
import subprocess
def execute_git_cmd(path, cmd):
try:
proc = subprocess.Popen(cmd, cwd = (BaseIcsPath+path))
except OSError as e:
# print(file=sys.stderr)
print("fatal: %s" %e, file=sys.stderr)
sys.exit(1)
if proc.wait() != 0:
print("fatal: %s" %cmd)
sys.exit(2)
def upload_git(name,path):
print("upload_git: name=%s, path=%s" % (name, path))
cmd1 = [GIT, "init", '--quiet']
cmd2 = [GIT, "add", '.']
cmd3 = [GIT, "commit", '-a', '-m', 'init version']
cmd4 = [GIT, "remote", 'add', 'origin', BaseRemotePath+name]
cmd5 = [GIT, "push", 'origin', 'master']
execute_git_cmd(path, cmd1)
execute_git_cmd(path, cmd2)
execute_git_cmd(path, cmd3)
execute_git_cmd(path, cmd4)
execute_git_cmd(path, cmd5)
def main():
# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("manifest.xml")
collection = DOMTree.documentElement
# Get all the movies in the collection
movies = collection.getElementsByTagName("project")
print("project count=%d" % len(movies))
ii = 0
projectlist=""
for movie in movies:
ii = ii + 1
path = movie.getAttribute("path")
name = movie.getAttribute("name")
#print "path=%s, name=%s" % (path,name)
if not os.path.isdir(BaseIcsPath + path):
print("not find %s" % path)
else:
projectlist = projectlist + " " + name
upload_git(name, path)
# if ii == 1:
# upload_git(name, path)
# print("project list: %s" % projectlist)
if __name__ == '__main__':
main()
manifest.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="aosp"
fetch=".." />
<default revision="refs/tags/android-4.0.1_r1"
remote="aosp"
sync-j="4" />
<project path="build" name="platform/build">
<copyfile src="core/root.mk" dest="Makefile" />
</project>
<project path="abi/cpp" name="platform/abi/cpp" />
<project path="bionic" name="platform/bionic" />
<project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" />
<project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" />
<project path="bootable/recovery" name="platform/bootable/recovery" />
<project path="cts" name="platform/cts" />
<project path="dalvik" name="platform/dalvik" />
<project path="development" name="platform/development" />
。。。。。。
<project path="system/core" name="platform/system/core" />
<project path="system/extras" name="platform/system/extras" />
<project path="system/media" name="platform/system/media" />
<project path="system/netd" name="platform/system/netd" />
<project path="system/vold" name="platform/system/vold" />
</manifest>
更多推荐
已为社区贡献1条内容
所有评论(0)