ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Console.py
Revision: 265
Committed: Mon Feb 4 18:47:35 2013 UTC (13 years, 1 month ago) by nino.borges
Content type: text/x-python
File size: 21482 byte(s)
Log Message:
Finished and tested Alternate Media Path feature with settings feature.

File Contents

# User Rev Content
1 ninoborges 8 """
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 nino.borges 189 #responsibleCases,casesDir = MCP_Lib.GetCaseList('',self.accessDB)
28     myCases, officeCases, allCases,casesDir= MCP_Lib.GetCaseList('',self.accessDB)
29 ninoborges 8
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 nino.borges 189 self.responsibleCasesList = myCases
38 ninoborges 8 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     return (chargeableBool,respAttorney,respParalegal,respVendorTpl,revPlatform,respTPM,respOffice,caseStatus)
96    
97     def AddProductionEntry(self, CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes):
98     """This method adds one production entry to the case."""
99     errRpt = True
100     if CLM:
101     if prodID:
102     if prodDate:
103     if begBates:
104     if endBates:
105     if prodDocCount:
106     if prodPageCount:
107     if prodNotes:
108     self.accessDB.UpdateProductionDetail(CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes)
109     errRpt = False
110     return errRpt
111    
112     def AddDataUpload(self,CLM, reviewPlatform, reportSize):
113     """This method will add one case upload."""
114     ## TODO: one day change it so that copy up requst calls this instead
115     ## of it being internal to that prog.
116     epoch = str(int(time.time()))
117     self.accessDB.UpdateCaseUpload(CLM,reviewPlatform,{epoch:(time.strftime('%m/%d/%Y'),reportSize)})
118    
119     def RemoveDataUpload(self,CLM,UEPOCH):
120     """This method calls DeleteCaseUpload and removes just one case upload. """
121     err = self.accessDB.DeleteCaseUpload(CLM,UEPOCH)
122     if err:
123     print "ERROR: An Error occured and this value was not removed!"
124     else:
125     print "%s Removed"% UEPOCH
126    
127     def GetUploadData(self, caseName):
128     # Used to get upload data, on the selected case, to populate the upload dialog
129     clientMatter = caseName.split("_(")[1]
130     clientMatter = clientMatter[:-1]
131     clientMatter = clientMatter.replace('-','.')
132     uploadList = self.accessDB.RetrieveUploadsByCLM(clientMatter)
133     return uploadList
134    
135     def GetProductionData(self,caseName):
136     clientMatter = caseName.split("_(")[1]
137     clientMatter = clientMatter[:-1]
138     clientMatter = clientMatter.replace('-','.')
139     productionList = self.accessDB.RetrieveProductionsByCLM(clientMatter)
140     return productionList
141    
142     def GetProductionTotal(self,productionList):
143     """Using the above productionList, this returns the total docs and pages produced"""
144     pgCountTotal = 0
145     docCountTotal = 0
146     for i in productionList:
147     pageCount = i[-2]
148     docCount = i[-3]
149     if 'None' in pageCount:
150     pass
151     else:
152     #print pageCount
153     pgCountTotal = pgCountTotal+int(pageCount)
154     if 'None' in pageCount:
155     pass
156     else:
157     #print docCount
158     docCountTotal = docCountTotal+int(docCount)
159     return pgCountTotal,docCountTotal
160    
161     def ExportProductionDataToExcel(self,CaseName,pathToCSV):
162     """Exports the production data to a csv file"""
163     productionList = self.GetProductionData(CaseName)
164     #print productionList
165     outputFile = open(pathToCSV,'w')
166     outputFile.write('Production ID,Production Date,Start Bates,End Bates,Document Count,Page Count,Notes\n')
167     for i in productionList:
168     for x in i:
169     outputFile.write(x+",")
170     outputFile.write("\n")
171     outputFile.close()
172    
173     def GetUploadTotal(self,uploadList):
174     """ Using the above uploadList, this will return the total uploaded """
175     count = 0.
176     for i in uploadList:
177     size = i[-1]
178    
179     if 'None' in size:
180     pass
181     else:
182     rawSize = directorySize2.prettyToUnpretty_Filesize(size)
183     count = count + rawSize
184     prettySizeFinal = directorySize2.pretty_filesize2(count)
185     return prettySizeFinal
186    
187     def MakeCaseDormant(self, caseAndCLM):
188     """Moves the case to the Dormant folder"""
189     print "Making %s case dormant..."
190     os.rename(os.path.join(self.casesDir,caseAndCLM),os.path.join(self.casesDir,os.path.join('zzzz_dormant_', caseAndCLM)))
191     print "Case has been archived."
192    
193    
194 nino.borges 158 def ViewCaseNotes(self,caseName,office):
195     """Trys to open the case notes file,in the case folder, for the active case, regardless who owns it."""
196     caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
197     clientMatter = caseName.split("_(")[1]
198     clientMatter = clientMatter[:-1]
199     if "." in clientMatter:
200     clientMatter = clientMatter.replace('.','-')
201     folderMatrix = {}
202     #caseFolderLocation = os.path.join(caseFolderLocation,case)
203     err = False
204     if caseFolderLocation:
205     if os.path.exists(caseFolderLocation):
206     for f in os.listdir(caseFolderLocation):
207     if "_(" in f:
208     folderClientMatter = f.split("_(")[1]
209     folderClientMatter = folderClientMatter[:-1]
210     folderMatrix[folderClientMatter] = f
211     try:
212     folderName = folderMatrix[clientMatter]
213     os.startfile(os.path.join(caseFolderLocation, folderName)+"/Gen_Notes.txt")
214     except:
215     err = True
216     else:
217     err = True
218     else:
219     print "A case folder for this case was not found."
220     err = True
221     return err
222    
223     def ViewProdSpec(self,caseName,office):
224     """Trys to open the prod spec file,in the case folder, for the active case, regardless who owns it."""
225     caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
226     clientMatter = caseName.split("_(")[1]
227     clientMatter = clientMatter[:-1]
228     if "." in clientMatter:
229     clientMatter = clientMatter.replace('.','-')
230     folderMatrix = {}
231     #caseFolderLocation = os.path.join(caseFolderLocation,case)
232     err = False
233     if caseFolderLocation:
234     if os.path.exists(caseFolderLocation):
235     for f in os.listdir(caseFolderLocation):
236     if "_(" in f:
237     folderClientMatter = f.split("_(")[1]
238     folderClientMatter = folderClientMatter[:-1]
239     folderMatrix[folderClientMatter] = f
240     try:
241     folderName = folderMatrix[clientMatter]
242     os.startfile(os.path.join(caseFolderLocation, folderName+"/Production_Spec.txt"))
243     except:
244     err = True
245     else:
246     err = True
247     else:
248     print "A case folder for this case was not found."
249     err = True
250     return err
251    
252 nino.borges 261 def OpenAlternateMediaFolder(self,caseName,office):
253     """Trys to open the Alternate media folder, for the active case, regardless who owns it."""
254     clientMatter = caseName.split("_(")[1]
255     clientMatter = clientMatter[:-1]
256     clientMatter = clientMatter.replace('-','.')
257     altMediaPath = self.accessDB.GetAlternateMediaPath(clientMatter)
258     err = False
259     if altMediaPath:
260     if os.path.exists(altMediaPath):
261     os.startfile(altMediaPath)
262     else:
263     print "An alternate media folder for this case was not found."
264     err = True
265     else:
266     err = True
267     return err
268 nino.borges 265
269     def SetAlternateMediaFolder(self,caseName,altMediaPath):
270     """Sets the alternate Media Path"""
271     clientMatter = caseName.split("_(")[1]
272     clientMatter = clientMatter[:-1]
273     clientMatter = clientMatter.replace('-','.')
274     self.accessDB.UpdateAlternateMediaPath(clientMatter,altMediaPath)
275 nino.borges 261
276 nino.borges 262 def GetCasePathsData(self,caseName, office):
277     clientMatter = caseName.split("_(")[1]
278     clientMatter = clientMatter[:-1]
279     clientMatter = clientMatter.replace('-','.')
280     altMediaPath = self.accessDB.GetAlternateMediaPath(clientMatter)
281     caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
282     caseFolderLocation = os.path.join(caseFolderLocation,caseName)
283     return altMediaPath, caseFolderLocation
284    
285 ninoborges 8 def OpenCaseFolder(self,caseName,office):
286     """Trys to open the case folder for the active case, regardless who owns it."""
287     caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
288     clientMatter = caseName.split("_(")[1]
289     clientMatter = clientMatter[:-1]
290     if "." in clientMatter:
291     clientMatter = clientMatter.replace('.','-')
292     folderMatrix = {}
293     #caseFolderLocation = os.path.join(caseFolderLocation,case)
294     err = False
295     if caseFolderLocation:
296     if os.path.exists(caseFolderLocation):
297     for f in os.listdir(caseFolderLocation):
298     if "_(" in f:
299     folderClientMatter = f.split("_(")[1]
300     folderClientMatter = folderClientMatter[:-1]
301     folderMatrix[folderClientMatter] = f
302     try:
303     folderName = folderMatrix[clientMatter]
304     os.startfile(os.path.join(caseFolderLocation, folderName))
305     except:
306     err = True
307     else:
308     err = True
309     else:
310     print "A case folder for this case was not found."
311     err = True
312     return err
313    
314    
315     def SetCaseNameAndCLM(self, newCaseName, newClientMatterNumber):
316     """Used when setting up a new case. Should have both or nothing"""
317     self.caseName = newCaseName
318     self.clientMatter = newClientMatterNumber
319     #print self.clientMatter
320    
321     def SetChargableCase(self, chargBool):
322     """sets or clears the chargable case settings"""
323     pass
324     def SetResponsibleVendor(self, vendorInfo):
325     """Sets the vendor name that is responsible for the case"""
326     pass
327     def SetReviewPlatform(self, reviewPlatform):
328     """Sets the review platform chosen for this case"""
329     if reviewPlatform == "Concordance":
330     print "Concordance selected. Creating DIS directories..."
331     hDrivePath = ConcordanceHelperTools.ParseClientMatter(self.clientMatter)
332     os.mkdir(hDrivePath)
333     print "Matter folder created."
334     os.mkdir(os.path.join(hDrivePath,'Match'))
335     os.mkdir(os.path.join(hDrivePath,'Tag_Databases'))
336     print "Supplemental folders created."
337     print "DIS directories done!"
338    
339    
340    
341     def SyncWithAccessDB(self,case = 'ALL'):
342     """Syncs your cases with the access database. This might only get run once when you first install
343     the program though..."""
344     ## So this syncs 'your' databases only. even though you are looking at a list of eeryone's databases
345     ## it will only sync yours. even if you did an upload for another tpm, that wouldnt get synced unles
346     ## the owner did a sync all. for 2 way sync to work, you should check, in access, that they have the case name
347     ## (with no funky characters) populated, before they run this for the first time.
348     if case == 'ALL':
349     ## verify that all your cases are up there, if not add it. but have support for cases where is should be
350     ## yours but is assigned to someone else...
351     fullClientMatterList = self.accessDB.RetrieveAllCaseList()
352     myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
353     myLocalClientMatterList = []
354    
355     ## Sync cases from my local to access
356     for case in self.responsibleCasesList:
357     localCaseName,clientMatter = case.split("_(")
358     clientMatter = clientMatter.replace(")","")
359     clientMatter = clientMatter.replace("-",".")
360     myLocalClientMatterList.append(clientMatter)
361     for clm in myLocalClientMatterList:
362     if clm in myAccessClientMatterList:
363     print "%s exists"% clm
364     elif clm in fullClientMatterList:
365     print "%s cant be added to your cases because it's owned by someone else..."% clm
366     else:
367     print "%s does not exist in the database. Adding it..."% clm
368     self.AddCaseToAccessDB(localCaseName,clientMatter)
369    
370     ## Sync cases from Access to my local
371    
372    
373     uploadReportMatrix = {}
374     for caseName in self.responsibleCasesList:
375     print "now processing %s"% caseName
376     casePath = os.path.join(self.casesDir,caseName)
377     if os.path.exists(os.path.join(casePath,"UploadReport.txt")):
378     print "yup"
379     caseUploadContents = open(os.path.join(casePath,"UploadReport.txt")).readlines()
380     clientMatter = caseName.split("_(")[1]
381     clientMatter = clientMatter.replace(")","")
382     clientMatter = clientMatter.replace("-",".")
383     for i in caseUploadContents:
384     i = i.replace("\n","")
385     i = i.replace(" | ","|")
386     try:
387     uploadReportMatrix[clientMatter].append(("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3]))
388     except:
389     uploadReportMatrix[clientMatter] = [("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3])]
390     #print uploadReportMatrix
391    
392     accessMyCaseUploads = self.accessDB.RetrieveMyCaseUploads('09756')
393     for x in uploadReportMatrix.keys():
394     localCaseUploadList = uploadReportMatrix[x]
395     tempMatrix = {}
396     try:
397     accessCaseUploadList = accessMyCaseUploads[x]
398     #print accessCaseUploadList
399     for y in localCaseUploadList:
400     epoch = y[0]
401     if int(epoch) > 1298462400:
402     #print epoch
403     reviewPlatform = y[1]
404     reportSize = y[3]
405     #print "."
406     #print accessCaseUploadList
407     if epoch in accessCaseUploadList:
408     print "%s, in the %s case, is already in there, skipping."%(y,x)
409     else:
410     print "%s, in the %s case, is missing. Will be added..."%(y,x)
411     date = y[2]
412     date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
413    
414     self.accessDB.UpdateCaseUpload(x,reviewPlatform,{epoch:(date,reportSize)})
415     #tempMatrix[epoch] = [platform,(date,size)]
416     else:
417     #print "This entry is pre cutover"
418     pass
419     except KeyError:
420     print "nothing for this one"
421     for z in localCaseUploadList:
422     print "%s, in the %s case, is missing. Will be added..."%(z,x)
423     date = z[0]
424     date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
425     #try:
426     # tempMatrix[date].append(z[1])
427     #except:
428     # tempMatrix[date] = [z[1]]
429     #print tempMatrix
430     #if tempMatrix:
431     # #print tempMatrix
432     # self.accessDB.UpdateCaseUpload(x,'Concordance DIS', tempMatrix)
433     #pass
434    
435    
436     #print myLocalClientMatterList
437     ## verify that all of your uploads are up there, if not, add it.
438     self.accessDB.CloseAccessConnection()
439    
440     else:
441     fullClientMatterList = self.accessDB.RetrieveAllCaseList()
442     myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
443    
444