Please note that the CVS and issue trackers have moved to GitHub. These Trac pages are no longer kept up-to-date.

root/seattle/trunk/deploymentscripts/log_maintenance.py@5637

Revision 2810, 2.4 KB (checked in by konp, 10 years ago)

Fixed high cpu usage, added summary tool, a number of other fixes and improvements as well. Note: blackbox node keys have not been added yet.

Line 
1"""
2<Program Name>
3  log_maintenance.py
4
5<Started>
6  Aug 2009
7
8<Author>
9  n2k8000@u.washington.edu
10  Konstantin Pik
11
12<Purpose>
13  Script provides methods that'll summarize all files in a directory.
14
15<Usage>
16  Script is used to run manually on files that have not been summarized.
17 
18"""
19
20import deploy_html
21import deploy_helper
22import os
23import sys
24
25# this file will crawl log directories and import the latest summary tools
26
27
28def summarize_file(file_path):
29  """
30  <Purpose>
31    Summarizes a file given a file path, and writes it back to the same file.
32
33  <Arguments>
34    file_path:
35      The path to the file relative to this file where the file you
36      want to be summarized resides.
37
38  <Exceptions>
39    None.
40
41  <Side Effects>
42    None.
43
44  <Returns>
45    None.
46  """
47 
48  try:
49    # read in the whole file
50    file_handle = open(file_path, 'r')
51    file_content = deploy_html.read_whole_file(file_handle)
52    file_handle.close()
53   
54    # grab the contents
55    final_content = deploy_helper.summarize_all_blocks(file_content)
56   
57    # write the file contents again only if it changed.
58    if final_content != file_content:
59      # remake the file.
60      file_handle = open(file_path, 'w+')
61      file_handle.write(final_content)
62      file_handle.close()
63   
64    print "Summarized "+file_path
65  except Exception, e:
66    print e
67
68
69
70def summarize_dir(directory):
71  """
72  <Purpose>
73    Summarizes all the files in a directory, and all files within that directory.
74   
75  <Arguments>
76    directory:
77      the directory to summarize ( and all child directories as well)
78
79  <Exceptions>
80    None.
81
82  <Side Effects>
83    None.
84
85  <Returns>
86    None.
87  """
88 
89  if os.path.isdir(directory):
90    for each_dir in os.listdir(directory):
91      if os.path.isdir(directory+'/'+each_dir):
92        # it's a directory! now summarize each file
93        for each_file in os.listdir(directory+'/'+each_dir):
94          if os.path.isfile(directory+'/'+each_dir+'/'+each_file):
95            # summarize the file!
96            summarize_file(directory+'/'+each_dir+'/'+each_file)
97
98
99
100def main():
101  # entry point into the program.  If there is an argument
102  # then we clean out deploy.logs, and if there isn't an argument
103  # then we clean out the detailed_logs directory.
104  if len(sys.argv) == 2:
105    # clean up deploy_logs directory
106    summarize_dir('deploy.logs')
107  else:
108    summarize_dir('detailed_logs')
109   
110
111if __name__ == '__main__':
112  main()
Note: See TracBrowser for help on using the browser.