ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 303
Committed: Wed Mar 6 16:09:57 2013 UTC (13 years ago) by nino.borges
Content type: text/x-python
File size: 38879 byte(s)
Log Message:
Added initial support for upload and hosting pricing and added an initial gui dialog to change it.  Updated version to 1.8.0

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 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",
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 #print vendorFolderPath
613 try:
614 daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath', specialWhere = "ClientMatterNum='%s'"%CLM)
615 daoRSObj.Edit()
616 except:
617 daoRSObj = self.MakeNewRSConnection('tbl_VendorFolderPath')
618 daoRSObj.Edit()
619 daoRSObj.Fields('ClientMatterNum').Value = CLM
620 daoRSObj.Fields('VendorFolderPath').Value = vendorFolderPath
621 daoRSObj.Update()
622 daoRSObj.Close()
623
624 def GetUploadCostRate(self,CLM):
625 """Returns the upload cost for a case"""
626 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
627 val = daoRSObj.Fields('UploadCost_GB').Value
628 daoRSObj.Close()
629 return val
630
631 def UpdateUploadCostRate(self,CLM, uploadCost):
632 """Updates the upload cost for a case"""
633 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
634 daoRSObj.Edit()
635 daoRSObj.Fields('UploadCost_GB').Value = uploadCost
636 daoRSObj.Update()
637 daoRSObj.Close()
638
639 def GetStorageCostRate(self,CLM):
640 """Returns the Storage cost for a case"""
641 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
642 val = daoRSObj.Fields('StorageCost_GB').Value
643 daoRSObj.Close()
644 return val
645
646 def UpdateStorageCostRate(self,CLM, storageCost):
647 """Updates the upload cost for a case"""
648 daoRSObj = self.MakeNewRSConnection('tbl_MatterTrackingData', specialWhere = "ClientMatterNum='%s'"%CLM)
649 daoRSObj.Edit()
650 daoRSObj.Fields('StorageCost_GB').Value = storageCost
651 daoRSObj.Update()
652 daoRSObj.Close()
653
654 def GetDefaultUploadCostRate(self, platform = "Relativity"):
655 """Returns the current default upload cost"""
656 if platform == "Relativity":
657 cost = "50"
658 else:
659 cost = "50"
660 return cost
661
662 def GetDefaultStorageCostRate(self, platform = "Relativity"):
663 """Returns the current default storage cost"""
664 if platform == "Relativity":
665 cost = "20"
666 else:
667 cost = "20"
668 return cost
669
670 class ExpeDatConnection:
671 def __init__(self, platform):
672 if platform == "Relativity":
673 self.initialPath = "Relativity"
674 #self.userName = "eborges"
675 else:
676 self.initialPath = "Concordance Data"
677 #self.userName = "eborgesc"
678
679 self.userName = "eborges"
680 self.hostName = "@mweftp.litigation.lexisnexis.com"
681 self.userPassword = "9atrEFeh"
682 #self.exeLocation = r"C:\Documents and Settings\eborges\My Documents\MyDownloads\ExpDat\movedat.exe"
683 self.exeLocation = r"C:\Program Files\ExpDat\movedat.exe"
684
685 def ListDir(self,path):
686 """Returns the contents of a directory. returns files, dirs."""
687 path = os.path.join(self.initialPath,path)
688 args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
689 fnull = open(os.devnull, 'w')
690 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
691 rawFileList,errCode =process.communicate()
692 rawFileList = rawFileList.split("\n")
693 fileList = []
694 dirList = []
695 if rawFileList:
696 for i in rawFileList:
697 if i:
698 i = i.split(" ")[-1]
699 if i[-1] == "/":
700 dirList.append(i)
701 else:
702 fileList.append(i)
703 fnull.close()
704 return fileList, dirList
705
706 def GatherFullDirListMatrix(self,vendorFolder):
707 """Returns a matrix of a list path, with all the files and dirs in a vendor folder"""
708 fileList,dirList = self.ListDir(vendorFolder)
709 folderMatrix = []
710 currentPath = vendorFolder
711 for indFile in fileList:
712 folderMatrix.append(indFile)
713 #while dirList:
714 for dir in dirList:
715 #print dir
716 newPath = os.path.join(currentPath, dir)
717 print currentPath
718 subFileList,subDirList = self.ListDir(newPath)
719 newList = []
720 for indFile in subFileList:
721 newList.append(indFile)
722 #print indFile
723 folderMatrix.append([dir,newList])
724 #print folderMatrix
725 #while dirList:
726 return folderMatrix
727
728 def GatherSize(self,path):
729 """Returns the size of a given path or archive"""
730 extension = os.path.splitext(path)[1]
731 path = os.path.join(self.initialPath,path)
732 #path = self.initialPath + "/" + path
733 if extension.upper() == '.ZIP':
734 args = [self.exeLocation,"-D","%s:%s%s:%s=zipsize"%(self.userName,self.userPassword,self.hostName,path)]
735 fnull = open(os.devnull, 'w')
736 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
737 rawFileSize,errCode =process.communicate()
738 elif extension == "":
739 args = [self.exeLocation,"%s:%s%s:%s=*lr"%(self.userName,self.userPassword,self.hostName,path)]
740 #print args
741 fnull = open(os.devnull, 'w')
742 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
743 rawDirList,errCode =process.communicate()
744 rawDirList = rawDirList.split("\n")
745 rawFileSize = 0
746 for line in rawDirList[1:]:
747 if line:
748 size = line.split("\t")[1]
749 itemType = line.split("\t")[3]
750 if itemType == "F":
751 rawFileSize = rawFileSize + int(size,16)
752 else:
753 args = [self.exeLocation,"%s:%s%s:%s=*ls"%(self.userName,self.userPassword,self.hostName,path)]
754 #print args
755 fnull = open(os.devnull, 'w')
756 process = subprocess.Popen(args,stdout = subprocess.PIPE, stderr = fnull)
757 rawDirList,errCode =process.communicate()
758 rawDirList = rawDirList.split("\n")[2]
759 print rawDirList
760 rawFileSize = 0
761 if rawDirList:
762 size = rawDirList.split("\t")[1]
763 rawFileSize = int(size,16)
764 fnull.close()
765 if rawFileSize:
766 print "size is %s"%rawFileSize
767 else:
768 rawFileSize = False
769 return rawFileSize
770
771 def TestPath(self,path):
772 """Tests to see if path already exists"""
773 path = os.path.join(self.initialPath,path)
774 args = [self.exeLocation,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
775 #print args
776 fnull = open(os.devnull, 'w')
777 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
778 fnull.close()
779 if errCode == 0:
780 return True
781 if errCode == 25:
782 return False
783 else:
784 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
785
786 def CreateNewPath(self,path):
787 """Creates a new path on the LN system"""
788 path = os.path.join(self.initialPath,path)
789 args = [self.exeLocation,"-n","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,path)]
790 fnull = open(os.devnull, 'w')
791 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
792 fnull.close()
793 #return errCode
794 if errCode == 0:
795 return True
796 if errCode == 34:
797 ## Path already exists
798 return False
799 else:
800 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
801
802 def MoveOnLN(self,absSourcePathAndFile,targetDirAndFile):
803 """Performs a move from LN to LN"""
804 targetDirAndFile = os.path.join(self.initialPath,targetDirAndFile)
805 absSourcePathAndFile = os.path.join(self.initialPath,absSourcePathAndFile)
806 #targetDir = targetDir + "\\"
807 args = [self.exeLocation,"-m","%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,absSourcePathAndFile),"%s"%targetDirAndFile]
808 fnull = open(os.devnull, 'w')
809 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
810 fnull.close()
811 #return errCode
812 if errCode == 0:
813 return True
814 if errCode == 34:
815 ## Path already exists
816 return False
817 else:
818 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
819
820 def CopyToLN(self,absSourcePathAndFile,targetDir):
821 """copies absPath to LN. targetDir should be a dir not a file."""
822 ## Expedat requires that if it's a target dir, you end it in a trailing slash
823 targetDir = os.path.join(self.initialPath,targetDir)
824 targetDir = targetDir + "\\"
825 args = [self.exeLocation,absSourcePathAndFile,"%s:%s%s:%s"%(self.userName,self.userPassword,self.hostName,targetDir)]
826 fnull = open(os.devnull, 'w')
827 errCode = subprocess.call(args,stdout = fnull, stderr = fnull)
828 fnull.close()
829 #return errCode
830 if errCode == 0:
831 return True
832 if errCode == 25:
833 """The target path does not exist"""
834 return False
835 elif errCode == 29:
836 """The source file or path does not exist"""
837 return False
838 else:
839 print "OTHER ERROR CODE %s. CALL MANNY!"%str(errCode)
840
841 class MweFtpConnection:
842 def __init__(self):
843 self.userName = "eborges"
844 self.hostName = "disftp.mwe.com"
845 self.userPassword = "rever78"
846 self.connection = ftplib.FTP_TLS(self.hostName)
847 self.connection.login(self.userName,self.userPassword)
848 self.connection.prot_p()
849
850 def TestPath(self,path):
851 startDir = self.connection.pwd()
852 try:
853 self.connection.cwd(path)
854 sucess = True
855 except:
856 sucess = False
857 self.connection.cwd(startDir)
858 return sucess
859
860 def CreateNewPath(self,path):
861 self.connection.mkd(path)
862
863 def CopyToDis(self,absSourcePathAndFile,targetDir):
864 startDir = self.connection.pwd()
865 fileName = os.path.split(absSourcePathAndFile)[1]
866 self.connection.cwd(targetDir)
867 activePackage = open(absSourcePathAndFile,'rb')
868 self.connection.storbinary("STOR %s"%fileName,activePackage)
869 activePackage.close()
870 self.connection.cwd(startDir)
871
872 def CloseConnection(self):
873 self.connection.close()