ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/MW/Summation_ViewerPy.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
Original Path: Python/NinoCode/MW/Summation_ViewerPy.py
File size: 6560 byte(s)
Log Message:
Initial Import

File Contents

# Content
1 ## Summation_ViewerPy.py
2 ##
3 ## EBorges
4 ## 08.19.03
5
6 import os,shutil
7
8
9 def GetBatesList():
10 projectList = open(projectFile,'r').readlines()
11 batesList = []
12 for x in projectList:
13 x = x.split(',')
14 batesList.append(x[0])
15 print len(batesList)
16 return batesList
17
18 def CreateMatrix(batesList,imagesDir):
19 clear = open(r'C:\test_dir\CSX\error.log','w').close()
20 clear = open(r'C:\test_dir\CSX\WorkFile.log','w').close()
21 tiffLookupDB = open(tiffLookupFile,'r').readlines()
22 for beginBates in batesList:
23 position = 0
24 for location in tiffLookupDB:
25 found = location.find(beginBates)
26 if found != -1:
27 break
28 else:
29 position = position + 1
30 if found == -1:
31 print "%s was not found in the database...\n"%(beginBates)
32 err = open(r'C:\test_dir\CSX\error.log','a')
33 err.write("%s was not found in the database...\n"%(beginBates))
34 err.close()
35 #test = raw_input("stoped")
36 else:
37 fileLocation = tiffLookupDB[position]
38 Paths = FormatPath(fileLocation)
39 for path in Paths:
40 print "%s is found at location %s"% (beginBates,path)
41 output = open(r'C:\test_dir\CSX\WorkFile.log','a')
42 output.write("%s is found at location %s"% (beginBates,path))
43 output.close()
44
45 def FormatPath(fileLocation):
46 """This function will return a list of paths for a particular bates"""
47 fileLocation = fileLocation.split(",")
48 locations = []
49 locations.append(fileLocation[2].replace('\n',''))
50 if ";" in locations[0]:
51 locations = HandleMulti(locations)
52 #print locations
53 Paths = []
54 for location in locations:
55 if fileLocation == '""':
56 newFileLocation = imagesDir + "\\" + location.strip() + '\n'
57 else:
58 newFileLocation = imagesDir + "\\" + fileLocation[1].strip() + "\\" + location.strip() + '\n'
59 #newFileLocation = "\\" + fileLocation[1].strip() + "\\" + location.strip()
60 #newFileLocation = `newFileLocation`
61 #newFileLocation = os.path.normpath(newFileLocation)
62 #newFileLocation = str(newFileLocation)
63 #newFileLocation = imagesDir + newFileLocation + '\n'
64 Paths.append(newFileLocation.replace('"',''))
65 #print Paths
66 return Paths
67
68
69 def HandleMulti(fileLocation):
70 """This function will handle multiple listings seperated by a semi-colon ;"""
71 #print fileLocation
72 #locations = []
73 for x in fileLocation:
74 locations=x.split(';')
75 return locations
76
77
78 def ProcessJobFile(verify=0):
79 """This function will process the Job file that was created by CreateMatrix"""
80 r = open(r'C:\test_dir\CSX\WorkFile.log','r')
81 contents = r.readlines()
82 r.close()
83 for line in contents:
84 line = line.split('location ')
85 line = line[1].strip()
86 processPath = os.path.normpath(line)
87 if '{' in processPath:
88 print "Span found! Processing %s"% processPath
89 HandleSpan(processPath,verify)
90 else:
91 print "Single image found. Processing %s\n"% processPath
92 CopyFile(processPath,verify)
93 #out = open(r'C:\test_dir\CSX\temp.log','a')
94 #out.write(processPath + '\n')
95 #out.close()
96
97 def CopyFile(absFile,verify):
98 destinationDir = imagesDir + "\\Printing" + os.path.split(absFile.split('CSX GRADE CROSSINGS DISCOVERY DATABASE\IMAGES')[1])[0]
99 print destinationDir
100 print "-"*80
101 print "copying %s\n"% absFile
102 try:
103 if verify == 0:
104 if os.path.exists(destinationDir) == 0:
105 os.makedirs(destinationDir)
106 shutil.copy2(absFile,destinationDir)
107 print "Done!\n"
108 copySuccess = open(r'C:\test_dir\CSX\copySuccess.log','a')
109 copySuccess.write(absFile+'\n')
110 copySuccess.close()
111 except:
112 print "This file could not be copied! It either dosent exist or something is wrong with the path..."
113 copyError = open(r'C:\test_dir\CSX\copyError.log','a')
114 copyError.write("I can't find or process %s \n"% absFile)
115 copyError.close()
116
117 def HandleSpan(path,verify):
118 """This function will handle documents that have mapped ranges by converting those ranges to individule files"""
119 parts = path.split('{')
120 folder = parts[0]
121 part2 = parts[1]
122 span,ext =part2.split('}')
123 startSpan,endSpan = span.split('-')
124 startSpan = int(startSpan)
125 endSpan = int(endSpan)
126 endSpan = endSpan + 1
127 for i in range(startSpan,endSpan):
128 absFile = folder + str(i) + ext
129 CopyFile(absFile,verify)
130
131
132 if __name__ == '__main__':
133 imagesDir = r'\\mwcase001\iblazer\CaseData\CSX GRADE CROSSINGS DISCOVERY DATABASE\IMAGES'
134 tiffLookupFile = r'C:\test_dir\CSX\CSXWilliamsImages.txt'
135 projectFile = r'C:\test_dir\CSX\CSXWilliams.txt'
136 batesList = GetBatesList()
137 #CreateMatrix(batesList,imagesDir)
138 clear = open(r'C:\test_dir\CSX\copySuccess.log','w').close()
139 raw_input("A translation file has been created.\nPress any key to compile a work file and get the scope of the project...")
140 ProcessJobFile(1)
141 firstCount = len(open(r'c:\test_dir\CSX\copySuccess.log','r').readlines())
142 question = raw_input('A workfile has now been created.\nThere are %i individual files that will be copied.\nShould I process this file? (y/n) '% firstCount)
143 if question == 'y':
144 clear = open(r'C:\test_dir\CSX\copySuccess.log','w').close()
145 clear = open(r'C:\test_dir\CSX\copyError.log','w').close()
146 ProcessJobFile()
147 secondCount = len(open(r'c:\test_dir\CSX\copySuccess.log','r').readlines())
148 notCopiedCount = len(open(r'c:\test_dir\CSX\copyError.log','r').readlines())
149 filesOutstanding = firstCount-(secondCount+notCopiedCount)
150 print "All files have now been copied with the exception of %i files that I was not able to copy\nHere are the Stats:\n"
151 print "-"*80
152 print "There were %i files to be copied total.\n\n"% firstCount
153 print "%i \tfiles were copied successfully.\n"% secondCount
154 print "%i \tfiles were NOT copied because I couldent find them.\n"% notCopiedCount
155 print "There are %i files not accounted for.\n"% filesOutstanding
156
157