ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 460
Committed: Mon Sep 23 18:54:34 2013 UTC (12 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 48820 byte(s)
Log Message:
For some reason the mycases, activecases,officecases lists are no longer sorting by client matter. Changed to force the sort.

File Contents

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