1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
| #!/usr/bin/env python
#-*- coding: UTF-8 -*-
import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
import xlrd
import os
import shutil
sheet_name=[u'TP应用列表',u'TP服务器列表',u'CC应用列表',u'CC服务器列表',u'FP应用列表',u'FP服务器列表',u'EC应用列表',u'EC服务器列表',u'PA应用列表',u'PA服务器列表',u'外包应用列表',u'外包服务器列表']
filedir=os.path.dirname(os.path.abspath(__file__))
if len(sys.argv)!=2:
raise AssertionError('需要参数:配置路径')
#ininame=sys.argv[1]+".ini"
confpath=sys.argv[1].rstrip("/Sessions")
if not os.path.exists(confpath+"/vbs/"):
os.makedirs(confpath+"/vbs/")
#ininamepath=os.path.join(filedir,"ininame")
#ininames=os.listdir(ininamepath)
#inidir=os.path.join(filedir,"ini")
vbsdir=os.path.join(confpath,"vbs")
path=os.path.join(filedir,"howbuy.xls")
class DataToSql:
def __init__(self,path):
self.data = xlrd.open_workbook(path)
def dataToSql(self,num,string):
sysdata=self.data.sheet_by_name(sheet_name[num])
sysrows = sysdata.nrows
if os.path.exists(confpath+"/Sessions/"+string):
shutil.rmtree(confpath+"/Sessions/"+string)
for sysrow in range(1,sysrows):
sysrowvalue = sysdata.row_values(sysrow)
ip=sysrowvalue[1].strip()
ipvbs=os.path.join(vbsdir,ip+".vbs")
appname=string+"/"+sysrowvalue[0].strip()
#ipvbs1=os.path.join(vbsdir,appname+'/'+ip+".vbs")
#ipvbs2=os.path.join(vbsdir,appname)
#appnamepath=os.path.join(inidir,appname)
if not os.path.exists(confpath+"/Sessions/"+appname):
os.makedirs(confpath+"/Sessions/"+appname)
file_object_read = open(confpath+"/Sessions/10.50.50.245.xsh", 'r')
stringsave=""
stringread=file_object_read.readline()
while stringread:
stringread=stringread.replace('ScriptPath=', 'ScriptPath='+confpath+'\\vbs\\'+ip+'.vbs')
stringsave=stringsave+stringread
stringread=file_object_read.readline()
file_object_save = open(confpath+"/Sessions/"+appname+"/"+ip+".xsh", 'w')
file_object_save.write(stringsave)
file_object_read.close()
file_object_save.close()
if not os.path.exists(ipvbs):
file_object_read = open(filedir+"/"+"xshellvbs.txt", 'r')
stringsave=""
stringread=file_object_read.readline()
while stringread:
stringread=stringread.replace('tihuan','/i:'+ip)
stringsave=stringsave+stringread
stringread=file_object_read.readline()
file_object_save = open(ipvbs, 'w')
file_object_save.write(stringsave)
file_object_read.close()
file_object_save.close()
data=DataToSql(path)
try:
data.dataToSql(1,"TP")
except:
print "tp no data"
try:
data.dataToSql(3,"CC")
except:
print "cc no data"
try:
data.dataToSql(5,"FP")
except:
print "fp no data"
try:
data.dataToSql(7,"EC")
except:
print "ec no data"
try:
data.dataToSql(9,"PA")
except:
print "pa no data"
try:
data.dataToSql(11,"WB")
except:
print "wb no data"
|