ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 266
Committed: Mon Feb 4 19:25:36 2013 UTC (13 years, 1 month ago) by nino.borges
Content type: text/x-python
File size: 36780 byte(s)
Log Message:
moved the list of archive file types to the lib, so that there would be one place only to change it, and pointed copy up here.  Also added a warning dialog to copy up to warn when it's about to gather the compressed size of an archive.

File Contents

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