ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Lib.py
Revision: 462
Committed: Tue Oct 1 19:53:25 2013 UTC (12 years, 5 months ago) by nino.borges
Content type: text/x-python
File size: 50750 byte(s)
Log Message:
Added support in view edit for the case path style setting and added a popup that forces you to choose if you select an IDS system. Also added ability to have the MCP create the data folders.

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