ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 469
Committed: Wed Oct 9 20:07:24 2013 UTC (12 years, 5 months ago) by nino.borges
Content type: text/x-python
File size: 52890 byte(s)
Log Message:
Updated to build 003

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