ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MCP/MCP_Case_Scan.py
Revision: 364
Committed: Tue May 28 13:43:06 2013 UTC (12 years, 10 months ago) by nino.borges
Content type: text/x-python
File size: 9481 byte(s)
Log Message:
updating case scan to grab full folders and support davita.

File Contents

# User Rev Content
1 ninoborges 8 """
2    
3     MCP_Case_Scan.py
4    
5     Created by
6     Emanuel Borges
7     04.08.2009
8    
9     This program will run in batch mode and automatically add the SendToIpro menu item to any databases
10     that it finds, which do not have the menu item. This might be changed to add other things to the
11     menu too, in the future.
12    
13     NOTE: This needs to be changed so that it actually checks the line. There have been instances where
14     the line is there but it's not complete.
15    
16    
17     UPDATE: on 7-31-2010 changed name from Concordance_MenuItem_Adder.py to MCP_Case_Scan.py
18     to reflect the fact that it's now a part of th MCP and to add functions.
19     """
20    
21     import ConfigParser,os,ConcordanceHelperTools,MCP_Lib
22    
23    
24    
25     def ProcessCasesMain(caseToProcess = 'ALL'):
26     responsibleCases,casesDir = MCP_Lib.GetCaseList()
27     responsibleCasesMatrix = {}
28     if caseToProcess == 'ALL':
29     pass
30     else:
31     responsibleCases = [caseToProcess]
32     for i in responsibleCases:
33     caseName,clientMatterNumber = i.split("_(")
34     clientMatterNumber = clientMatterNumber[:-1]
35     responsibleCasesMatrix[clientMatterNumber] = caseName
36     responsibleCLMList = responsibleCasesMatrix.keys()
37    
38 nino.borges 364 ## if the case is Davita, turn the davita flag on.
39     if '39323308' in responsibleCLMList:
40     davitaFlag = True
41    
42 ninoborges 8 for cliMatt in responsibleCLMList:
43     fullDatabaseList = []
44     print "-"*32
45     print
46     print "Now processing %s"% responsibleCasesMatrix[cliMatt]
47     #os.path.walk(ConcordanceHelperTools.ParseClientMatter(cliMatt), CheckForMenuItem, args)
48     for root, dirs, files in os.walk(ConcordanceHelperTools.ParseClientMatter(cliMatt)):
49     if os.path.split(root)[1] == "Match":
50     pass
51     else:
52     CheckForMenuItem(root, files)
53     databaseList = ConcordanceHelperTools.EnumerateConcordanceDatabases(root, files)
54     fullDatabaseList.extend(databaseList)
55 nino.borges 364 ## If this is davita, grab db names with folder path, grab contents of the cats and contents of global tag dbs.
56     for dbi in databaseList:
57     fullDatabaseMatrix[dbi] = root
58    
59 ninoborges 8 currentDatabaseList = []
60     databaseListFile = os.path.join(casesDir,responsibleCasesMatrix[cliMatt]+"_("+cliMatt+")","DatabaseList.txt")
61 nino.borges 364 databaseWithPathListFile = os.path.join(casesDir,responsibleCasesMatrix[cliMatt]+"_("+cliMatt+")","DatabaseListWithPaths.txt")
62 ninoborges 8 print "Checking the database list file..."
63     if os.path.isfile(databaseListFile):
64     currentDatabaseList = open(databaseListFile).readlines()
65     missingFiles = False
66     for db in fullDatabaseList:
67     if db+"\n" in currentDatabaseList:
68     pass
69     else:
70     missingFiles = True
71     if missingFiles:
72     print "Incomplete database list file found. Updating..."
73     outputFile = open(databaseListFile,'w')
74 nino.borges 364 outputFile2 = open(databaseWithPathListFile,'w')
75 ninoborges 8 for i in fullDatabaseList:
76     outputFile.write(i+"\n")
77 nino.borges 364 outputFile2.write(fullDatabaseMatrix[i]+"|"+i+"\n")
78 ninoborges 8 outputFile.close()
79 nino.borges 364 outputFile2.close()
80 ninoborges 8 print "Updating complete."
81     else:
82     print "All databases in list file accounted for."
83     else:
84     print "No database list file found, making a new one.."
85     outputFile = open(databaseListFile,'w')
86     for i in fullDatabaseList:
87     outputFile.write(i+"\n")
88     outputFile.close()
89     print "File created."
90    
91     def UpdateDatabaseList(dirName, filesInDir):
92     databaseList = ConcordanceHelperTools.EnumerateConcordanceDatabases(dirName, filesInDir)
93    
94     def CheckForMenuItem(dirName, filesInDir):
95     for file in filesInDir:
96     if os.path.isfile(os.path.join(dirName, file)):
97     if os.path.splitext(file)[1].upper() == '.DCB':
98     if os.path.splitext(file)[0][-6:].upper() == '-NOTES':
99     pass
100     elif os.path.splitext(file)[0][-9:].upper() == '-REDLINES':
101     pass
102     elif os.path.exists(os.path.join(dirName,os.path.splitext(file)[0] +'.ini')) == False:
103     print "There is no ini file for %s!!"%file
104     else:
105     iniFile = os.path.splitext(file)[0] +'.ini'
106     ## Check to see if it's already there
107     cp = ConfigParser.ConfigParser()
108     cp.read(os.path.join(dirName, iniFile))
109     ## I'm only checking for the entire section here, so this needs to
110     ## change, if you use it for more than this.
111     if cp.has_section('AddedMenuItems'):
112     if cp.get('AddedMenuItems','default') == "":
113     menuBool = True
114     else:
115     menuBool = False
116     if 'Find Attachments' in cp.get('AddedMenuItems','default'):
117     menuBool = False
118     else:
119     menuBool = True
120     else:
121     menuBool = True
122     if cp.has_section('Settings'):
123     settingsBool = False
124     else:
125     settingsBool = True
126     if menuBool or settingsBool:
127     print
128     print "Missing Menu item from %s. Adding..."%file
129     AddMenuItem(os.path.join(dirName, iniFile), menuBool, settingsBool)
130    
131     else:
132     print
133     print "Skipping %s"% file
134    
135    
136     def AddMenuItem(iniFile,menuBool, settingsBool):
137     #value = """default=Search(Send Query to IPRO,H:\cpl\DDEIQRY.CPL,-1)"""
138     cp = ConfigParser.ConfigParser()
139     cp.read(iniFile)
140     if menuBool:
141     if cp.has_section('AddedMenuItems'):
142     pass
143     else:
144     cp.add_section("AddedMenuItems")
145     cp.set('AddedMenuItems', "default", r"Search(Send Query to IPRO,H:\cpl\DDEIQRY.CPL,-1),Search(Find Attachments, H:\cpl\findattachments.cpl, -1)")
146     if settingsBool:
147     cp.add_section("Settings")
148     cp.set('Settings', "Viewer", r"L:\app\IPRO\i2kprem.exe")
149     cp.set('Settings', "ViewerCPL", r"H:\cpl\DDEIVIEW.CPL")
150     ## Back up the ini
151     try:
152     os.rename(iniFile,os.path.splitext(iniFile)[0] + "ini.BAK")
153     except:
154     os.remove(os.path.splitext(iniFile)[0] + "ini.BAK")
155     os.rename(iniFile,os.path.splitext(iniFile)[0] + "ini.BAK")
156    
157    
158     ## Add to the ini
159     outputFile = open(iniFile,'w')
160     cp.write(outputFile)
161     outputFile.close()
162     print
163     print "Added line to %s"% iniFile
164    
165     if __name__ == '__main__':
166     ProcessCasesMain('ALL')
167     #responsibleCases,casesDir = MCP_Lib.GetCaseList()
168     #responsibleCasesMatrix = {}
169     #for i in responsibleCases:
170     # caseName,clientMatterNumber = i.split("_(")
171     # clientMatterNumber = clientMatterNumber[:-1]
172     # responsibleCasesMatrix[clientMatterNumber] = caseName
173     #responsibleCLMList = responsibleCasesMatrix.keys()
174     #
175     #
176     #
177     #for cliMatt in responsibleCLMList:
178     # fullDatabaseList = []
179     # print "-"*32
180     # print
181     # print "Now processing %s"% responsibleCasesMatrix[cliMatt]
182     # #os.path.walk(ConcordanceHelperTools.ParseClientMatter(cliMatt), CheckForMenuItem, args)
183     # for root, dirs, files in os.walk(ConcordanceHelperTools.ParseClientMatter(cliMatt)):
184     # if os.path.split(root)[1] == "Match":
185     # pass
186     # else:
187     # CheckForMenuItem(root, files)
188     # databaseList = ConcordanceHelperTools.EnumerateConcordanceDatabases(root, files)
189     # fullDatabaseList.extend(databaseList)
190     # currentDatabaseList = []
191     # databaseListFile = os.path.join(casesDir,responsibleCasesMatrix[cliMatt]+"_("+cliMatt+")","DatabaseList.txt")
192     # print "Checking the database list file..."
193     # if os.path.isfile(databaseListFile):
194     # currentDatabaseList = open(databaseListFile).readlines()
195     # missingFiles = False
196     # for db in fullDatabaseList:
197     # if db+"\n" in currentDatabaseList:
198     # pass
199     # else:
200     # missingFiles = True
201     # if missingFiles:
202     # print "Incomplete database list file found. Updating..."
203     # outputFile = open(databaseListFile,'w')
204     # for i in fullDatabaseList:
205     # outputFile.write(i+"\n")
206     # outputFile.close()
207     # print "Updating complete."
208     # else:
209     # print "All databases in list file accounted for."
210     # else:
211     # print "No database list file found, making a new one.."
212     # outputFile = open(databaseListFile,'w')
213     # for i in fullDatabaseList:
214     # outputFile.write(i+"\n")
215     # outputFile.close()
216     # print "File created."
217     #