ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/Trunk/MCP_Console.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/Active_prgs/MCP/MCP_Console.py
File size: 17299 byte(s)
Log Message:
Initial Import

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     responsibleCases,casesDir = MCP_Lib.GetCaseList('',self.accessDB)
28    
29     ## Testing version
30     #self.accessDB = MCP_Lib.AccessDBConnection(r"W:\Manny\testing\TPM_CaseTracking.mdb")
31     #responsibleCases,casesDir = MCP_Lib.GetCaseList(r"C:\Documents and Settings\eborges\My Documents\My Dropbox\Dev\Python\NinoCode\Active_prgs\Concordance\MCP",self.accessDB)
32     #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")
33    
34     print "connected to DB."
35    
36     self.responsibleCasesList = responsibleCases
37     self.casesDir = casesDir
38    
39    
40     def AddNewCase(self, caseName, clientMatter, chargable = False, reviewPlatform = "", responsibleProcessingVendor = "",
41     responsibleScanningVendor = "",responsibleHostingVendor = ""):
42     ## Add the local folders The GUI should test that the clm is 10 digits and has hyphen.
43     template = os.path.join(self.casesDir,'_Template_')
44     new = os.path.join(self.casesDir, caseName + '_(%s)'%clientMatter)
45     if os.path.exists(new):
46     print "ERROR: This case already exists!!"
47     else:
48     #print template
49     #print new
50     os.mkdir(new)
51     for file in os.listdir(template):
52     shutil.copy2(os.path.join(template,file),new)
53     ## Check the H drive for the supplemental folders and the matter folder, only if they select Concordance.
54     self.SetCaseNameAndCLM(caseName,clientMatter)
55     self.AddCaseToAccessDB(caseName,clientMatter)
56    
57     def AddCaseToAccessDB(self, caseName, clientMatter):
58     ## First test to see if it's already in the DB.
59     fullClientMatterList = self.accessDB.RetrieveAllCaseList()
60     clientMatter = clientMatter.replace("-",".")
61     if clientMatter in fullClientMatterList:
62     print "This client matter already exists in the database. Skipping."
63     else:
64     print "New client matter. Adding."
65     self.accessDB.AddNewCase(caseName, clientMatter, self.tPMName,self.tPMID,responsibleOffice = self.tPMOffice)
66     print "Added!"
67    
68     def EditCaseData(self,caseName,chargeableBool,respAttorney,respParalegal,respVendorTpl,revPlatform,respTPM,respOffice, caseStatus):
69     clientMatter = caseName.split("_(")[1]
70     clientMatter = clientMatter[:-1]
71     clientMatter = clientMatter.replace('-','.')
72     self.accessDB.UpdateChargable(clientMatter,chargeableBool)
73     self.accessDB.UpdateResponsibleAttorney(clientMatter,respAttorney)
74     self.accessDB.UpdateResponsibleParalegal(clientMatter,respParalegal)
75     self.accessDB.UpdateReviewPlatform(clientMatter,revPlatform)
76     self.accessDB.UpdateResponsibleTPM(clientMatter,respTPM)
77     self.accessDB.UpdatePrimaryOffice(clientMatter,respOffice)
78     self.accessDB.UpdateResponsibleVendors(clientMatter,respVendorTpl)
79     self.accessDB.UpdateCaseStatus(clientMatter, caseStatus)
80    
81     def GetCaseData(self, caseName):
82     #use this to get the data on the selected case, to populate your GUI
83     clientMatter = caseName.split("_(")[1]
84     clientMatter = clientMatter[:-1]
85     clientMatter = clientMatter.replace('-','.')
86     chargeableBool = self.accessDB.GetChargable(clientMatter)
87     respAttorney = self.accessDB.GetResponsibleAttorney(clientMatter)
88     respParalegal = self.accessDB.GetResponsibleParalegal(clientMatter)
89     respVendorTpl = self.accessDB.GetResponsibleVendorTpl(clientMatter)
90     revPlatform = self.accessDB.GetReviewPlatform(clientMatter)
91     respTPM = self.accessDB.GetResponsibleTPM(clientMatter)
92     respOffice = self.accessDB.GetPrimaryOffice(clientMatter)
93     caseStatus = self.accessDB.GetCaseStatus(clientMatter)
94     return (chargeableBool,respAttorney,respParalegal,respVendorTpl,revPlatform,respTPM,respOffice,caseStatus)
95    
96     def AddProductionEntry(self, CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes):
97     """This method adds one production entry to the case."""
98     errRpt = True
99     if CLM:
100     if prodID:
101     if prodDate:
102     if begBates:
103     if endBates:
104     if prodDocCount:
105     if prodPageCount:
106     if prodNotes:
107     self.accessDB.UpdateProductionDetail(CLM,prodID,prodDate,begBates,endBates,prodDocCount, prodPageCount, prodNotes)
108     errRpt = False
109     return errRpt
110    
111     def AddDataUpload(self,CLM, reviewPlatform, reportSize):
112     """This method will add one case upload."""
113     ## TODO: one day change it so that copy up requst calls this instead
114     ## of it being internal to that prog.
115     epoch = str(int(time.time()))
116     self.accessDB.UpdateCaseUpload(CLM,reviewPlatform,{epoch:(time.strftime('%m/%d/%Y'),reportSize)})
117    
118     def RemoveDataUpload(self,CLM,UEPOCH):
119     """This method calls DeleteCaseUpload and removes just one case upload. """
120     err = self.accessDB.DeleteCaseUpload(CLM,UEPOCH)
121     if err:
122     print "ERROR: An Error occured and this value was not removed!"
123     else:
124     print "%s Removed"% UEPOCH
125    
126     def GetUploadData(self, caseName):
127     # Used to get upload data, on the selected case, to populate the upload dialog
128     clientMatter = caseName.split("_(")[1]
129     clientMatter = clientMatter[:-1]
130     clientMatter = clientMatter.replace('-','.')
131     uploadList = self.accessDB.RetrieveUploadsByCLM(clientMatter)
132     return uploadList
133    
134     def GetProductionData(self,caseName):
135     clientMatter = caseName.split("_(")[1]
136     clientMatter = clientMatter[:-1]
137     clientMatter = clientMatter.replace('-','.')
138     productionList = self.accessDB.RetrieveProductionsByCLM(clientMatter)
139     return productionList
140    
141     def GetProductionTotal(self,productionList):
142     """Using the above productionList, this returns the total docs and pages produced"""
143     pgCountTotal = 0
144     docCountTotal = 0
145     for i in productionList:
146     pageCount = i[-2]
147     docCount = i[-3]
148     if 'None' in pageCount:
149     pass
150     else:
151     #print pageCount
152     pgCountTotal = pgCountTotal+int(pageCount)
153     if 'None' in pageCount:
154     pass
155     else:
156     #print docCount
157     docCountTotal = docCountTotal+int(docCount)
158     return pgCountTotal,docCountTotal
159    
160     def ExportProductionDataToExcel(self,CaseName,pathToCSV):
161     """Exports the production data to a csv file"""
162     productionList = self.GetProductionData(CaseName)
163     #print productionList
164     outputFile = open(pathToCSV,'w')
165     outputFile.write('Production ID,Production Date,Start Bates,End Bates,Document Count,Page Count,Notes\n')
166     for i in productionList:
167     for x in i:
168     outputFile.write(x+",")
169     outputFile.write("\n")
170     outputFile.close()
171    
172     def GetUploadTotal(self,uploadList):
173     """ Using the above uploadList, this will return the total uploaded """
174     count = 0.
175     for i in uploadList:
176     size = i[-1]
177    
178     if 'None' in size:
179     pass
180     else:
181     rawSize = directorySize2.prettyToUnpretty_Filesize(size)
182     count = count + rawSize
183     prettySizeFinal = directorySize2.pretty_filesize2(count)
184     return prettySizeFinal
185    
186     def MakeCaseDormant(self, caseAndCLM):
187     """Moves the case to the Dormant folder"""
188     print "Making %s case dormant..."
189     os.rename(os.path.join(self.casesDir,caseAndCLM),os.path.join(self.casesDir,os.path.join('zzzz_dormant_', caseAndCLM)))
190     print "Case has been archived."
191    
192    
193     def OpenCaseFolder(self,caseName,office):
194     """Trys to open the case folder for the active case, regardless who owns it."""
195     caseFolderLocation = MCP_Lib.GetOtherCaseFolder(office)
196     clientMatter = caseName.split("_(")[1]
197     clientMatter = clientMatter[:-1]
198     if "." in clientMatter:
199     clientMatter = clientMatter.replace('.','-')
200     folderMatrix = {}
201     #caseFolderLocation = os.path.join(caseFolderLocation,case)
202     err = False
203     if caseFolderLocation:
204     if os.path.exists(caseFolderLocation):
205     for f in os.listdir(caseFolderLocation):
206     if "_(" in f:
207     folderClientMatter = f.split("_(")[1]
208     folderClientMatter = folderClientMatter[:-1]
209     folderMatrix[folderClientMatter] = f
210     try:
211     folderName = folderMatrix[clientMatter]
212     os.startfile(os.path.join(caseFolderLocation, folderName))
213     except:
214     err = True
215     else:
216     err = True
217     else:
218     print "A case folder for this case was not found."
219     err = True
220     return err
221    
222    
223     def SetCaseNameAndCLM(self, newCaseName, newClientMatterNumber):
224     """Used when setting up a new case. Should have both or nothing"""
225     self.caseName = newCaseName
226     self.clientMatter = newClientMatterNumber
227     #print self.clientMatter
228    
229     def SetChargableCase(self, chargBool):
230     """sets or clears the chargable case settings"""
231     pass
232     def SetResponsibleVendor(self, vendorInfo):
233     """Sets the vendor name that is responsible for the case"""
234     pass
235     def SetReviewPlatform(self, reviewPlatform):
236     """Sets the review platform chosen for this case"""
237     if reviewPlatform == "Concordance":
238     print "Concordance selected. Creating DIS directories..."
239     hDrivePath = ConcordanceHelperTools.ParseClientMatter(self.clientMatter)
240     os.mkdir(hDrivePath)
241     print "Matter folder created."
242     os.mkdir(os.path.join(hDrivePath,'Match'))
243     os.mkdir(os.path.join(hDrivePath,'Tag_Databases'))
244     print "Supplemental folders created."
245     print "DIS directories done!"
246    
247    
248    
249     def SyncWithAccessDB(self,case = 'ALL'):
250     """Syncs your cases with the access database. This might only get run once when you first install
251     the program though..."""
252     ## So this syncs 'your' databases only. even though you are looking at a list of eeryone's databases
253     ## it will only sync yours. even if you did an upload for another tpm, that wouldnt get synced unles
254     ## the owner did a sync all. for 2 way sync to work, you should check, in access, that they have the case name
255     ## (with no funky characters) populated, before they run this for the first time.
256     if case == 'ALL':
257     ## verify that all your cases are up there, if not add it. but have support for cases where is should be
258     ## yours but is assigned to someone else...
259     fullClientMatterList = self.accessDB.RetrieveAllCaseList()
260     myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
261     myLocalClientMatterList = []
262    
263     ## Sync cases from my local to access
264     for case in self.responsibleCasesList:
265     localCaseName,clientMatter = case.split("_(")
266     clientMatter = clientMatter.replace(")","")
267     clientMatter = clientMatter.replace("-",".")
268     myLocalClientMatterList.append(clientMatter)
269     for clm in myLocalClientMatterList:
270     if clm in myAccessClientMatterList:
271     print "%s exists"% clm
272     elif clm in fullClientMatterList:
273     print "%s cant be added to your cases because it's owned by someone else..."% clm
274     else:
275     print "%s does not exist in the database. Adding it..."% clm
276     self.AddCaseToAccessDB(localCaseName,clientMatter)
277    
278     ## Sync cases from Access to my local
279    
280    
281     uploadReportMatrix = {}
282     for caseName in self.responsibleCasesList:
283     print "now processing %s"% caseName
284     casePath = os.path.join(self.casesDir,caseName)
285     if os.path.exists(os.path.join(casePath,"UploadReport.txt")):
286     print "yup"
287     caseUploadContents = open(os.path.join(casePath,"UploadReport.txt")).readlines()
288     clientMatter = caseName.split("_(")[1]
289     clientMatter = clientMatter.replace(")","")
290     clientMatter = clientMatter.replace("-",".")
291     for i in caseUploadContents:
292     i = i.replace("\n","")
293     i = i.replace(" | ","|")
294     try:
295     uploadReportMatrix[clientMatter].append(("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3]))
296     except:
297     uploadReportMatrix[clientMatter] = [("%s"%i.split("|")[0],"%s"%i.split("|")[1],"%s"%i.split("|")[2],"%s"%i.split("|")[3])]
298     #print uploadReportMatrix
299    
300     accessMyCaseUploads = self.accessDB.RetrieveMyCaseUploads('09756')
301     for x in uploadReportMatrix.keys():
302     localCaseUploadList = uploadReportMatrix[x]
303     tempMatrix = {}
304     try:
305     accessCaseUploadList = accessMyCaseUploads[x]
306     #print accessCaseUploadList
307     for y in localCaseUploadList:
308     epoch = y[0]
309     if int(epoch) > 1298462400:
310     #print epoch
311     reviewPlatform = y[1]
312     reportSize = y[3]
313     #print "."
314     #print accessCaseUploadList
315     if epoch in accessCaseUploadList:
316     print "%s, in the %s case, is already in there, skipping."%(y,x)
317     else:
318     print "%s, in the %s case, is missing. Will be added..."%(y,x)
319     date = y[2]
320     date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
321    
322     self.accessDB.UpdateCaseUpload(x,reviewPlatform,{epoch:(date,reportSize)})
323     #tempMatrix[epoch] = [platform,(date,size)]
324     else:
325     #print "This entry is pre cutover"
326     pass
327     except KeyError:
328     print "nothing for this one"
329     for z in localCaseUploadList:
330     print "%s, in the %s case, is missing. Will be added..."%(z,x)
331     date = z[0]
332     date = "%s/%s/%s"%(date[4:6],date[6:],date[:4])
333     #try:
334     # tempMatrix[date].append(z[1])
335     #except:
336     # tempMatrix[date] = [z[1]]
337     #print tempMatrix
338     #if tempMatrix:
339     # #print tempMatrix
340     # self.accessDB.UpdateCaseUpload(x,'Concordance DIS', tempMatrix)
341     #pass
342    
343    
344     #print myLocalClientMatterList
345     ## verify that all of your uploads are up there, if not, add it.
346     self.accessDB.CloseAccessConnection()
347    
348     else:
349     fullClientMatterList = self.accessDB.RetrieveAllCaseList()
350     myAccessClientMatterList = self.accessDB.RetrieveMyCaseList(self.tPMID)
351    
352