ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 232
Committed: Wed Dec 19 20:55:55 2012 UTC (13 years, 3 months ago) by nino.borges
Content type: text/x-python
File size: 36615 byte(s)
Log Message:
changed expire date on chai v8 and 10. Added GatherSize to MCP lib.

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     import os,sys, win32com.client,subprocess,ftplib,NinoGenTools
15    
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     def GetMCPVersion():
109     """Returns the current version of the entire MCP program set"""
110 nino.borges 151 return 'v .17'
111 ninoborges 8
112    
113     class AccessDBConnection:
114     def __init__(self, accessDB):
115     daoEngine = win32com.client.Dispatch('DAO.DBEngine.36')
116     self.daoDB = daoEngine.OpenDatabase(accessDB)
117    
118     def MakeNewRSConnection(self, table, specialSelect = "*", specialWhere="" ):
119     """ This method will make a new RS connection for either reading or writing."""
120     if specialWhere:
121     statement = "SELECT %s FROM %s WHERE %s"%(specialSelect,table, specialWhere)
122     else:
123     statement = "SELECT %s FROM %s"%(specialSelect,table)
124     daoRSObj = self.daoDB.OpenRecordset(statement)
125     return daoRSObj
126    
127     def CloseAccessConnection(self):
128     """This closes the entire connection and not just the RS"""
129     self.daoDB.Close()
130    
131     def RetrieveAllCaseList(self):
132     """Retrieves all of the cases in the database regardless of assignment.(client matter list)"""
133     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData')
134     daoRSObj.MoveLast()
135     fullCount = daoRSObj.RecordCount
136     daoRSObj.MoveFirst()
137    
138     accessDBCLMList = []
139     for i in range(fullCount):
140     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
141     daoRSObj.MoveNext()
142     daoRSObj.Close()
143     return accessDBCLMList
144    
145     def RetrieveMyCaseList(self, empID):
146     """Retrieves just 1 employees case list (client matter list)"""
147     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "empID = '%s'"%empID)
148     daoRSObj.MoveLast()
149     fullCount = daoRSObj.RecordCount
150     daoRSObj.MoveFirst()
151    
152     accessDBCLMList = []
153     for i in range(fullCount):
154     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
155     daoRSObj.MoveNext()
156     daoRSObj.Close()
157     return accessDBCLMList
158    
159     def RetrieveOfficeCaseList(self, primaryOffice):
160     """Retrieves the case list for an entire office. Note, a case can be owned by a TPM in another office but
161     the primary office might still be an office that that TPM does not work for. Also people are not always
162     good about updating the primary office...(client matter list)"""
163     accessDBCLMList = []
164     try:
165     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "PrimaryOffice = '%s'"%primaryOffice)
166     daoRSObj.MoveLast()
167     fullCount = daoRSObj.RecordCount
168     daoRSObj.MoveFirst()
169    
170    
171     for i in range(fullCount):
172     accessDBCLMList.append(daoRSObj.Fields('ClientMatterNum').Value)
173     daoRSObj.MoveNext()
174     daoRSObj.Close()
175     except:
176     pass
177     return accessDBCLMList
178    
179     def RetrieveProductionsByCLM(self,CLM):
180     """This will retrieve a FULL production matrix for a specific clm"""
181     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail',
182     "ProductionID,ProductionComplDate, BegBates,EndBates,ProdDocCount,ProdPageCount,Notes",
183     specialWhere = "ClientMatterNum='%s' ORDER BY ProductionComplDate"%CLM)
184     try:
185     ## Getting an exception that I cant capture when table is empty.
186     ## this will test and return empty if empty, until I can figure out a better test.
187     daoRSObj.MoveLast()
188     tableHasData = True
189     except:
190     tableHasData = False
191     productionList = []
192     if tableHasData:
193     fullCount = daoRSObj.RecordCount
194     daoRSObj.MoveFirst()
195     for i in range(fullCount):
196     try:
197     pgCount = str(int(daoRSObj.Fields('ProdPageCount').Value))
198     except:
199     pgCount = '0'
200     try:
201     docCount = str(int(daoRSObj.Fields('ProdDocCount').Value))
202     except:
203     docCount = '0'
204     productionList.append((str(daoRSObj.Fields('ProductionID').Value),
205     str(daoRSObj.Fields('ProductionComplDate').Value).split(' ')[0],
206     str(daoRSObj.Fields('BegBates').Value),str(daoRSObj.Fields('EndBates').Value),
207     docCount,pgCount,
208     str(daoRSObj.Fields('Notes').Value)))
209     daoRSObj.MoveNext()
210     print len(productionList)
211     daoRSObj.Close()
212     return productionList
213    
214    
215     def RetrieveUploadsByCLM(self, CLM):
216     """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."""
217     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity',
218     "UEPOCH,ReviewPlatform,DataLoadDate,DataLoadedGB,DataLoadedMB,DataLoadedKB",
219     specialWhere = "ClientMatterNum='%s'"%CLM)
220     try:
221     ## Getting an exception that I cant capture when table is empty.
222     ## this will test and return empty if empty, until I can figure out a better test.
223     daoRSObj.MoveLast()
224     tableHasData = True
225     except:
226     tableHasData = False
227     caseUploadList = []
228     if tableHasData:
229     fullCount = daoRSObj.RecordCount
230     daoRSObj.MoveFirst()
231    
232     for i in range(fullCount):
233     if daoRSObj.Fields('DataLoadedKB').Value:
234     size = str(daoRSObj.Fields('DataLoadedKB').Value) + ' KB'
235     elif daoRSObj.Fields('DataLoadedMB').Value:
236     size = str(daoRSObj.Fields('DataLoadedMB').Value) + ' MB'
237     else:
238     size = str(daoRSObj.Fields('DataLoadedGB').Value) + ' GB'
239    
240     caseUploadList.append((str(daoRSObj.Fields('UEPOCH').Value),daoRSObj.Fields('ReviewPlatform').Value,
241     str(daoRSObj.Fields('DataLoadDate').Value).split(' ')[0],size))
242     daoRSObj.MoveNext()
243     daoRSObj.Close()
244     return caseUploadList
245    
246     def RetrieveOfficeUploads(self, primaryOffice):
247     """This only returns a matrix of clm{[EPOCH]}, since there isnt a reason to sync uploads from access"""
248     myClientMatterList = self.RetrieveOfficeCaseList(primaryOffice)
249     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
250     daoRSObj.MoveLast()
251     fullCount = daoRSObj.RecordCount
252     daoRSObj.MoveFirst()
253    
254     caseUploadMatrix = {}
255     for i in range(fullCount):
256     currentClientMatter = daoRSObj.Fields('ClientMatterNum').Value
257     if currentClientMatter in myClientMatterList:
258     epoch = str(daoRSObj.Fields('UEPOCH').Value)
259     try:
260     caseUploadMatrix[currentClientMatter].append(epoch)
261     except:
262     caseUploadMatrix[currentClientMatter] = [epoch]
263     daoRSObj.MoveNext()
264     daoRSObj.Close()
265     return caseUploadMatrix
266    
267     def RetrieveMyCaseUploads(self,empID):
268     """This only returns a matrix of clm{[EPOCH]}, since there isnt a reason to sync uploads from access"""
269     myClientMatterList = self.RetrieveMyCaseList(empID)
270     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
271     daoRSObj.MoveLast()
272     fullCount = daoRSObj.RecordCount
273     daoRSObj.MoveFirst()
274    
275     caseUploadMatrix = {}
276     for i in range(fullCount):
277     currentClientMatter = daoRSObj.Fields('ClientMatterNum').Value
278     if currentClientMatter in myClientMatterList:
279     epoch = daoRSObj.Fields('UEPOCH').Value
280     if epoch:
281     epoch = str(epoch)
282     if '.' in epoch:
283     epoch = epoch.split('.')[0]
284    
285     try:
286     caseUploadMatrix[currentClientMatter].append(epoch)
287     except:
288     caseUploadMatrix[currentClientMatter] = [epoch]
289     #loadedDate = daoRSObj.Fields('DataLoadDate').Value
290     #loadedDate = str(loadedDate.Format('%Y%m%d'))
291     #loadedSize =daoRSObj.Fields('DataLoadedGB').Value
292     #loadedSizeType = " GB"
293     #
294     #if loadedSize:
295     # ## If the GB loaded size exists, use that.
296     # pass
297     #else:
298     # ## if it does not, use the MB loaded field.
299     # loadedSize =daoRSObj.Fields('DataLoadedMB').Value
300     # loadedSizeType = " MB"
301     #loadedSize = str(loadedSize)
302     #if "." in loadedSize:
303     # loadedSize = loadedSize[:loadedSize.index('.')+3]
304     #try:
305     # caseUploadMatrix[currentClientMatter].append((loadedDate,loadedSize+loadedSizeType))
306     #except:
307     # caseUploadMatrix[currentClientMatter] = [(loadedDate,loadedSize+loadedSizeType)]
308     daoRSObj.MoveNext()
309     daoRSObj.Close()
310     return caseUploadMatrix
311    
312     def AddNewCase(self, caseName, CLM, TPM_Name, empID, chargable = False, reviewPlatform = "", responsibleVendor = "", responsibleOffice = ""):
313     """Adds a new case in the access DB."""
314     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData')
315     daoRSObj.AddNew()
316     daoRSObj.Fields('ClientMatterNum').Value = CLM
317     daoRSObj.Fields('CaseName').Value = caseName
318     daoRSObj.Fields('EmpID').Value = empID
319     daoRSObj.Fields('TPM').Value = TPM_Name
320     daoRSObj.Fields('PrimaryOffice').Value = responsibleOffice
321     daoRSObj.Update()
322     daoRSObj.Close()
323    
324     ## Per aaron, add to two other tables
325     clientNumber = CLM.split('.')[0]
326     daoRSObj = self.MakeNewRSConnection('tbl_Ref_Client')
327     try:
328     daoRSObj.AddNew()
329     daoRSObj.Fields('ClientNum').Value = clientNumber
330     daoRSObj.Update()
331     except:
332     pass
333     daoRSObj.Close()
334    
335     daoRSObj = self.MakeNewRSConnection('tbl_Ref_ClientMatter')
336     try:
337     daoRSObj.AddNew()
338     daoRSObj.Fields('ClientNum').Value = clientNumber
339     daoRSObj.Fields('ClientMatterNum').Value = CLM
340     daoRSObj.Update()
341     except:
342     pass
343     daoRSObj.Close()
344    
345     ## These below make their own record sets.
346     if chargable:
347     ## change this one aaron adds it.
348     pass
349     if reviewPlatform:
350     self.UpdateReviewPlatform(CLM, reviewPlatform)
351     if responsibleVendor:
352     self.UpdateResponsibleVendor(CLM,responsibleVendor)
353    
354    
355    
356     def UpdateChargable(self, CLM, chargable):
357     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
358     daoRSObj.Edit()
359     daoRSObj.Fields('BillableMatter').Value = chargable
360     daoRSObj.Update()
361     daoRSObj.Close()
362    
363     def GetChargable(self,CLM):
364     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
365     chargable = daoRSObj.Fields('BillableMatter').Value
366     daoRSObj.Close()
367     return chargable
368    
369     def UpdateReviewPlatform(self, CLM, reviewPlatform):
370     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
371     daoRSObj.Edit()
372     daoRSObj.Fields('ReviewPlatform').Value = reviewPlatform
373     daoRSObj.Update()
374     daoRSObj.Close()
375    
376     def GetReviewPlatform(self,CLM):
377     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
378     platform = daoRSObj.Fields('ReviewPlatform').Value
379     daoRSObj.Close()
380     return platform
381    
382     def UpdateResponsibleVendors(self, CLM,responsibleVendorTpl):
383     """VendorTpl should be a tuple of (processing,scanning,hosting) with None if you dont have it"""
384     processingVendor, scanningVendor, hostingVendor = responsibleVendorTpl
385     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
386     if processingVendor:
387     daoRSObj.Edit()
388     daoRSObj.Fields('ProcessingVendor').Value = processingVendor
389     daoRSObj.Update()
390     if scanningVendor:
391     daoRSObj.Edit()
392     daoRSObj.Fields('ScanningVendor').Value = scanningVendor
393     daoRSObj.Update()
394     if hostingVendor:
395     daoRSObj.Edit()
396     daoRSObj.Fields('HostingVendor').Value = hostingVendor
397     daoRSObj.Update()
398     daoRSObj.Close()
399    
400     def GetResponsibleVendorTpl(self, CLM):
401     """Returns a tuple of (processing,scanning,hosting) with None if you dont have it"""
402     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
403     processingVendor = daoRSObj.Fields('ProcessingVendor').Value
404     scanningVendor = daoRSObj.Fields('ScanningVendor').Value
405     hostingVendor = daoRSObj.Fields('HostingVendor').Value
406     daoRSObj.Close()
407     tmpTpl = (processingVendor,scanningVendor,hostingVendor)
408     return tmpTpl
409    
410     def UpdateCaseUpload(self, CLM, reviewPlatform, uploadMatrix):
411     """Format for matrix is epoch is key and uploads are in a tpl. (12/23/2010,49MB) Date format is mm/dd/yyyy"""
412     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity')
413    
414     ## Dont for get to convert the date first somewhere.
415     for i in uploadMatrix.keys():
416     (date, size) = uploadMatrix[i]
417     daoRSObj.AddNew()
418     daoRSObj.Fields('ClientMatterNum').Value = CLM
419     daoRSObj.Fields('UEPOCH').Value = i
420     daoRSObj.Fields('DataLoadDate').Value = date
421     daoRSObj.Fields('ReviewPlatform').Value = reviewPlatform
422     if "GB" in size:
423     daoRSObj.Fields('dataLoadedGB').Value = float(size.replace("GB",""))
424     elif "MB" in size:
425     daoRSObj.Fields('dataLoadedMB').Value = float(size.replace("MB",""))
426     else:
427     daoRSObj.Fields('DataLoadedKB').Value = float(size.replace("KB",""))
428     daoRSObj.Update()
429     daoRSObj.Close()
430    
431     def DeleteCaseUpload(self,CLM,UEPOCH):
432     """This method will let you delete a single case upload but only if it was added by the MCP.
433     i.e has a UEPOCH"""
434     ## When calling UEPOCHs, dont put it in a ''
435     daoRSObj = self.MakeNewRSConnection('tbl_ClientDataQuantity', specialWhere = "UEPOCH=%s"%UEPOCH)
436     ## 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.
437     daoRSObj.MoveLast()
438     recordCount = daoRSObj.RecordCount
439     daoRSObj.MoveFirst()
440     ## This wont allow you to delete if there are multiple records with same UEPOCH
441     if recordCount == 1:
442     val2 = daoRSObj.Fields('ClientMatterNum').Value
443     if val2 == CLM:
444     daoRSObj.Delete()
445     errorRpt = False
446     else:
447     errorRpt = True
448     else:
449     errorRpt = True
450     daoRSObj.Close()
451     #print errorRpt
452     return errorRpt
453    
454     def UpdateProductionDetail(self, CLM, prodID, prodDate, begBates,endBates,prodDocCount, prodPageCount, prodNotes):
455     """This method will let you add an entire produciton record to the production table. All fields are manadatory.
456     the date is in mm/dd/yyyy format."""
457     try:
458     testdaoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail', specialSelect ="ProductionID",specialWhere = "ClientMatterNum='%s'"%CLM)
459     testdaoRSObj.MoveLast()
460     testRecordCount = testdaoRSObj.RecordCount
461     testdaoRSObj.MoveFirst()
462     prodList = []
463     if testRecordCount:
464     for i in range(testRecordCount):
465     prodList.append(testdaoRSObj.Fields('ProductionID').Value)
466     testdaoRSObj.MoveNext()
467     testdaoRSObj.Close()
468     #print testRecordCount
469     #print prodList
470     if prodID in prodList:
471     prodIncrement = NinoGenTools.Counter(1)
472     prodID = prodID+ "_"+"%0*d"%(4,prodIncrement.count)
473     prodIncrement.inc()
474     while prodID in prodList:
475     prodID = prodID[:-4] +"%0*d"%(4,prodIncrement.count)
476     prodIncrement.inc()
477     except:
478     pass
479    
480     daoRSObj = self.MakeNewRSConnection('Tbl_MatterProductionDetail')
481     daoRSObj.AddNew()
482     daoRSObj.Fields('ClientMatterNum').Value = CLM
483     daoRSObj.Fields('ProductionID').Value = prodID
484     daoRSObj.Fields('ProductionComplDate').Value = prodDate
485     daoRSObj.Fields('BegBates').Value = begBates
486     daoRSObj.Fields('EndBates').Value = endBates
487     daoRSObj.Fields('ProdDocCount').Value = prodDocCount
488     daoRSObj.Fields('ProdPageCount').Value = prodPageCount
489     daoRSObj.Fields('Notes').Value = prodNotes
490    
491     daoRSObj.Update()
492     daoRSObj.Close()
493    
494     def UpdateResponsibleAttorney(self, CLM, responsibleAttny):
495     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
496     daoRSObj.Edit()
497     daoRSObj.Fields('PrimaryAttorneyContact').Value = responsibleAttny
498     daoRSObj.Update()
499     daoRSObj.Close()
500    
501     def GetResponsibleAttorney(self, CLM):
502     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
503     val = daoRSObj.Fields('PrimaryAttorneyContact').Value
504     daoRSObj.Close()
505     return val
506    
507     def UpdateOtherAttorneys(self,CLM, otherAttorneysList):
508     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
509     daoRSObj.Edit()
510     ## add this when aaron adds it.
511     daoRSObj.Update()
512     daoRSObj.Close()
513    
514     def UpdateResponsibleParalegal(self,CLM, responsibleParalegal):
515     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
516     daoRSObj.Edit()
517     daoRSObj.Fields('ParalegalContact').Value = responsibleParalegal
518     daoRSObj.Update()
519     daoRSObj.Close()
520    
521     def GetResponsibleParalegal(self,CLM):
522     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
523     val = daoRSObj.Fields('ParalegalContact').Value
524     daoRSObj.Close()
525     return val
526    
527     def UpdatePrimaryOffice(self,CLM, primaryOffice):
528     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
529     daoRSObj.Edit()
530     daoRSObj.Fields('PrimaryOffice').Value = primaryOffice
531     daoRSObj.Update()
532     daoRSObj.Close()
533    
534     def GetPrimaryOffice(self,CLM):
535     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
536     val = daoRSObj.Fields('PrimaryOffice').Value
537     daoRSObj.Close()
538     return val
539    
540     def UpdateResponsibleTPM(self, CLM, tPMName):
541     """Format should be last, first"""
542     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
543     daoRSObj.Edit()
544     daoRSObj.Fields('TPM').Value = tPMName
545     daoRSObj.Update()
546     daoRSObj.Close()
547    
548     def GetResponsibleTPM(self,CLM):
549     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
550     val = daoRSObj.Fields('TPM').Value
551     daoRSObj.Close()
552     return val
553    
554     def GetCaseStatus(self,CLM):
555     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
556     val = daoRSObj.Fields('ProjectStatus').Value
557     daoRSObj.Close()
558     return val
559    
560     def UpdateCaseStatus(self,CLM,status):
561     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
562     daoRSObj.Edit()
563     daoRSObj.Fields('ProjectStatus').Value = status
564     daoRSObj.Update()
565     daoRSObj.Close()
566    
567     def GetCaseName(self,CLM):
568     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
569     val = daoRSObj.Fields('CaseName').Value
570     daoRSObj.Close()
571     return val
572    
573     def UpdateCaseName(self,CLM,caseName):
574     """This is just the internal name for the case"""
575     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
576     daoRSObj.Edit()
577     daoRSObj.Fields('CaseName').Value = caseName
578     daoRSObj.Update()
579     daoRSObj.Close()
580    
581 nino.borges 232 def GetAlternateMediaPath(self,CLM):
582     """Returns the alternate media path"""
583     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
584     val = daoRSObj.Fields('AlternateMediaPath').Value
585     daoRSObj.Close()
586     return val
587    
588     def UpdateAlternateMediaPath(self,CLM,alternateMediaPath):
589     """Updates the alternate Media Path in the db"""
590     daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
591     daoRSObj.Edit()
592     daoRSObj.Fields('AlternateMediaPath').Value = alternateMediaPath
593     daoRSObj.Update()
594     daoRSObj.Close()
595    
596     def GetVendorFolderPath(self,CLM):
597     """Returns the vendor Folder path"""
598     try:
599     daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
600     val = daoRSObj.Fields('VendorFolderPath').Value
601     daoRSObj.Close()
602     except:
603     val = None
604     return val
605    
606     def UpdateVendorFolderPath(self,CLM,vendorFolderPath):
607     """Updates the Vendor Folder Path in the db"""
608     daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
609     daoRSObj.Edit()
610     daoRSObj.Fields('VendorFolderPath').Value = vendorFolderPath
611     daoRSObj.Update()
612     daoRSObj.Close()
613    
614 ninoborges 8 class ExpeDatConnection:
615     def __init__(self, platform):
616     if platform == "Relativity":
617     self.initialPath = "Relativity"
618     #self.userName = "eborges"
619     else:
620     self.initialPath = "Concordance Data"
621     #self.userName = "eborgesc"
622    
623     self.userName = "eborges"
624     self.hostName = "@mweftp.litigation.lexisnexis.com"
625     self.userPassword = "9atrEFeh"
626     #self.exeLocation = r"C:\Documents and Settings\eborges\My Documents\MyDownloads\ExpDat\movedat.exe"
627     self.exeLocation = r"C:\Program Files\ExpDat\movedat.exe"
628    
629 nino.borges 203 def ListDir(self,path):
630     """Returns the contents of a directory. returns files, dirs."""
631     path = os.path.join(self.initialPath,path)
632     args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
633     fnull = open(os.devnull, 'w')
634     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
635     rawFileList,errCode =process.communicate()
636     rawFileList = rawFileList.split("\n")
637     fileList = []
638     dirList = []
639     if rawFileList:
640     for i in rawFileList:
641     if i:
642     i = i.split(" ")[-1]
643     if i[-1] == "/":
644     dirList.append(i)
645     else:
646     fileList.append(i)
647     fnull.close()
648     return fileList, dirList
649    
650     def GatherFullDirListMatrix(self,vendorFolder):
651     """Returns a matrix of a list path, with all the files and dirs in a vendor folder"""
652     fileList,dirList = self.ListDir(vendorFolder)
653     folderMatrix = []
654     currentPath = vendorFolder
655     for indFile in fileList:
656     folderMatrix.append(indFile)
657     #while dirList:
658     for dir in dirList:
659 nino.borges 232 #print dir
660 nino.borges 206 newPath = os.path.join(currentPath, dir)
661 nino.borges 203 print currentPath
662 nino.borges 206 subFileList,subDirList = self.ListDir(newPath)
663 nino.borges 203 newList = []
664     for indFile in subFileList:
665     newList.append(indFile)
666 nino.borges 232 #print indFile
667 nino.borges 203 folderMatrix.append([dir,newList])
668 nino.borges 232 #print folderMatrix
669 nino.borges 203 #while dirList:
670     return folderMatrix
671    
672 nino.borges 232 def GatherSize(self,path):
673     """Returns the size of a given path or archive"""
674     extension = os.path.splitext(path)[1]
675     path = os.path.join(self.initialPath,path)
676     #path = self.initialPath + "/" + path
677     if extension.upper() == '.ZIP':
678     args = [self.exeLocation,"-D","%s:%s%s:%s=zipsize"%(self.userName,self.userPassword,self.hostName,path)]
679     fnull = open(os.devnull, 'w')
680     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
681     rawFileSize,errCode =process.communicate()
682     elif extension == "":
683     args = [self.exeLocation,"%s:%s%s:%s=*lr"%(self.userName,self.userPassword,self.hostName,path)]
684     #print args
685     fnull = open(os.devnull, 'w')
686     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
687     rawDirList,errCode =process.communicate()
688     rawDirList = rawDirList.split("\n")
689     rawFileSize = 0
690     for line in rawDirList[1:]:
691     if line:
692     size = line.split("\t")[1]
693     itemType = line.split("\t")[3]
694     if itemType == "F":
695     rawFileSize = rawFileSize + int(size,16)
696     else:
697     args = [self.exeLocation,"%s:%s%s:%s=*ls"%(self.userName,self.userPassword,self.hostName,path)]
698     #print args
699     fnull = open(os.devnull, 'w')
700     process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
701     rawDirList,errCode =process.communicate()
702     rawDirList = rawDirList.split("\n")[2]
703     print rawDirList
704     rawFileSize = 0
705     if rawDirList:
706     size = rawDirList.split("\t")[1]
707     rawFileSize = int(size,16)
708     fnull.close()
709     if rawFileSize:
710     print "size is %s"%rawFileSize
711     else:
712     rawFileSize = False
713    
714 ninoborges 8 def TestPath(self,path):
715     """Tests to see if path already exists"""
716     path = os.path.join(self.initialPath,path)
717     args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
718 nino.borges 232 #print args
719 ninoborges 8 fnull = open(os.devnull, 'w')
720     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
721     fnull.close()
722     if errCode == 0:
723     return True
724     if errCode == 25:
725     return False
726     else:
727     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
728    
729     def CreateNewPath(self,path):
730     """Creates a new path on the LN system"""
731     path = os.path.join(self.initialPath,path)
732     args = [self.exeLocation,"-n","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
733     fnull = open(os.devnull, 'w')
734     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
735     fnull.close()
736     #return errCode
737     if errCode == 0:
738     return True
739     if errCode == 34:
740     ## Path already exists
741     return False
742     else:
743     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
744 nino.borges 203
745     def MoveOnLN(self,absSourcePathAndFile,targetDirAndFile):
746     """Performs a move from LN to LN"""
747     targetDirAndFile = os.path.join(self.initialPath,targetDirAndFile)
748     absSourcePathAndFile = os.path.join(self.initialPath,absSourcePathAndFile)
749     #targetDir = targetDir + "\\"
750     args = [self.exeLocation,"-m","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,absSourcePathAndFile),"%s"%targetDirAndFile]
751     fnull = open(os.devnull, 'w')
752     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
753     fnull.close()
754     #return errCode
755     if errCode == 0:
756     return True
757     if errCode == 34:
758     ## Path already exists
759     return False
760     else:
761     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
762 ninoborges 8
763     def CopyToLN(self,absSourcePathAndFile,targetDir):
764     """copies absPath to LN. targetDir should be a dir not a file."""
765     ## Expedat requires that if it's a target dir, you end it in a trailing slash
766     targetDir = os.path.join(self.initialPath,targetDir)
767     targetDir = targetDir + "\\"
768     args = [self.exeLocation,absSourcePathAndFile,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,targetDir)]
769     fnull = open(os.devnull, 'w')
770     errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
771     fnull.close()
772     #return errCode
773     if errCode == 0:
774     return True
775     if errCode == 25:
776     """The target path does not exist"""
777     return False
778     elif errCode == 29:
779     """The source file or path does not exist"""
780     return False
781     else:
782     print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
783    
784     class MweFtpConnection:
785     def __init__(self):
786     self.userName = "eborges"
787     self.hostName = "disftp.mwe.com"
788     self.userPassword = "rever78"
789     self.connection = ftplib.FTP_TLS(self.hostName)
790     self.connection.login(self.userName,self.userPassword)
791     self.connection.prot_p()
792    
793     def TestPath(self,path):
794     startDir = self.connection.pwd()
795     try:
796     self.connection.cwd(path)
797     sucess = True
798     except:
799     sucess = False
800     self.connection.cwd(startDir)
801     return sucess
802    
803     def CreateNewPath(self,path):
804     self.connection.mkd(path)
805    
806     def CopyToDis(self,absSourcePathAndFile,targetDir):
807     startDir = self.connection.pwd()
808     fileName = os.path.split(absSourcePathAndFile)[1]
809     self.connection.cwd(targetDir)
810     activePackage = open(absSourcePathAndFile,'rb')
811     self.connection.storbinary("STOR %s"%fileName,activePackage)
812     activePackage.close()
813     self.connection.cwd(startDir)
814    
815     def CloseConnection(self):
816     self.connection.close()