ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Commence_results.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 3250 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 ## Commence_results.py
2     ## This program will give you the results on the various commence updates by connecting to their logfiles
3     ## kept on the Y drives containing who ran the program successfully.
4     ## EBorges
5     ## 06.19.03
6    
7     from lgflcntr import getoffice
8    
9     def WhosLeft(ranList, resultsList, masterContents):
10     """(ranList, resultsList, masterContents) Compares the first argument (ranList) which is a list of
11     users that have run the program to a master list of all users who have Commence (masterContents)
12     3rd argument. It then writes to the second argument (resultsList) with a list of who os left."""
13     masterDict = {}
14     for line in masterContents:
15     userName = line.split(',')[0]
16     realName = line.split(',')[1:]
17     masterDict[userName] = realName
18     for x in ranList:
19     x = x.split(':')[0]
20     x = x.rstrip()
21     if masterDict.has_key(x):
22     del masterDict[x]
23     remaining = len(masterDict)
24     w = open(resultsList, 'w')
25     for key in masterDict.keys():
26     #w.write(str(key) + ',' + str(masterDict[key]))
27     w.write(key + ' : ')
28     w.writelines(masterDict[key])
29     w.close()
30     return remaining
31    
32     def ReturnResults(peopleList):
33     """(peopleList) Print results to stdout in a readable format. Argument should be a list."""
34     print "And here are those people:"
35     print "--------------------------"
36     for person in peopleList:
37     print person
38    
39     def WriteResults(peopleList):
40     """(peopleList) Prints results to a file on the executer's U drive, selected by user. Argument
41     should be a list"""
42     file = raw_input("I will put the file on your U drive. Select file name: ")
43     w = open('U:\\' + file, 'w')
44     w.writelines(peopleList)
45     w.close()
46     print "%s was written to your U drive. "%file
47    
48     if __name__ == '__main__':
49     masterList = r'y:\commence\updates\commence user list.TXT'
50     rm = open(masterList,'r')
51     masterContents = rm.readlines()
52     rm.close()
53     resultsList = r'u:\commence_Users_left.txt'
54     clear = open(resultsList,'w')
55     clear.close()
56     ranItList = []
57     appservers = getoffice()
58     for x in appservers:
59     ranItFile = '//%s/app/log_files/Completed_Commence_agent_fixes.log'%x
60     try:
61     r = open(ranItFile,'r')
62     contents = r.readlines()
63     r.close()
64     for line in contents:
65     ranItList.append(line)
66     except:
67     print "No one in %s has run the program"% x
68     # --Compare the results.--
69     print "%d people have run this program successfully.\n"% len(ranItList)
70     print "There are %d people that still need to run the program"% WhosLeft(ranItList,resultsList,masterContents)
71     listPeople = raw_input("Would you like me to list the people who HAVE run the program? (y/n) ")
72     if listPeople == 'y':
73     ReturnResults(ranItList)
74     writePeople = raw_input('Would you prefer to have this list in a file? (y/n) ')
75     if writePeople == 'y':
76     WriteResults(ranItList)
77     print "\nOk I'm done. A list of people that are LEFT to run the program has been written to %s"% resultsList
78     exit = raw_input("\n<--Press any-key to exit-->\n")
79