ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 321
Committed: Tue Mar 26 14:51:35 2013 UTC (13 years ago) by nino.borges
Content type: text/x-python
File size: 44676 byte(s)
Log Message:
Added the disclosure letter feature with dialogs and warning message on main view edit.

File Contents

# User Rev Content
1 ninoborges 8 """
2    
3     MCP_Lib
4    
5     Created by
6     Emanuel Borges
7     10.25.2010
8    
9     This wil be the main library for the MCP aplications. Shared methods will be
10     kept here. Version informaiton for the entire MCP program will be kept here to.
11    
12     """
13    
14 nino.borges 321 import os,sys, win32com.client,subprocess,ftplib,NinoGenTools, win32com.decimal_23
15 ninoborges 8
16     def GetCaseList(sys_Overwrite ="", accessConnectionObj = None):
17 nino.borges 189 """ Main method to parse and return usable lists of cases. returns list of my cases, office cases and all cases.
18     also returns the cases directory."""
19 ninoborges 8 #print os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),"settings.sys")
20     if sys_Overwrite:
21     casesDir = open(os.path.join(sys_Overwrite,"settings.sys")).readline().replace("\n","")
22     else:
23     casesDir = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),"settings.sys")).readline().replace("\n","")
24     #casesDir = r"C:\Documents and Settings\eborges\My Documents\My Dropbox\Documents\Cases"
25     responsibleCases = []
26 nino.borges 189 officeCases = []
27     allCases = []
28     tPMName,tPMID,nul = GetTPMInfo()
29     if accessConnectionObj:
30     accessDB = accessConnectionObj
31     else:
32     print "connecting to matter tracking access db..."
33     ## Production version
34     accessDB = AccessDBConnection(r"\\chiads01\app\DS_CaseTrack\TPM_CaseTracking.mdb")
35    
36     ## Testing version
37     #accessDB = AccessDBConnection(r"W:\Manny\testing\TPM_CaseTracking.mdb")
38     print "connected to DB."
39     officeList = GetFullOfficeList()
40    
41     cliMatList = []
42     for office in officeList:
43     cliMatList.extend(accessDB.RetrieveOfficeCaseList(office))
44     cliMatList.sort()
45     for cliMat in cliMatList:
46     caseName = accessDB.GetCaseName(cliMat)
47     allCases.append('%s_(%s)'%(caseName,cliMat))
48    
49 ninoborges 8 if tPMName == 'ANALYST':
50     casesDir = None
51 nino.borges 189 officeCases = allCases
52     responsibleCases = allCases
53 ninoborges 8 else:
54 nino.borges 189 myMatterList = accessDB.RetrieveMyCaseList(tPMID)
55 ninoborges 8 for file in os.listdir(casesDir):
56     if os.path.isdir(os.path.join(casesDir,file)):
57     if file == "_Template_":
58     pass
59     elif file == "zzzz_dormant_":
60     pass
61     else:
62 nino.borges 189 officeCases.append(file)
63     ## if the case's matter is in my matter list, also append to responsibleCases
64     clientMatter = file.split("_(")[1]
65     clientMatter = clientMatter[:-1]
66     clientMatter = clientMatter.replace('-','.')
67     if clientMatter in myMatterList:
68     responsibleCases.append(file)
69     return responsibleCases, officeCases, allCases, casesDir
70 ninoborges 8
71     def GetTPMInfo(sys_Overwrite = ""):
72     """ Main method to parse and return the TMP and the Employee ID"""
73     if sys_Overwrite:
74     syscaseDir,tPMName, tPMID,office = open(os.path.join(sys_Overwrite,"settings.sys")).readlines()
75     else:
76     syscaseDir,tPMName, tPMID,office = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),"settings.sys")).readlines()
77    
78     #syscaseDir,tPMName, tPMID = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),"settings.sys")).readlines()
79     tPMName = tPMName.replace("\n","")
80     tPMID = tPMID.replace("\n","")
81     office = office.replace("\n","")
82     return tPMName, tPMID, office
83    
84     def GetFullOfficeList():
85     """Simply returns a list of all of the offices."""
86     officeList = ['Boston','Brussels','Chicago','Huston','London','Los Angeles','Miami','Moscow','Munich','New York',
87     'Orange County','Rome','San Diego','Silicon Valley','Washington, D.C.']
88     return officeList
89    
90     def GetOtherCaseFolder(office):
91     """This method will return the case folder for cases that you dont own"""
92     ## So this is in two places that I now have to maintian... not sure I like that.
93     caseFolderMatrix={'Boston':r"\\bstads01\app\Manny\Cases",
94     'Chicago':r"\\chiads01\data\CLI\Litigation_Support\MCP\Cases",
95     'Los Angeles':r"\\lasads01\data\Cli\_Lit_Support\MCP",
96     'New York':r"\\nykads01\data\cli\LitSupport\MCP\Cases",
97     'Miami':r"\\nykads01\data\cli\LitSupport\MCP\Cases",
98     'Orange County':r"\\lasads01\data\Cli\_Lit_Support\MCP",
99     'San Diego':r"\\lasads01\data\Cli\_Lit_Support\MCP",
100     'Silicon Valley':r"\\lasads01\data\Cli\_Lit_Support\MCP",
101     'Washington, D.C.':r"\\wdcads01\data\Cli\_MCP\Cases"}
102     try:
103     location = caseFolderMatrix[office]
104     except:
105     location = None
106     return location
107    
108 nino.borges 266 def GetArchiveFileTypeList():
109     """Returns a list of extensions of archive type files"""
110     return [".ZIP", ".RAR",".TAR",".7Z"]
111    
112 ninoborges 8 def GetMCPVersion():
113     """Returns the current version of the entire MCP program set"""
114 nino.borges 303 return 'v 1.8.0'
115 ninoborges 8
116    
117     class AccessDBConnection:
118     def __init__(self, accessDB):
119     daoEngine = win32com.client.Dispatch('DAO.DBEngine.36')
120     self.daoDB = daoEngine.OpenDatabase(accessDB)
121    
122     def MakeNewRSConnection(self, table, specialSelect = "*", specialWhere="" ):
123     """ This method will make a new RS connection for either reading or writing."""
124     if specialWhere:
125     statement = "SELECT %s FROM %s WHERE %s"%(specialSelect,table, specialWhere)
126     else:
127     statement = "SELECT %s FROM %s"%(specialSelect,table)
128     daoRSObj = self.daoDB.OpenRecordset(statement)
129     return daoRSObj
130    
131     def CloseAccessConnection(self):
132     """This closes the entire connection and not just the RS"""
133     self.daoDB.Close()
134    
135     def RetrieveAllCaseList(self):
136     """Retrieves all of the cases in the database regardless of assignment.(client matter list)"""
137     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData')
138     daoRSObj.MoveLast()
139     fullCount = daoRSObj.RecordCount
140     daoRSObj.MoveFirst()
141    
142     accessDBCLMList = []
143     for i in range(fullCount):
144     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
145     daoRSObj.MoveNext()
146     daoRSObj.Close()
147     return accessDBCLMList
148    
149     def RetrieveMyCaseList(self, empID):
150     """Retrieves just 1 employees case list (client matter list)"""
151     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "empID = '%s'"%empID)
152     daoRSObj.MoveLast()
153     fullCount = daoRSObj.RecordCount
154     daoRSObj.MoveFirst()
155    
156     accessDBCLMList = []
157     for i in range(fullCount):
158     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
159     daoRSObj.MoveNext()
160     daoRSObj.Close()
161     return accessDBCLMList
162    
163     def RetrieveOfficeCaseList(self, primaryOffice):
164     """Retrieves the case list for an entire office. Note, a case can be owned by a TPM in another office but
165     the primary office might still be an office that that TPM does not work for. Also people are not always
166     good about updating the primary office...(client matter list)"""
167     accessDBCLMList = []
168     try:
169     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "PrimaryOffice = '%s'"%primaryOffice)
170     daoRSObj.MoveLast()
171     fullCount = daoRSObj.RecordCount
172     daoRSObj.MoveFirst()
173    
174    
175     for i in range(fullCount):
176     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
177     daoRSObj.MoveNext()
178     daoRSObj.Close()
179     except:
180     pass
181     return accessDBCLMList
182    
183     def RetrieveProductionsByCLM(self,CLM):
184     """This will retrieve a FULL production matrix for a specific clm"""
185     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail',
186 nino.borges 321 "ProductionID,ProductionComplDate, BegBates,EndBates,ProdDocCount,ProdPageCount,Notes,ProducedTo,ProductionMedia,ProductionSource,RequestedBy,ProductionDate,ProductionMediaPassword",
187 ninoborges 8 specialWhere = "ClientMatterNum='%s' ORDER BY ProductionComplDate"%CLM)
188     try:
189     ## Getting an exception that I cant capture when table is empty.
190     ## this will test and return empty if empty, until I can figure out a better test.
191     daoRSObj.MoveLast()
192     tableHasData = True
193     except:
194     tableHasData = False
195     productionList = []
196 nino.borges 321 productionMatrix = {}
197 ninoborges 8 if tableHasData:
198     fullCount = daoRSObj.RecordCount
199     daoRSObj.MoveFirst()
200     for i in range(fullCount):
201     try:
202     pgCount = str(int(daoRSObj.Fields('ProdPageCount').Value))
203     except:
204     pgCount = '0'
205     try:
206     docCount = str(int(daoRSObj.Fields('ProdDocCount').Value))
207     except:
208     docCount = '0'
209 nino.borges 321 grouping = str(daoRSObj.Fields('ProducedTo').Value)
210     if grouping:
211     pass
212     else:
213     grouping = 'default'
214     if grouping in productionMatrix.keys():
215     productionMatrix[grouping].append((str(daoRSObj.Fields('ProductionID').Value),
216 ninoborges 8 str(daoRSObj.Fields('ProductionComplDate').Value).split(' ')[0],
217 nino.borges 321 str(daoRSObj.Fields('ProductionDate').Value).split(' ')[0],
218 ninoborges 8 str(daoRSObj.Fields('BegBates').Value),str(daoRSObj.Fields('EndBates').Value),
219     docCount,pgCount,
220 nino.borges 321 str(daoRSObj.Fields('ProducedTo').Value),
221     str(daoRSObj.Fields('RequestedBy').Value),
222     str(daoRSObj.Fields('ProductionMedia').Value),
223     str(daoRSObj.Fields('ProductionMediaPassword').Value),
224     str(daoRSObj.Fields('ProductionSource').Value),
225 ninoborges 8 str(daoRSObj.Fields('Notes').Value)))
226 nino.borges 321 else:
227     productionMatrix[grouping] = [(str(daoRSObj.Fields('ProductionID').Value),
228     str(daoRSObj.Fields('ProductionComplDate').Value).split(' ')[0],
229     str(daoRSObj.Fields('ProductionDate').Value).split(' ')[0],
230     str(daoRSObj.Fields('BegBates').Value),str(daoRSObj.Fields('EndBates').Value),
231     docCount,pgCount,
232     str(daoRSObj.Fields('ProducedTo').Value),
233     str(daoRSObj.Fields('RequestedBy').Value),
234     str(daoRSObj.Fields('ProductionMedia').Value),
235     str(daoRSObj.Fields('ProductionMediaPassword').Value),
236     str(daoRSObj.Fields('ProductionSource').Value),
237     str(daoRSObj.Fields('Notes').Value))]
238     #productionList.append((str(daoRSObj.Fields('ProductionID').Value),
239     # str(daoRSObj.Fields('ProductionComplDate').Value).split(' ')[0],
240     # str(daoRSObj.Fields('BegBates').Value),str(daoRSObj.Fields('EndBates').Value),
241     # docCount,pgCount,
242     # str(daoRSObj.Fields('Notes').Value)))
243 ninoborges 8 daoRSObj.MoveNext()
244 nino.borges 321 #print len(productionList)
245 ninoborges 8 daoRSObj.Close()
246 nino.borges 321 return productionMatrix
247 ninoborges 8
248    
249     def RetrieveUploadsByCLM(self, CLM):
250     """This will retrieve a FULL upload matrix for a specific clm. This wil also pick the best Size (gb,mb,kb), since it's just for display."""
251     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity',
252     "UEPOCH,ReviewPlatform,DataLoadDate,DataLoadedGB,DataLoadedMB,DataLoadedKB",
253     specialWhere = "ClientMatterNum='%s'"%CLM)
254     try:
255     ## Getting an exception that I cant capture when table is empty.
256     ## this will test and return empty if empty, until I can figure out a better test.
257     daoRSObj.MoveLast()
258     tableHasData = True
259     except:
260     tableHasData = False
261     caseUploadList = []
262     if tableHasData:
263     fullCount = daoRSObj.RecordCount
264     daoRSObj.MoveFirst()
265    
266     for i in range(fullCount):
267     if daoRSObj.Fields('DataLoadedKB').Value:
268     size = str(daoRSObj.Fields('DataLoadedKB').Value) + ' KB'
269     elif daoRSObj.Fields('DataLoadedMB').Value:
270     size = str(daoRSObj.Fields('DataLoadedMB').Value) + ' MB'
271     else:
272     size = str(daoRSObj.Fields('DataLoadedGB').Value) + ' GB'
273    
274     caseUploadList.append((str(daoRSObj.Fields('UEPOCH').Value),daoRSObj.Fields('ReviewPlatform').Value,
275     str(daoRSObj.Fields('DataLoadDate').Value).split(' ')[0],size))
276     daoRSObj.MoveNext()
277     daoRSObj.Close()
278     return caseUploadList
279    
280     def RetrieveOfficeUploads(self, primaryOffice):
281     """This only returns a matrix of clm{[EPOCH]}, since there isnt a reason to sync uploads from access"""
282     myClientMatterList = self.RetrieveOfficeCaseList(primaryOffice)
283     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
284     daoRSObj.MoveLast()
285     fullCount = daoRSObj.RecordCount
286     daoRSObj.MoveFirst()
287    
288     caseUploadMatrix = {}
289     for i in range(fullCount):
290     currentClientMatter = daoRSObj.Fields('ClientMatterNum').Value
291     if currentClientMatter in myClientMatterList:
292     epoch = str(daoRSObj.Fields('UEPOCH').Value)
293     try:
294     caseUploadMatrix[currentClientMatter].append(epoch)
295     except:
296     caseUploadMatrix[currentClientMatter] = [epoch]
297     daoRSObj.MoveNext()
298     daoRSObj.Close()
299     return caseUploadMatrix
300    
301     def RetrieveMyCaseUploads(self,empID):
302     """This only returns a matrix of clm{[EPOCH]}, since there isnt a reason to sync uploads from access"""
303     myClientMatterList = self.RetrieveMyCaseList(empID)
304     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
305     daoRSObj.MoveLast()
306     fullCount = daoRSObj.RecordCount
307     daoRSObj.MoveFirst()
308    
309     caseUploadMatrix = {}
310     for i in range(fullCount):
311     currentClientMatter = daoRSObj.Fields('ClientMatterNum').Value
312     if currentClientMatter in myClientMatterList:
313     epoch = daoRSObj.Fields('UEPOCH').Value
314     if epoch:
315     epoch = str(epoch)
316     if '.' in epoch:
317     epoch = epoch.split('.')[0]
318    
319     try:
320     caseUploadMatrix[currentClientMatter].append(epoch)
321     except:
322     caseUploadMatrix[currentClientMatter] = [epoch]
323     #loadedDate = daoRSObj.Fields('DataLoadDate').Value
324     #loadedDate = str(loadedDate.Format('%Y%m%d'))
325     #loadedSize =daoRSObj.Fields('DataLoadedGB').Value
326     #loadedSizeType = " GB"
327     #
328     #if loadedSize:
329     # ## If the GB loaded size exists, use that.
330     # pass
331     #else:
332     # ## if it does not, use the MB loaded field.
333     # loadedSize =daoRSObj.Fields('DataLoadedMB').Value
334     # loadedSizeType = " MB"
335     #loadedSize = str(loadedSize)
336     #if "." in loadedSize:
337     # loadedSize = loadedSize[:loadedSize.index('.')+3]
338     #try:
339     # caseUploadMatrix[currentClientMatter].append((loadedDate,loadedSize+loadedSizeType))
340     #except:
341     # caseUploadMatrix[currentClientMatter] = [(loadedDate,loadedSize+loadedSizeType)]
342     daoRSObj.MoveNext()
343     daoRSObj.Close()
344     return caseUploadMatrix
345    
346     def AddNewCase(self, caseName, CLM, TPM_Name, empID, chargable = False, reviewPlatform = "", responsibleVendor = "", responsibleOffice = ""):
347     """Adds a new case in the access DB."""
348     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData')
349     daoRSObj.AddNew()
350     daoRSObj.Fields('ClientMatterNum').Value = CLM
351     daoRSObj.Fields('CaseName').Value = caseName
352     daoRSObj.Fields('EmpID').Value = empID
353     daoRSObj.Fields('TPM').Value = TPM_Name
354     daoRSObj.Fields('PrimaryOffice').Value = responsibleOffice
355     daoRSObj.Update()
356     daoRSObj.Close()
357    
358     ## Per aaron, add to two other tables
359     clientNumber = CLM.split('.')[0]
360     daoRSObj = self.MakeNewRSConnection('tbl_Ref_Client')
361     try:
362     daoRSObj.AddNew()
363     daoRSObj.Fields('ClientNum').Value = clientNumber
364     daoRSObj.Update()
365     except:
366     pass
367     daoRSObj.Close()
368    
369     daoRSObj = self.MakeNewRSConnection('tbl_Ref_ClientMatter')
370     try:
371     daoRSObj.AddNew()
372     daoRSObj.Fields('ClientNum').Value = clientNumber
373     daoRSObj.Fields('ClientMatterNum').Value = CLM
374     daoRSObj.Update()
375     except:
376     pass
377     daoRSObj.Close()
378    
379     ## These below make their own record sets.
380     if chargable:
381     ## change this one aaron adds it.
382     pass
383     if reviewPlatform:
384     self.UpdateReviewPlatform(CLM, reviewPlatform)
385     if responsibleVendor:
386     self.UpdateResponsibleVendor(CLM,responsibleVendor)
387    
388    
389    
390     def UpdateChargable(self, CLM, chargable):
391     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
392     daoRSObj.Edit()
393     daoRSObj.Fields('BillableMatter').Value = chargable
394     daoRSObj.Update()
395     daoRSObj.Close()
396    
397     def GetChargable(self,CLM):
398     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
399     chargable = daoRSObj.Fields('BillableMatter').Value
400     daoRSObj.Close()
401     return chargable
402 nino.borges 321
403     def UpdateDisclosureLetter(self,CLM, letterSaved, pathToLetter):
404     """Allows you to check or uncheck the state of the disclosure letter and the link to it."""
405     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
406     daoRSObj.Edit()
407     daoRSObj.Fields('DisclosureLetterSaved').Value = letterSaved
408     daoRSObj.Fields('LinktoDisclosureLetter').Value = pathToLetter
409     daoRSObj.Update()
410     daoRSObj.Close()
411 ninoborges 8
412 nino.borges 321 def GetDisclosureLetter(self, CLM):
413     """Returns the state of the saved letter and the path to the disclosure letter"""
414     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
415     letterSaved = daoRSObj.Fields('DisclosureLetterSaved').Value
416     pathToLetter = daoRSObj.Fields('LinktoDisclosureLetter').Value
417     #pathToLetter = "foo"
418     #print letterSaved
419     daoRSObj.Close()
420     return letterSaved,pathToLetter
421    
422 ninoborges 8 def UpdateReviewPlatform(self, CLM, reviewPlatform):
423     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
424     daoRSObj.Edit()
425     daoRSObj.Fields('ReviewPlatform').Value = reviewPlatform
426     daoRSObj.Update()
427     daoRSObj.Close()
428    
429     def GetReviewPlatform(self,CLM):
430     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
431     platform = daoRSObj.Fields('ReviewPlatform').Value
432     daoRSObj.Close()
433     return platform
434    
435     def UpdateResponsibleVendors(self, CLM,responsibleVendorTpl):
436     """VendorTpl should be a tuple of (processing,scanning,hosting) with None if you dont have it"""
437     processingVendor, scanningVendor, hostingVendor = responsibleVendorTpl
438     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
439     if processingVendor:
440     daoRSObj.Edit()
441     daoRSObj.Fields('ProcessingVendor').Value = processingVendor
442     daoRSObj.Update()
443     if scanningVendor:
444     daoRSObj.Edit()
445     daoRSObj.Fields('ScanningVendor').Value = scanningVendor
446     daoRSObj.Update()
447     if hostingVendor:
448     daoRSObj.Edit()
449     daoRSObj.Fields('HostingVendor').Value = hostingVendor
450     daoRSObj.Update()
451     daoRSObj.Close()
452    
453     def GetResponsibleVendorTpl(self, CLM):
454     """Returns a tuple of (processing,scanning,hosting) with None if you dont have it"""
455     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
456     processingVendor = daoRSObj.Fields('ProcessingVendor').Value
457     scanningVendor = daoRSObj.Fields('ScanningVendor').Value
458     hostingVendor = daoRSObj.Fields('HostingVendor').Value
459     daoRSObj.Close()
460     tmpTpl = (processingVendor,scanningVendor,hostingVendor)
461     return tmpTpl
462    
463     def UpdateCaseUpload(self, CLM, reviewPlatform, uploadMatrix):
464     """Format for matrix is epoch is key and uploads are in a tpl. (12/23/2010,49MB) Date format is mm/dd/yyyy"""
465     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
466    
467     ## Dont for get to convert the date first somewhere.
468     for i in uploadMatrix.keys():
469     (date, size) = uploadMatrix[i]
470     daoRSObj.AddNew()
471     daoRSObj.Fields('ClientMatterNum').Value = CLM
472     daoRSObj.Fields('UEPOCH').Value = i
473     daoRSObj.Fields('DataLoadDate').Value = date
474     daoRSObj.Fields('ReviewPlatform').Value = reviewPlatform
475     if "GB" in size:
476     daoRSObj.Fields('dataLoadedGB').Value = float(size.replace("GB",""))
477     elif "MB" in size:
478     daoRSObj.Fields('dataLoadedMB').Value = float(size.replace("MB",""))
479     else:
480     daoRSObj.Fields('DataLoadedKB').Value = float(size.replace("KB",""))
481     daoRSObj.Update()
482     daoRSObj.Close()
483    
484     def DeleteCaseUpload(self,CLM,UEPOCH):
485     """This method will let you delete a single case upload but only if it was added by the MCP.
486     i.e has a UEPOCH"""
487     ## When calling UEPOCHs, dont put it in a ''
488     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity', specialWhere = "UEPOCH=%s"%UEPOCH)
489     ## WHERE AND is not working so I'm going to have to WHERE for the UEPOCH and then do a quick search for the CLM, to be safe.
490     daoRSObj.MoveLast()
491     recordCount = daoRSObj.RecordCount
492     daoRSObj.MoveFirst()
493     ## This wont allow you to delete if there are multiple records with same UEPOCH
494     if recordCount == 1:
495     val2 = daoRSObj.Fields('ClientMatterNum').Value
496     if val2 == CLM:
497     daoRSObj.Delete()
498     errorRpt = False
499     else:
500     errorRpt = True
501     else:
502     errorRpt = True
503     daoRSObj.Close()
504     #print errorRpt
505     return errorRpt
506 nino.borges 321
507     def GetProducedToEntities(self,CLM):
508     """This will return, for a specific matter, a list of the current 'produced to' options, as kind of a history. """
509     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail',
510     specialWhere = "ClientMatterNum='%s'"%CLM)
511     prodToList = []
512     try:
513     daoRSObj.MoveLast()
514     tableHasData = True
515     except:
516     tableHasData = False
517     productionMatrix = {}
518     if tableHasData:
519     fullCount = daoRSObj.RecordCount
520     daoRSObj.MoveFirst()
521     for i in range(fullCount):
522     if daoRSObj.Fields('ProducedTo').Value:
523     productionMatrix[daoRSObj.Fields('ProducedTo').Value] = 1
524     daoRSObj.MoveNext()
525     prodToList = productionMatrix.keys()
526     daoRSObj.Close()
527     return prodToList
528    
529     def GetProductionRequestedByNames(self,CLM):
530     """This will return, for a specific matter, a list of the current 'production requested by names, as kind of a history. """
531     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail',
532     specialWhere = "ClientMatterNum='%s'"%CLM)
533     reqByList = []
534     try:
535     daoRSObj.MoveLast()
536     tableHasData = True
537     except:
538     tableHasData = False
539     reqByMatrix = {}
540     if tableHasData:
541     fullCount = daoRSObj.RecordCount
542     daoRSObj.MoveFirst()
543     for i in range(fullCount):
544     if daoRSObj.Fields('RequestedBy').Value:
545     reqByMatrix[daoRSObj.Fields('RequestedBy').Value] = 1
546     daoRSObj.MoveNext()
547     reqByList = reqByMatrix.keys()
548     daoRSObj.Close()
549     return reqByList
550 ninoborges 8
551 nino.borges 321 def UpdateProductionDetail(self, CLM, prodID, prodProcessedDate, begBates,endBates,prodDocCount, prodPageCount, prodNotes, prodTo, prodMedia,prodSource,prodReqBy,prodSentDate,prodMediaPassword):
552 ninoborges 8 """This method will let you add an entire produciton record to the production table. All fields are manadatory.
553     the date is in mm/dd/yyyy format."""
554     try:
555     testdaoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail', specialSelect ="ProductionID",specialWhere = "ClientMatterNum='%s'"%CLM)
556     testdaoRSObj.MoveLast()
557     testRecordCount = testdaoRSObj.RecordCount
558     testdaoRSObj.MoveFirst()
559     prodList = []
560     if testRecordCount:
561     for i in range(testRecordCount):
562     prodList.append(testdaoRSObj.Fields('ProductionID').Value)
563     testdaoRSObj.MoveNext()
564     testdaoRSObj.Close()
565     #print testRecordCount
566     #print prodList
567     if prodID in prodList:
568     prodIncrement = NinoGenTools.Counter(1)
569     prodID = prodID+ "_"+"%0*d"%(4,prodIncrement.count)
570     prodIncrement.inc()
571     while prodID in prodList:
572     prodID = prodID[:-4] +"%0*d"%(4,prodIncrement.count)
573     prodIncrement.inc()
574     except:
575     pass
576    
577     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail')
578     daoRSObj.AddNew()
579     daoRSObj.Fields('ClientMatterNum').Value = CLM
580     daoRSObj.Fields('ProductionID').Value = prodID
581 nino.borges 321 daoRSObj.Fields('ProductionComplDate').Value = prodProcessedDate
582 ninoborges 8 daoRSObj.Fields('BegBates').Value = begBates
583     daoRSObj.Fields('EndBates').Value = endBates
584     daoRSObj.Fields('ProdDocCount').Value = prodDocCount
585     daoRSObj.Fields('ProdPageCount').Value = prodPageCount
586     daoRSObj.Fields('Notes').Value = prodNotes
587 nino.borges 321 daoRSObj.Fields('ProducedTo').Value =prodTo
588     daoRSObj.Fields('ProductionMedia').Value =prodMedia
589     daoRSObj.Fields('ProductionSource').Value =prodSource
590     daoRSObj.Fields('RequestedBy').Value =prodReqBy
591     daoRSObj.Fields('ProductionDate').Value =prodSentDate
592     daoRSObj.Fields('ProductionMediaPassword').Value =prodMediaPassword
593 ninoborges 8
594     daoRSObj.Update()
595     daoRSObj.Close()
596    
597     def UpdateResponsibleAttorney(self, CLM, responsibleAttny):
598     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
599     daoRSObj.Edit()
600     daoRSObj.Fields('PrimaryAttorneyContact').Value = responsibleAttny
601     daoRSObj.Update()
602     daoRSObj.Close()
603    
604     def GetResponsibleAttorney(self, CLM):
605     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
606     val = daoRSObj.Fields('PrimaryAttorneyContact').Value
607     daoRSObj.Close()
608     return val
609    
610     def UpdateOtherAttorneys(self,CLM, otherAttorneysList):
611     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
612     daoRSObj.Edit()
613     ## add this when aaron adds it.
614     daoRSObj.Update()
615     daoRSObj.Close()
616    
617     def UpdateResponsibleParalegal(self,CLM, responsibleParalegal):
618     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
619     daoRSObj.Edit()
620     daoRSObj.Fields('ParalegalContact').Value = responsibleParalegal
621     daoRSObj.Update()
622     daoRSObj.Close()
623    
624     def GetResponsibleParalegal(self,CLM):
625     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
626     val = daoRSObj.Fields('ParalegalContact').Value
627     daoRSObj.Close()
628     return val
629    
630     def UpdatePrimaryOffice(self,CLM, primaryOffice):
631     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
632     daoRSObj.Edit()
633     daoRSObj.Fields('PrimaryOffice').Value = primaryOffice
634     daoRSObj.Update()
635     daoRSObj.Close()
636    
637     def GetPrimaryOffice(self,CLM):
638     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
639     val = daoRSObj.Fields('PrimaryOffice').Value
640     daoRSObj.Close()
641     return val
642    
643     def UpdateResponsibleTPM(self, CLM, tPMName):
644     """Format should be last, first"""
645     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
646     daoRSObj.Edit()
647     daoRSObj.Fields('TPM').Value = tPMName
648     daoRSObj.Update()
649     daoRSObj.Close()
650    
651     def GetResponsibleTPM(self,CLM):
652     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
653     val = daoRSObj.Fields('TPM').Value
654     daoRSObj.Close()
655     return val
656    
657     def GetCaseStatus(self,CLM):
658     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
659     val = daoRSObj.Fields('ProjectStatus').Value
660     daoRSObj.Close()
661     return val
662    
663     def UpdateCaseStatus(self,CLM,status):
664     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
665     daoRSObj.Edit()
666     daoRSObj.Fields('ProjectStatus').Value = status
667     daoRSObj.Update()
668     daoRSObj.Close()
669    
670     def GetCaseName(self,CLM):
671     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
672     val = daoRSObj.Fields('CaseName').Value
673     daoRSObj.Close()
674     return val
675    
676     def UpdateCaseName(self,CLM,caseName):
677     """This is just the internal name for the case"""
678     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
679     daoRSObj.Edit()
680     daoRSObj.Fields('CaseName').Value = caseName
681     daoRSObj.Update()
682     daoRSObj.Close()
683    
684 nino.borges 232 def GetAlternateMediaPath(self,CLM):
685     """Returns the alternate media path"""
686     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
687     val = daoRSObj.Fields('AlternateMediaPath').Value
688     daoRSObj.Close()
689     return val
690    
691     def UpdateAlternateMediaPath(self,CLM,alternateMediaPath):
692     """Updates the alternate Media Path in the db"""
693     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
694     daoRSObj.Edit()
695     daoRSObj.Fields('AlternateMediaPath').Value = alternateMediaPath
696     daoRSObj.Update()
697     daoRSObj.Close()
698    
699     def GetVendorFolderPath(self,CLM):
700     """Returns the vendor Folder path"""
701     try:
702     daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
703     val = daoRSObj.Fields('VendorFolderPath').Value
704     daoRSObj.Close()
705     except:
706     val = None
707     return val
708    
709     def UpdateVendorFolderPath(self,CLM,vendorFolderPath):
710     """Updates the Vendor Folder Path in the db"""
711 nino.borges 303 #print vendorFolderPath
712     try:
713     daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
714     daoRSObj.Edit()
715     except:
716     daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath')
717     daoRSObj.Edit()
718     daoRSObj.Fields('ClientMatterNum').Value = CLM
719 nino.borges 232 daoRSObj.Fields('VendorFolderPath').Value = vendorFolderPath
720     daoRSObj.Update()
721     daoRSObj.Close()
722 nino.borges 303
723     def GetUploadCostRate(self,CLM):
724     """Returns the upload cost for a case"""
725     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
726     val = daoRSObj.Fields('UploadCost_GB').Value
727     daoRSObj.Close()
728     return val
729 nino.borges 232
730 nino.borges 303 def UpdateUploadCostRate(self,CLM, uploadCost):
731     """Updates the upload cost for a case"""
732     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
733     daoRSObj.Edit()
734     daoRSObj.Fields('UploadCost_GB').Value = uploadCost
735     daoRSObj.Update()
736     daoRSObj.Close()
737    
738     def GetStorageCostRate(self,CLM):
739     """Returns the Storage cost for a case"""
740     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
741     val = daoRSObj.Fields('StorageCost_GB').Value
742     daoRSObj.Close()
743     return val
744    
745     def UpdateStorageCostRate(self,CLM, storageCost):
746     """Updates the upload cost for a case"""
747     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
748     daoRSObj.Edit()
749     daoRSObj.Fields('StorageCost_GB').Value = storageCost
750     daoRSObj.Update()
751     daoRSObj.Close()
752    
753     def GetDefaultUploadCostRate(self, platform = "Relativity"):
754     """Returns the current default upload cost"""
755     if platform == "Relativity":
756     cost = "50"
757     else:
758     cost = "50"
759     return cost
760    
761     def GetDefaultStorageCostRate(self, platform = "Relativity"):
762     """Returns the current default storage cost"""
763     if platform == "Relativity":
764     cost = "20"
765     else:
766     cost = "20"
767     return cost
768    
769 ninoborges 8 class ExpeDatConnection:
770     def __init__(self, platform):
771     if platform == "Relativity":
772     self.initialPath = "Relativity"
773     #self.userName = "eborges"
774     else:
775     self.initialPath = "Concordance Data"
776     #self.userName = "eborgesc"
777    
778     self.userName = "eborges"
779     self.hostName = "@mweftp.litigation.lexisnexis.com"
780     self.userPassword = "9atrEFeh"
781     #self.exeLocation = r"C:\Documents and Settings\eborges\My Documents\MyDownloads\ExpDat\movedat.exe"
782     self.exeLocation = r"C:\Program Files\ExpDat\movedat.exe"
783    
784 nino.borges 203 def ListDir(self,path):
785     """Returns the contents of a directory. returns files, dirs."""
786     path = os.path.join(self.initialPath,path)
787     args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
788     fnull = open(os.devnull, 'w')
789     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
790     rawFileList,errCode =process.communicate()
791     rawFileList = rawFileList.split("\n")
792     fileList = []
793     dirList = []
794     if rawFileList:
795     for i in rawFileList:
796     if i:
797     i = i.split(" ")[-1]
798     if i[-1] == "/":
799     dirList.append(i)
800     else:
801     fileList.append(i)
802     fnull.close()
803     return fileList, dirList
804    
805     def GatherFullDirListMatrix(self,vendorFolder):
806     """Returns a matrix of a list path, with all the files and dirs in a vendor folder"""
807     fileList,dirList = self.ListDir(vendorFolder)
808     folderMatrix = []
809     currentPath = vendorFolder
810     for indFile in fileList:
811     folderMatrix.append(indFile)
812     #while dirList:
813     for dir in dirList:
814 nino.borges 232 #print dir
815 nino.borges 206 newPath = os.path.join(currentPath, dir)
816 nino.borges 203 print currentPath
817 nino.borges 206 subFileList,subDirList = self.ListDir(newPath)
818 nino.borges 203 newList = []
819     for indFile in subFileList:
820     newList.append(indFile)
821 nino.borges 232 #print indFile
822 nino.borges 203 folderMatrix.append([dir,newList])
823 nino.borges 232 #print folderMatrix
824 nino.borges 203 #while dirList:
825     return folderMatrix
826    
827 nino.borges 232 def GatherSize(self,path):
828     """Returns the size of a given path or archive"""
829     extension = os.path.splitext(path)[1]
830     path = os.path.join(self.initialPath,path)
831     #path = self.initialPath + "/" + path
832     if extension.upper() == '.ZIP':
833     args = [self.exeLocation,"-D","%s:%s%s:%s=zipsize"%(self.userName,self.userPassword,self.hostName,path)]
834     fnull = open(os.devnull, 'w')
835     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
836     rawFileSize,errCode =process.communicate()
837     elif extension == "":
838     args = [self.exeLocation,"%s:%s%s:%s=*lr"%(self.userName,self.userPassword,self.hostName,path)]
839     #print args
840     fnull = open(os.devnull, 'w')
841     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
842     rawDirList,errCode =process.communicate()
843     rawDirList = rawDirList.split("\n")
844     rawFileSize = 0
845     for line in rawDirList[1:]:
846     if line:
847     size = line.split("\t")[1]
848     itemType = line.split("\t")[3]
849     if itemType == "F":
850     rawFileSize = rawFileSize + int(size,16)
851     else:
852     args = [self.exeLocation,"%s:%s%s:%s=*ls"%(self.userName,self.userPassword,self.hostName,path)]
853     #print args
854     fnull = open(os.devnull, 'w')
855     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
856     rawDirList,errCode =process.communicate()
857     rawDirList = rawDirList.split("\n")[2]
858     print rawDirList
859     rawFileSize = 0
860     if rawDirList:
861     size = rawDirList.split("\t")[1]
862     rawFileSize = int(size,16)
863     fnull.close()
864     if rawFileSize:
865     print "size is %s"%rawFileSize
866     else:
867     rawFileSize = False
868 nino.borges 239 return rawFileSize
869 nino.borges 232
870 ninoborges 8 def TestPath(self,path):
871     """Tests to see if path already exists"""
872     path = os.path.join(self.initialPath,path)
873     args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
874 nino.borges 232 #print args
875 ninoborges 8 fnull = open(os.devnull, 'w')
876     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
877     fnull.close()
878     if errCode == 0:
879     return True
880     if errCode == 25:
881     return False
882     else:
883     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
884    
885     def CreateNewPath(self,path):
886     """Creates a new path on the LN system"""
887     path = os.path.join(self.initialPath,path)
888     args = [self.exeLocation,"-n","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
889     fnull = open(os.devnull, 'w')
890     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
891     fnull.close()
892     #return errCode
893     if errCode == 0:
894     return True
895     if errCode == 34:
896     ## Path already exists
897     return False
898     else:
899     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
900 nino.borges 203
901     def MoveOnLN(self,absSourcePathAndFile,targetDirAndFile):
902     """Performs a move from LN to LN"""
903     targetDirAndFile = os.path.join(self.initialPath,targetDirAndFile)
904     absSourcePathAndFile = os.path.join(self.initialPath,absSourcePathAndFile)
905     #targetDir = targetDir + "\\"
906     args = [self.exeLocation,"-m","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,absSourcePathAndFile),"%s"%targetDirAndFile]
907     fnull = open(os.devnull, 'w')
908     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
909     fnull.close()
910     #return errCode
911     if errCode == 0:
912     return True
913     if errCode == 34:
914     ## Path already exists
915     return False
916     else:
917     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
918 ninoborges 8
919     def CopyToLN(self,absSourcePathAndFile,targetDir):
920     """copies absPath to LN. targetDir should be a dir not a file."""
921     ## Expedat requires that if it's a target dir, you end it in a trailing slash
922     targetDir = os.path.join(self.initialPath,targetDir)
923     targetDir = targetDir + "\\"
924     args = [self.exeLocation,absSourcePathAndFile,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,targetDir)]
925     fnull = open(os.devnull, 'w')
926     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
927     fnull.close()
928     #return errCode
929     if errCode == 0:
930     return True
931     if errCode == 25:
932     """The target path does not exist"""
933     return False
934     elif errCode == 29:
935     """The source file or path does not exist"""
936     return False
937     else:
938     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
939    
940     class MweFtpConnection:
941     def __init__(self):
942     self.userName = "eborges"
943     self.hostName = "disftp.mwe.com"
944     self.userPassword = "rever78"
945     self.connection = ftplib.FTP_TLS(self.hostName)
946     self.connection.login(self.userName,self.userPassword)
947     self.connection.prot_p()
948    
949     def TestPath(self,path):
950     startDir = self.connection.pwd()
951     try:
952     self.connection.cwd(path)
953     sucess = True
954     except:
955     sucess = False
956     self.connection.cwd(startDir)
957     return sucess
958    
959     def CreateNewPath(self,path):
960     self.connection.mkd(path)
961    
962     def CopyToDis(self,absSourcePathAndFile,targetDir):
963     startDir = self.connection.pwd()
964     fileName = os.path.split(absSourcePathAndFile)[1]
965     self.connection.cwd(targetDir)
966     activePackage = open(absSourcePathAndFile,'rb')
967     self.connection.storbinary("STOR %s"%fileName,activePackage)
968     activePackage.close()
969     self.connection.cwd(startDir)
970    
971     def CloseConnection(self):
972     self.connection.close()