-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
177 lines (160 loc) · 4.82 KB
/
test.py
File metadata and controls
177 lines (160 loc) · 4.82 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import os
import shutil
import subprocess
import fileinput
import time
import sys
import util
#from commands import *
def test1():
output = subprocess.check_output(
'echo to stdout; echo to stderr 1>&2; exit 1',
shell=True,
stderr=subprocess.STDOUT,
)
print 'Have %d bytes in output' % len(output)
print output
def test2():
idFilePath = r"D:\tmp\ticket\TMobile\Tmous-user.txt"
for line in fileinput.input(idFilePath):
decIDString = line.strip("\n")
strHex =hex(int(decIDString))
strLen = len(strHex)
strHex = "0-"+strHex[2:strLen-1]+"-0"
print strHex
def getUserHexList():
userList = []
idFilePath = r"D:\tmp\ticket\TMobile\Tmous-user.txt"
for line in fileinput.input(idFilePath):
decIDString = line.strip("\n")
strHex =hex(int(decIDString))
strLen = len(strHex)
strHex = "0-"+strHex[2:strLen-1]+"-0"
print strHex
userList.append(strHex)
return userList
pass
def test3():
userList = getUserHexList()
'''
userList = ["0-143c1339748b0-0","0-143c1339747f9-0","0-143c133974775-0",
"0-143c133974556-0","0-143c1339745b9-0","0-143c1339745e3-0",
"0-143c13397437f-0","0-143c133974467-0","0-143c133974236-0"]
'''
print userList
crcsPath = r"D:\tmp\ticket\TMobile\crcs.log"
filteredCRCSPath = r"D:\tmp\ticket\TMobile\filter-crcs.log"
with open(filteredCRCSPath, "w") as resultFile:
for line in fileinput.input(crcsPath):
tempLine = line.strip("\n").split(",")
if tempLine[1] in userList:
resultFile.write(line)
def splitCRCS(crcsPath):
userList = []
fileList = []
strPath = os.path.dirname(crcsPath)+os.sep+"splitCRCS"
if os.path.exists(strPath):
shutil.rmtree(strPath, ignore_errors=True)
os.mkdir(strPath)
for line in fileinput.input(crcsPath):
tempLine = line.strip("\n").split(",")
user = tempLine[1].strip()
index = -1
if user in userList:
index = userList.index(user, 0)
if index>=0:
userFile = fileList[index]
userFile.write(line)
else:
userList.append(user)
strOpenFile = strPath+os.sep+user+".csv"
userFile = open(strOpenFile,"w")
fileList.append(userFile)
userFile.write(line)
for userFile in fileList:
userFile.close()
pass
def testSplitFile():
strCRCSPath = ""
if len(sys.argv)>1:
strCRCSPath = sys.argv[1].strip()
if not strCRCSPath:
strCRCSPath = os.curdir+os.sep+"crcs.csv"
if os.path.exists(strCRCSPath):
splitCRCS(strCRCSPath)
else:
print "file %s does not exist" %(strCRCSPath)
def testGetFirst():
strPath = r"D:\tmp\ticket\TMobile\08-11\upc.log"
userList = []
upcList = []
for tempLine in fileinput.input(strPath):
struser = tempLine.split(",")[1]
if not struser in userList:
userList.append(struser)
upcList.append(tempLine)
print struser
print len(userList)
print userList
print "upc list:"
for upc in upcList:
print upc,
def test4():
str ="abc"
splitList = str.split(":")
print len(splitList)
print "%s" %(",".join(splitList))
pass
def test5():
import fileinput
userList = []
userTimeList = []
filePath = r"D:\tmp\ticket\temp\a"
for line in fileinput.input(filePath):
dt,user = line.split(",")
user = user.strip("\n")
if not user in userList:
userList.append(user)
userTimeList.append((user,dt))
for userInfo in userTimeList:
print "%s:%s" %(userInfo[0],userInfo[1])
def test6():
for i in range(10):
strPath = r"D:\tmp\ticket\17946\temp"+os.sep+str(1)+"-"+str(i)+".log"
with open(strPath,"w") as tempFile:
pass
import multiprocessing
def newProcessor():
print "new processor"
pcdPath = r"D:\Project\Analysis\pcd.jar"
pcdPath = pcdPath.strip()
if os.path.exists(pcdPath):
runPCDCommand = "java -Xmx1048m -jar %s" %(pcdPath,)
print runPCDCommand
result = util.shell_execute(runPCDCommand)
print result
print "end new processor"
pass
def test7():
p = multiprocessing.Process(target=newProcessor)
p.start()
print "end test7"
class A(object):
def runProcess(self):
p = multiprocessing.Process(target=self.worker,args=("hello",))
p.start()
pass
def worker(self,str):
print str
if __name__=="__main__":
print "start"
time.clock()
#test7()
#a = A()
#a.runProcess()
#test4()
#testSplitFile()
#testGetFirst()
print "finished"
print "cost time: %d seconds" %(time.clock())
pass