第二次感觉有很大进步,对列表使用慢慢熟悉,继续加油。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import csv
import codecs
import re
import sys
from copy import deepcopy
print 'Run:',sys.argv[0]
csvTitle = [‘A’,
‘B’,
‘C’,
‘templet’,
]
1
print csvTitle
teamName = [‘A’,
‘B’,
‘C’,
‘route_templet’,
'S'
]
route_a =[]
route_b =[]
route_c =[]
#route_templet =[]
dict_route = {teamName[0]:route_a,
teamName[1]:route_b,
teamName[2]:route_c,
#teamName[6]:route_templet,
}
#宏
csvTitleLen = len(csvTitle)
teamNameLen = len(teamName)
inpath = ‘H:C\表.csv’
source = ‘xcopy /y /S /I H:\’
target = ’ %WORKSPACE%\code\’
bat_fileName = “code_xcopy.bat”
bat_routeName = “route.txt”
#文件生成路径
outPath =[]
for outDir in teamName:
outPath.append(“G:/workspace/CCM/” + outDir + “/bat”)
#深拷贝
dict_col_route = deepcopy(dict_route)#从csv文件获取的的代码路径数据
dict_bat_route = deepcopy(dict_route)#输出到bat文件的代码路径数据
dict_out_route = deepcopy(dict_route)#输出到txt文件的代码路径数据
def printDict(dict_route,i):
for i in dict_route[teamName[i]]:
print i
def getData(path):
uipath = unicode(path,"utf8")
data = open(uipath,'r')
return csv.reader(data)
def csv_prase(path,dict_route):
dataline = getData(path)
for row in dataline:
for i in range (0,csvTitleLen):
if row[1] == csvTitle[i]:
dict_route[teamName[i]].append(row[5])
def change_route(route, bat_route, out_route):
route = route.replace('/','\\')
route = route.rstrip('\\')
if route.find(‘_pm’) == 0:
route = route.replace(‘opm’,‘R\co\olm’,1)
bat_route.append(source + route + target + route)
elif route.find(‘00’) == 0:
route = route.replace(‘00’,‘NG\c0’,1)
bat_route.append(source + route + target + route)
elif route.find(‘ub’) == 0:
route.replace(‘ub’,‘oub’,1)
else :
bat_route.append(source + route + target + route)
out_route.append(route)
def route_prase(path,col_route,bat_route,out_route):
csv_prase(path,col_route)
for i in range (0,teamNameLen):
print '********************************************************'
print teamName[i]
print '********************************************************'
for route in col_route[teamName[i]]:
change_route(route,bat_route[teamName[i]], out_route[teamName[i]])
printDict(out_route,i)
def del_route_bat(targetPath, fileName):
pwd = os.getcwd()
os.chdir(targetPath)
if os.path.exists(fileName):
os.remove(fileName)
os.chdir(pwd)
def add_route_bat(str_r,targetPath, bat_route, fileName):
pwd = os.getcwd()
os.chdir(targetPath)
f = file(fileName, "a+")
f = open(fileName, "w")
f.write(str_r)
f.write('\n')
f.write('\n')
for line in bat_route:
f.write(line)
f.write('\n')
f.close
os.chdir(pwd)
def dat_del_opr(path,fileName):
for i in path:
del_route_bat(i, fileName)
def dat_add_opr(str_r,path,fileName,dict_route):
dat_del_opr(path,fileName)
for i in range (0,teamNameLen):
add_route_bat(str_r,path[i],dict_route[teamName[i]], fileName)
if (__name__ == "__main__"):
route_prase(inpath,dict_col_route,dict_bat_route,dict_out_route)
dat_add_opr('g:',outPath,bat_fileName,dict_bat_route)
dat_add_opr(' ',outPath,bat_routeName,dict_out_route)