ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Console.py
Revision: 303
Committed: Wed Mar 6 16:09:57 2013 UTC (13 years ago) by nino.borges
Content type: text/x-python
File size: 23108 byte(s)
Log Message:
Added initial support for upload and hosting pricing and added an initial gui dialog to change it.  Updated version to 1.8.0

File Contents

# Content
1 """
2
3 MCP_Console
4
5 Created by
6 Emanuel Borges
7 08.28.2010
8
9 This will be the interface to add, edit and archive cases.
10
11 Should this work as one large GUI and you pick the below or read from argv and let you
12 just call it with what you want, making these three look like separate apps.
13
14
15 """
16
17 import MCP_Lib,os,shutil,ConcordanceHelperTools, time,directorySize2
18
19 class MainConsole:
20 def __init__(self):
21 ## Gather the case list
22
23 print "connecting to matter tracking access db..."
24 ## Production version
25 self.accessDB = MCP_Lib.AccessDBConnection(r"\\chiads01\app\DS_CaseTrack\TPM_CaseTracking.mdb")
26 self.tPMName, self.tPMID, self.tPMOffice = MCP_Lib.GetTPMInfo()
27 #responsibleCases,casesDir = MCP_Lib.GetCaseList('',self.accessDB)
28 myCases, officeCases, allCases,casesDir= MCP_Lib.GetCaseList('',self.accessDB)
29
30 ## Testing version
31 #self.accessDB = MCP_Lib.AccessDBConnection(r"W:\Manny\testing\TPM_CaseTracking.mdb")
32 #responsibleCases,casesDir = MCP_Lib.GetCaseList(r"C:\Documents and Settings\eborges\My Documents\My Dropbox\Dev\Python\NinoCode\Active_prgs\Concordance\MCP",self.accessDB)
33 #self.tPMName, self.tPMID, self.tPMOffice = MCP_Lib.GetTPMInfo(r"C:\Documents and Settings\eborges\My Documents\My Dropbox\Dev\Python\NinoCode\Active_prgs\Concordance\MCP")
34
35 print "connected to DB."
36
37 self.responsibleCasesList = myCases
38 self.casesDir = casesDir
39
40
41 def AddNewCase(self, caseName, clientMatter, chargable = False, reviewPlatform = "", responsibleProcessingVendor = "",
42 responsibleScanningVendor = "",responsibleHostingVendor = ""):
43 ## Add the local folders The GUI should test that the clm is 10 digits and has hyphen.
44 template = os.path.join(self.casesDir,'_Template_')
45 new = os.path.join(self.casesDir, caseName + '_(%s)'%clientMatter)
46 if os.path.exists(new):
47 print "ERROR: This case already exists!!"
48 else:
49 #print template
50 #print new
51 os.mkdir(new)
52 for file in os.listdir(template):
53 shutil.copy2(os.path.join(template,file),new)
54 ## Check the H drive for the supplemental folders and the matter folder, only if they select Concordance.
55 self.SetCaseNameAndCLM(caseName,clientMatter)
56 self.AddCaseToAccessDB(caseName,clientMatter)
57
58 def AddCaseToAccessDB(self, caseName, clientMatter):
59 ## First test to see if it's already in the DB.
60 fullClientMatterList = self.accessDB.RetrieveAllCaseList()
61 clientMatter = clientMatter.replace("-",".")
62 if clientMatter in fullClientMatterList:
63 print "This client matter already exists in the database. Skipping."
64 else:
65 print "New client matter. Adding."
66 self.accessDB.AddNewCase(caseName, clientMatter, self.tPMName,self.tPMID,responsibleOffice = self.tPMOffice)
67 print "Added!"
68
69 def EditCaseData(self,caseName,chargeableBool,respAttorney,respParalegal,respVendorTpl,revPlatform,respTPM,respOffice, caseStatus):
70 clientMatter = caseName.split("_(")[1]
71 clientMatter = clientMatter[:-1]
72 clientMatter = clientMatter.replace('-','.')
73 self.accessDB.UpdateChargable(clientMatter,chargeableBool)
74 self.accessDB.UpdateResponsibleAttorney(clientMatter,respAttorney)
75 self.accessDB.UpdateResponsibleParalegal(clientMatter,respParalegal)
76 self.accessDB.UpdateReviewPlatform(clientMatter,revPlatform)
77 self.accessDB.UpdateResponsibleTPM(clientMatter,respTPM)
78 self.accessDB.UpdatePrimaryOffice(clientMatter,respOffice)
79 self.accessDB.UpdateResponsibleVendors(clientMatter,respVendorTpl)
80 self.accessDB.UpdateCaseStatus(clientMatter, caseStatus)
81
82 def GetCaseData(self, caseName):
83 #use this to get the data on the selected case, to populate your GUI
84 clientMatter = caseName.split("_(")[1]
85 clientMatter = clientMatter[:-1]
86 clientMatter = clientMatter.replace('-','.')
87 chargeableBool = self.accessDB.GetChargable(clientMatter)
88 respAttorney = self.accessDB.GetResponsibleAttorney(clientMatter)
89 respParalegal = self.accessDB.GetResponsibleParalegal(clientMatter)
90 respVendorTpl = self.accessDB.GetResponsibleVendorTpl(clientMatter)
91 revPlatform = self.accessDB.GetReviewPlatform(clientMatter)
92 respTPM = self.accessDB.GetResponsibleTPM(clientMatter)
93 respOffice = self.accessDB.GetPrimaryOffice(clientMatter)
94 caseStatus = self.accessDB.GetCaseStatus(clientMatter)
95 uploadCost = self.accessDB.GetUploadCostRate(clientMatter)
96 storageCost = self.accessDB.GetStorageCostRate(clientMatter)
97 return (chargeableBool,respAttorney,respParalegal,respVendorTpl,revPlatform,respTPM,respOffice,caseStatus,uploadCost,storageCost)
98
99 def AddProductionEntry(self, CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes):
100 """This method adds one production entry to the case."""
101 errRpt = True
102 if CLM:
103 if prodID:
104 if prodDate:
105 if begBates:
106 if endBates:
107 if prodDocCount:
108 if prodPageCount:
109 if prodNotes:
110 self.accessDB.UpdateProductionDetail(CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes)
111 errRpt = False
112 return errRpt
113
114 def AddDataUpload(self,CLM, reviewPlatform, reportSize):
115 """This method will add one case upload."""
116 ## TODO: one day change it so that copy up requst calls this instead
117 ## of it being internal to that prog.
118 epoch = str(int(time.time()))
119 self.accessDB.UpdateCaseUpload(CLM,reviewPlatform,{epoch:(time.strftime('%m/%d/%Y'),reportSize)})
120
121 def RemoveDataUpload(self,CLM,UEPOCH):
122 """This method calls DeleteCaseUpload and removes just one case upload. """
123 err = self.accessDB.DeleteCaseUpload(CLM,UEPOCH)
124 if err:
125 print "ERROR: An Error occured and this value was not removed!"
126 else:
127 print "%s Removed"% UEPOCH
128
129 def GetUploadData(self, caseName):
130 # Used to get upload data, on the selected case, to populate the upload dialog
131 clientMatter = caseName.split("_(")[1]
132 clientMatter = clientMatter[:-1]
133 clientMatter = clientMatter.replace('-','.')
134 uploadList = self.accessDB.RetrieveUploadsByCLM(clientMatter)
135 return uploadList
136
137 def GetProductionData(self,caseName):
138 clientMatter = caseName.split("_(")[1]
139 clientMatter = clientMatter[:-1]
140 clientMatter = clientMatter.replace('-','.')
141 productionList = self.accessDB.RetrieveProductionsByCLM(clientMatter)
142 return productionList
143
144 def GetProductionTotal(self,productionList):
145 """Using the above productionList, this returns the total docs and pages produced"""
146 pgCountTotal = 0
147 docCountTotal = 0
148 for i in productionList:
149 pageCount = i[-2]
150 docCount = i[-3]
151 if 'None' in pageCount:
152 pass
153 else:
154 #print pageCount
155 pgCountTotal = pgCountTotal+int(pageCount)
156 if 'None' in pageCount:
157 pass
158 else:
159 #print docCount
160 docCountTotal = docCountTotal+int(docCount)
161 return pgCountTotal,docCountTotal
162
163 def ExportProductionDataToExcel(self,CaseName,pathToCSV):
164 """Exports the production data to a csv file"""
165 productionList = self.GetProductionData(CaseName)
166 #print productionList
167 outputFile = open(pathToCSV,'w')
168 outputFile.write('Production ID,Production Date,Start Bates,End Bates,Document Count,Page Count,Notes\n')
169 for i in productionList:
170 for x in i:
171 outputFile.write(x+",")
172 outputFile.write("\n")
173 outputFile.close()
174
175 def GetUploadTotal(self,uploadList):
176 """ Using the above uploadList, this will return the total uploaded """
177 count = 0.
178 for i in uploadList:
179 size = i[-1]
180
181 if 'None' in size:
182 pass
183 else:
184 rawSize = directorySize2.prettyToUnpretty_Filesize(size)
185 count = count + rawSize
186 prettySizeFinal = directorySize2.pretty_filesize2(count)
187 return prettySizeFinal
188
189 def MakeCaseDormant(self, caseAndCLM):
190 """Moves the case to the Dormant folder"""
191 print "Making %s case dormant..."
192 os.rename(os.path.join(self.casesDir,caseAndCLM),os.path.join(self.casesDir,os.path.join('zzzz_dormant_', caseAndCLM)))
193 print "Case has been archived."
194
195
196 def ViewCaseNotes(self,caseName,office):
197 """Trys to open the case notes file,in the case folder, for the active case, regardless who owns it."""
198 caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
199 clientMatter = caseName.split("_(")[1]
200 clientMatter = clientMatter[:-1]
201 if "." in clientMatter:
202 clientMatter = clientMatter.replace('.','-')
203 folderMatrix = {}
204 #caseFolderLocation = os.path.join(caseFolderLocation,case)
205 err = False
206 if caseFolderLocation:
207 if os.path.exists(caseFolderLocation):
208 for f in os.listdir(caseFolderLocation):
209 if "_(" in f:
210 folderClientMatter = f.split("_(")[1]
211 folderClientMatter = folderClientMatter[:-1]
212 folderMatrix[folderClientMatter] = f
213 try:
214 folderName = folderMatrix[clientMatter]
215 os.startfile(os.path.join(caseFolderLocation, folderName)+"/Gen_Notes.txt")
216 except:
217 err = True
218 else:
219 err = True
220 else:
221 print "A case folder for this case was not found."
222 err = True
223 return err
224
225 def ViewProdSpec(self,caseName,office):
226 """Trys to open the prod spec file,in the case folder, for the active case, regardless who owns it."""
227 caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
228 clientMatter = caseName.split("_(")[1]
229 clientMatter = clientMatter[:-1]
230 if "." in clientMatter:
231 clientMatter = clientMatter.replace('.','-')
232 folderMatrix = {}
233 #caseFolderLocation = os.path.join(caseFolderLocation,case)
234 err = False
235 if caseFolderLocation:
236 if os.path.exists(caseFolderLocation):
237 for f in os.listdir(caseFolderLocation):
238 if "_(" in f:
239 folderClientMatter = f.split("_(")[1]
240 folderClientMatter = folderClientMatter[:-1]
241 folderMatrix[folderClientMatter] = f
242 try:
243 folderName = folderMatrix[clientMatter]
244 os.startfile(os.path.join(caseFolderLocation, folderName+"/Production_Spec.txt"))
245 except:
246 err = True
247 else:
248 err = True
249 else:
250 print "A case folder for this case was not found."
251 err = True
252 return err
253
254 def OpenAlternateMediaFolder(self,caseName,office):
255 """Trys to open the Alternate media folder, for the active case, regardless who owns it."""
256 clientMatter = caseName.split("_(")[1]
257 clientMatter = clientMatter[:-1]
258 clientMatter = clientMatter.replace('-','.')
259 altMediaPath = self.accessDB.GetAlternateMediaPath(clientMatter)
260 err = False
261 if altMediaPath:
262 if os.path.exists(altMediaPath):
263 os.startfile(altMediaPath)
264 else:
265 print "An alternate media folder for this case was not found."
266 err = True
267 else:
268 err = True
269 return err
270
271 def SetAlternateMediaFolder(self,caseName,altMediaPath):
272 """Sets the alternate Media Path"""
273 clientMatter = caseName.split("_(")[1]
274 clientMatter = clientMatter[:-1]
275 clientMatter = clientMatter.replace('-','.')
276 self.accessDB.UpdateAlternateMediaPath(clientMatter,altMediaPath)
277
278 def GetVendorFolders(self,caseName):
279 """Returns the current list of vendor folders, for one case"""
280 clientMatter = caseName.split("_(")[1]
281 clientMatter = clientMatter[:-1]
282 clientMatter = clientMatter.replace('-','.')
283 vendorFolders = self.accessDB.GetVendorFolderPath(clientMatter)
284 #print "V%s "%vendorFolders
285 return vendorFolders
286
287 def SetVendorFolders(self,caseName, vendorFolders):
288 """Sets the Vendor Folder"""
289 clientMatter = caseName.split("_(")[1]
290 clientMatter = clientMatter[:-1]
291 clientMatter = clientMatter.replace('-','.')
292 self.accessDB.UpdateVendorFolderPath(clientMatter,vendorFolders)
293
294 def GetVendorFoldersList(self):
295 """Returns a list of all vendorFolders"""
296 ## Change this so that it actually grabs the current ones from ln. Dont know if I should grab from a table in access.
297 vendorFolderList = ["None"]
298 for n in range(1,61):
299 vendorFolderList.append("mwevendor%0*d"%(2,n))
300 return vendorFolderList
301
302 def GetCasePathsData(self,caseName, office):
303 clientMatter = caseName.split("_(")[1]
304 clientMatter = clientMatter[:-1]
305 clientMatter = clientMatter.replace('-','.')
306 altMediaPath = self.accessDB.GetAlternateMediaPath(clientMatter)
307 caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
308 caseFolderLocation = os.path.join(caseFolderLocation,caseName)
309 return altMediaPath, caseFolderLocation
310
311 def SetUploadAndStorageCosts(self, caseName,uploadCost,storageCost):
312 clientMatter = caseName.split("_(")[1]
313 clientMatter = clientMatter[:-1]
314 clientMatter = clientMatter.replace('-','.')
315 self.accessDB.UpdateUploadCostRate(clientMatter,uploadCost)
316 self.accessDB.UpdateStorageCostRate(clientMatter,storageCost)
317
318 def OpenCaseFolder(self,caseName,office):
319 """Trys to open the case folder for the active case, regardless who owns it."""
320 caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
321 clientMatter = caseName.split("_(")[1]
322 clientMatter = clientMatter[:-1]
323 if "." in clientMatter:
324 clientMatter = clientMatter.replace('.','-')
325 folderMatrix = {}
326 #caseFolderLocation = os.path.join(caseFolderLocation,case)
327 err = False
328 if caseFolderLocation:
329 if os.path.exists(caseFolderLocation):
330 for f in os.listdir(caseFolderLocation):
331 if "_(" in f:
332 folderClientMatter = f.split("_(")[1]
333 folderClientMatter = folderClientMatter[:-1]
334 folderMatrix[folderClientMatter] = f
335 try:
336 folderName = folderMatrix[clientMatter]
337 os.startfile(os.path.join(caseFolderLocation, folderName))
338 except:
339 err = True
340 else:
341 err = True
342 else:
343 print "A case folder for this case was not found."
344 err = True
345 return err
346
347
348 def SetCaseNameAndCLM(self, newCaseName, newClientMatterNumber):
349 """Used when setting up a new case. Should have both or nothing"""
350 self.caseName = newCaseName
351 self.clientMatter = newClientMatterNumber
352 #print self.clientMatter
353
354 def SetChargableCase(self, chargBool):
355 """sets or clears the chargable case settings"""
356 pass
357 def SetResponsibleVendor(self, vendorInfo):
358 """Sets the vendor name that is responsible for the case"""
359 pass
360 def SetReviewPlatform(self, reviewPlatform):
361 """Sets the review platform chosen for this case"""
362 if reviewPlatform == "Concordance":
363 print "Concordance selected. Creating DIS directories..."
364 hDrivePath = ConcordanceHelperTools.ParseClientMatter(self.clientMatter)
365 os.mkdir(hDrivePath)
366 print "Matter folder created."
367 os.mkdir(os.path.join(hDrivePath,'Match'))
368 os.mkdir(os.path.join(hDrivePath,'Tag_Databases'))
369 print "Supplemental folders created."
370 print "DIS directories done!"
371
372
373
374 def SyncWithAccessDB(self,case = 'ALL'):
375 """Syncs your cases with the access database. This might only get run once when you first install
376 the program though..."""
377 ## So this syncs 'your' databases only. even though you are looking at a list of eeryone's databases
378 ## it will only sync yours. even if you did an upload for another tpm, that wouldnt get synced unles
379 ## the owner did a sync all. for 2 way sync to work, you should check, in access, that they have the case name
380 ## (with no funky characters) populated, before they run this for the first time.
381 if case == 'ALL':
382 ## verify that all your cases are up there, if not add it. but have support for cases where is should be
383 ## yours but is assigned to someone else...
384 fullClientMatterList = self.accessDB.RetrieveAllCaseList()
385 myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
386 myLocalClientMatterList = []
387
388 ## Sync cases from my local to access
389 for case in self.responsibleCasesList:
390 localCaseName,clientMatter = case.split("_(")
391 clientMatter = clientMatter.replace(")","")
392 clientMatter = clientMatter.replace("-",".")
393 myLocalClientMatterList.append(clientMatter)
394 for clm in myLocalClientMatterList:
395 if clm in myAccessClientMatterList:
396 print "%s exists"% clm
397 elif clm in fullClientMatterList:
398 print "%s cant be added to your cases because it's owned by someone else..."% clm
399 else:
400 print "%s does not exist in the database. Adding it..."% clm
401 self.AddCaseToAccessDB(localCaseName,clientMatter)
402
403 ## Sync cases from Access to my local
404
405
406 uploadReportMatrix = {}
407 for caseName in self.responsibleCasesList:
408 print "now processing %s"% caseName
409 casePath = os.path.join(self.casesDir,caseName)
410 if os.path.exists(os.path.join(casePath,"UploadReport.txt")):
411 print "yup"
412 caseUploadContents = open(os.path.join(casePath,"UploadReport.txt")).readlines()
413 clientMatter = caseName.split("_(")[1]
414 clientMatter = clientMatter.replace(")","")
415 clientMatter = clientMatter.replace("-",".")
416 for i in caseUploadContents:
417 i = i.replace("\n","")
418 i = i.replace(" | ","|")
419 try:
420 uploadReportMatrix[clientMatter].append(("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3]))
421 except:
422 uploadReportMatrix[clientMatter] = [("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3])]
423 #print uploadReportMatrix
424
425 accessMyCaseUploads = self.accessDB.RetrieveMyCaseUploads('09756')
426 for x in uploadReportMatrix.keys():
427 localCaseUploadList = uploadReportMatrix[x]
428 tempMatrix = {}
429 try:
430 accessCaseUploadList = accessMyCaseUploads[x]
431 #print accessCaseUploadList
432 for y in localCaseUploadList:
433 epoch = y[0]
434 if int(epoch) > 1298462400:
435 #print epoch
436 reviewPlatform = y[1]
437 reportSize = y[3]
438 #print "."
439 #print accessCaseUploadList
440 if epoch in accessCaseUploadList:
441 print "%s, in the %s case, is already in there, skipping."%(y,x)
442 else:
443 print "%s, in the %s case, is missing. Will be added..."%(y,x)
444 date = y[2]
445 date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
446
447 self.accessDB.UpdateCaseUpload(x,reviewPlatform,{epoch:(date,reportSize)})
448 #tempMatrix[epoch] = [platform,(date,size)]
449 else:
450 #print "This entry is pre cutover"
451 pass
452 except KeyError:
453 print "nothing for this one"
454 for z in localCaseUploadList:
455 print "%s, in the %s case, is missing. Will be added..."%(z,x)
456 date = z[0]
457 date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
458 #try:
459 # tempMatrix[date].append(z[1])
460 #except:
461 # tempMatrix[date] = [z[1]]
462 #print tempMatrix
463 #if tempMatrix:
464 # #print tempMatrix
465 # self.accessDB.UpdateCaseUpload(x,'Concordance DIS', tempMatrix)
466 #pass
467
468
469 #print myLocalClientMatterList
470 ## verify that all of your uploads are up there, if not, add it.
471 self.accessDB.CloseAccessConnection()
472
473 else:
474 fullClientMatterList = self.accessDB.RetrieveAllCaseList()
475 myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
476
477