ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 446
Committed: Thu Aug 29 17:47:26 2013 UTC (12 years, 7 months ago) by nino.borges
Content type: text/x-python
File size: 45111 byte(s)
Log Message:
Updated the expedat connection to connect to the new IDS location.

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, win32com.decimal_23
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 1.8.0'
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,ProducedTo,ProductionMedia,ProductionSource,RequestedBy,ProductionDate,ProductionMediaPassword",
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 productionMatrix = {}
197 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 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 str(daoRSObj.Fields('ProductionComplDate').Value).split(' ')[0],
217 str(daoRSObj.Fields('ProductionDate').Value).split(' ')[0],
218 str(daoRSObj.Fields('BegBates').Value),str(daoRSObj.Fields('EndBates').Value),
219 docCount,pgCount,
220 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 str(daoRSObj.Fields('Notes').Value)))
226 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 daoRSObj.MoveNext()
244 #print len(productionList)
245 daoRSObj.Close()
246 return productionMatrix
247
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
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
412 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 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
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
551 def UpdateProductionDetail(self, CLM, prodID, prodProcessedDate, begBates,endBates,prodDocCount, prodPageCount, prodNotes, prodTo, prodMedia,prodSource,prodReqBy,prodSentDate,prodMediaPassword):
552 """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 daoRSObj.Fields('ProductionComplDate').Value = prodProcessedDate
582 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 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
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 def UpdateClientMatterNum(self,oldCLM,newCLM):
685 """Changes the client matter number for a case"""
686 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%oldCLM)
687 daoRSObj.Edit()
688 daoRSObj.Fields('ClientMatterNum').Value = newCLM
689 daoRSObj.Update()
690 daoRSObj.Close()
691
692 def GetAlternateMediaPath(self,CLM):
693 """Returns the alternate media path"""
694 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
695 val = daoRSObj.Fields('AlternateMediaPath').Value
696 daoRSObj.Close()
697 return val
698
699 def UpdateAlternateMediaPath(self,CLM,alternateMediaPath):
700 """Updates the alternate Media Path in the db"""
701 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
702 daoRSObj.Edit()
703 daoRSObj.Fields('AlternateMediaPath').Value = alternateMediaPath
704 daoRSObj.Update()
705 daoRSObj.Close()
706
707 def GetVendorFolderPath(self,CLM):
708 """Returns the vendor Folder path"""
709 try:
710 daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
711 val = daoRSObj.Fields('VendorFolderPath').Value
712 daoRSObj.Close()
713 except:
714 val = None
715 return val
716
717 def UpdateVendorFolderPath(self,CLM,vendorFolderPath):
718 """Updates the Vendor Folder Path in the db"""
719 #print vendorFolderPath
720 try:
721 daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
722 daoRSObj.Edit()
723 except:
724 daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath')
725 daoRSObj.Edit()
726 daoRSObj.Fields('ClientMatterNum').Value = CLM
727 daoRSObj.Fields('VendorFolderPath').Value = vendorFolderPath
728 daoRSObj.Update()
729 daoRSObj.Close()
730
731 def GetUploadCostRate(self,CLM):
732 """Returns the upload cost for a case"""
733 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
734 val = daoRSObj.Fields('UploadCost_GB').Value
735 daoRSObj.Close()
736 return val
737
738 def UpdateUploadCostRate(self,CLM, uploadCost):
739 """Updates the upload cost for a case"""
740 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
741 daoRSObj.Edit()
742 daoRSObj.Fields('UploadCost_GB').Value = uploadCost
743 daoRSObj.Update()
744 daoRSObj.Close()
745
746 def GetStorageCostRate(self,CLM):
747 """Returns the Storage cost for a case"""
748 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
749 val = daoRSObj.Fields('StorageCost_GB').Value
750 daoRSObj.Close()
751 return val
752
753 def UpdateStorageCostRate(self,CLM, storageCost):
754 """Updates the upload cost for a case"""
755 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
756 daoRSObj.Edit()
757 daoRSObj.Fields('StorageCost_GB').Value = storageCost
758 daoRSObj.Update()
759 daoRSObj.Close()
760
761 def GetDefaultUploadCostRate(self, platform = "Relativity"):
762 """Returns the current default upload cost"""
763 if platform == "Relativity":
764 cost = "50"
765 else:
766 cost = "50"
767 return cost
768
769 def GetDefaultStorageCostRate(self, platform = "Relativity"):
770 """Returns the current default storage cost"""
771 if platform == "Relativity":
772 cost = "20"
773 else:
774 cost = "20"
775 return cost
776
777 class ExpeDatConnection:
778 def __init__(self, platform):
779 if platform == "Relativity":
780 self.initialPath = "Relativity"
781 #self.userName = "eborges"
782 else:
783 self.initialPath = "Concordance Data"
784 #self.userName = "eborgesc"
785
786 self.userName = "eborges"
787 #self.hostName = "@mweftp.litigation.lexisnexis.com"
788 self.hostName = "transfer.mcdermottdiscovery.com"
789 self.userPassword = "9atrEFeh"
790 #self.exeLocation = r"C:\Documents and Settings\eborges\My Documents\MyDownloads\ExpDat\movedat.exe"
791 self.exeLocation = r"C:\Program Files\ExpDat\movedat.exe"
792
793 def ListDir(self,path):
794 """Returns the contents of a directory. returns files, dirs."""
795 path = os.path.join(self.initialPath,path)
796 args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
797 fnull = open(os.devnull, 'w')
798 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
799 rawFileList,errCode =process.communicate()
800 rawFileList = rawFileList.split("\n")
801 fileList = []
802 dirList = []
803 if rawFileList:
804 for i in rawFileList:
805 if i:
806 i = i.split(" ")[-1]
807 if i[-1] == "/":
808 dirList.append(i)
809 else:
810 fileList.append(i)
811 fnull.close()
812 return fileList, dirList
813
814 def GatherFullDirListMatrix(self,vendorFolder):
815 """Returns a matrix of a list path, with all the files and dirs in a vendor folder"""
816 fileList,dirList = self.ListDir(vendorFolder)
817 folderMatrix = []
818 currentPath = vendorFolder
819 for indFile in fileList:
820 folderMatrix.append(indFile)
821 #while dirList:
822 for dir in dirList:
823 #print dir
824 newPath = os.path.join(currentPath, dir)
825 print currentPath
826 subFileList,subDirList = self.ListDir(newPath)
827 newList = []
828 for indFile in subFileList:
829 newList.append(indFile)
830 #print indFile
831 folderMatrix.append([dir,newList])
832 #print folderMatrix
833 #while dirList:
834 return folderMatrix
835
836 def GatherSize(self,path):
837 """Returns the size of a given path or archive"""
838 extension = os.path.splitext(path)[1]
839 path = os.path.join(self.initialPath,path)
840 #path = self.initialPath + "/" + path
841 if extension.upper() == '.ZIP':
842 args = [self.exeLocation,"-D","%s:%s%s:%s=zipsize"%(self.userName,self.userPassword,self.hostName,path)]
843 fnull = open(os.devnull, 'w')
844 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
845 rawFileSize,errCode =process.communicate()
846 elif extension == "":
847 args = [self.exeLocation,"%s:%s%s:%s=*lr"%(self.userName,self.userPassword,self.hostName,path)]
848 #print args
849 fnull = open(os.devnull, 'w')
850 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
851 rawDirList,errCode =process.communicate()
852 rawDirList = rawDirList.split("\n")
853 rawFileSize = 0
854 for line in rawDirList[1:]:
855 if line:
856 size = line.split("\t")[1]
857 itemType = line.split("\t")[3]
858 if itemType == "F":
859 rawFileSize = rawFileSize + int(size,16)
860 else:
861 args = [self.exeLocation,"%s:%s%s:%s=*ls"%(self.userName,self.userPassword,self.hostName,path)]
862 #print args
863 fnull = open(os.devnull, 'w')
864 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
865 rawDirList,errCode =process.communicate()
866 rawDirList = rawDirList.split("\n")[2]
867 print rawDirList
868 rawFileSize = 0
869 if rawDirList:
870 size = rawDirList.split("\t")[1]
871 rawFileSize = int(size,16)
872 fnull.close()
873 if rawFileSize:
874 print "size is %s"%rawFileSize
875 else:
876 rawFileSize = False
877 return rawFileSize
878
879 def TestPath(self,path):
880 """Tests to see if path already exists"""
881 path = os.path.join(self.initialPath,path)
882 args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
883 #print args
884 fnull = open(os.devnull, 'w')
885 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
886 fnull.close()
887 if errCode == 0:
888 return True
889 if errCode == 25:
890 return False
891 else:
892 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
893
894 def CreateNewPath(self,path):
895 """Creates a new path on the LN system"""
896 path = os.path.join(self.initialPath,path)
897 args = [self.exeLocation,"-n","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
898 fnull = open(os.devnull, 'w')
899 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
900 fnull.close()
901 #return errCode
902 if errCode == 0:
903 return True
904 if errCode == 34:
905 ## Path already exists
906 return False
907 else:
908 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
909
910 def MoveOnLN(self,absSourcePathAndFile,targetDirAndFile):
911 """Performs a move from LN to LN"""
912 targetDirAndFile = os.path.join(self.initialPath,targetDirAndFile)
913 absSourcePathAndFile = os.path.join(self.initialPath,absSourcePathAndFile)
914 #targetDir = targetDir + "\\"
915 args = [self.exeLocation,"-m","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,absSourcePathAndFile),"%s"%targetDirAndFile]
916 fnull = open(os.devnull, 'w')
917 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
918 fnull.close()
919 #return errCode
920 if errCode == 0:
921 return True
922 if errCode == 34:
923 ## Path already exists
924 return False
925 else:
926 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
927
928 def CopyToLN(self,absSourcePathAndFile,targetDir):
929 """copies absPath to LN. targetDir should be a dir not a file."""
930 ## Expedat requires that if it's a target dir, you end it in a trailing slash
931 targetDir = os.path.join(self.initialPath,targetDir)
932 targetDir = targetDir + "\\"
933 args = [self.exeLocation,absSourcePathAndFile,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,targetDir)]
934 fnull = open(os.devnull, 'w')
935 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
936 fnull.close()
937 #return errCode
938 if errCode == 0:
939 return True
940 if errCode == 25:
941 """The target path does not exist"""
942 return False
943 elif errCode == 29:
944 """The source file or path does not exist"""
945 return False
946 else:
947 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
948
949 class MweFtpConnection:
950 def __init__(self):
951 self.userName = "eborges"
952 self.hostName = "disftp.mwe.com"
953 self.userPassword = "rever78"
954 self.connection = ftplib.FTP_TLS(self.hostName)
955 self.connection.login(self.userName,self.userPassword)
956 self.connection.prot_p()
957
958 def TestPath(self,path):
959 startDir = self.connection.pwd()
960 try:
961 self.connection.cwd(path)
962 sucess = True
963 except:
964 sucess = False
965 self.connection.cwd(startDir)
966 return sucess
967
968 def CreateNewPath(self,path):
969 self.connection.mkd(path)
970
971 def CopyToDis(self,absSourcePathAndFile,targetDir):
972 startDir = self.connection.pwd()
973 fileName = os.path.split(absSourcePathAndFile)[1]
974 self.connection.cwd(targetDir)
975 activePackage = open(absSourcePathAndFile,'rb')
976 self.connection.storbinary("STOR %s"%fileName,activePackage)
977 activePackage.close()
978 self.connection.cwd(startDir)
979
980 def CloseConnection(self):
981 self.connection.close()