Changeset 2137


Ignore:
Timestamp:
07/04/2008 09:02:45 (4 years ago)
Author:
cbkm
Message:

Update bbreporter.py to newer version (oops!) and add GPLv3 LICENSE file.

Location:
box/trunk/contrib/bbreporter
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/contrib/bbreporter/bbreporter.py

    r2136 r2137  
    55# Copyright: (C) 2007 Three A IT Limited 
    66# Author: Kenny Millington <kenny.millington@3ait.co.uk> 
    7 # Version: $Id: bbreporter.py,v 1.15 2007-11-14 11:13:38 kenny Exp $ 
    87# 
    98# Credit: This script is based on the ideas of BoxReport.pl by Matt Brown of  
     
    8483                 log_file="/var/log/syslog", email_to=None,  
    8584                 email_from="report@boxbackup", rotate=False,  
    86                  verbose=False, stats=False): 
     85                 verbose=False, stats=False, sort=False): 
    8786         
    8887        # Config options 
     
    9493        self.verbose_report = verbose 
    9594        self.usage_stats = stats 
     95        self.sort_files = sort 
    9696         
    9797        # Regex's 
     
    107107        # Reset report data to default values 
    108108        self.hostname = "" 
    109         self.patched_files = {} 
    110         self.synced_files = {} 
    111         self.uploaded_files = {} 
     109        self.patched_files = [] 
     110        self.synced_files = [] 
     111        self.uploaded_files = [] 
    112112        self.warnings = [] 
    113113        self.errors = [] 
     
    198198    def _parse_syslog(self): 
    199199        lfh = open(self.log_file) 
     200         
     201        patched_files = {} 
     202        uploaded_files = {} 
     203        synced_files = {} 
    200204         
    201205        for line in lfh: 
     
    234238                    # We found a patch event, add the file to the patched_files. 
    235239                    if data[5] == "Uploading patch to file": 
    236                         self.patched_files[data[6]] = "" 
     240                        patched_files[data[6]] = "" 
    237241 
    238242                    # We found an upload event, add to uploaded files. 
    239243                    elif data[5] == "Uploading complete file": 
    240                         self.uploaded_files[data[6]] = "" 
     244                        uploaded_files[data[6]] = "" 
    241245                     
    242246                    # We found another upload event. 
    243247                    elif data[5] == "Uploaded file": 
    244                         self.uploaded_files[data[6]] = "" 
     248                        uploaded_files[data[6]] = "" 
    245249                     
    246250                    # We found a sync event, add the file to the synced_files. 
    247251                    elif data[5] == "Synchronised file": 
    248                         self.synced_files[data[6]] = "" 
     252                        synced_files[data[6]] = "" 
    249253                 
    250254                    # We found a warning, add the warning to the warnings. 
     
    255259                    elif data[5] == "ERROR": 
    256260                        self.errors.append(data[6]) 
    257  
     261         
     262         
     263        self.patched_files = patched_files.keys() 
     264        self.uploaded_files = uploaded_files.keys() 
     265        self.synced_files = synced_files.keys() 
     266         
     267        # There's no point running the sort functions if we're not going 
     268        # to display the resultant lists. 
     269        if self.sort_files and self.verbose_report: 
     270            self.patched_files.sort() 
     271            self.uploaded_files.sort() 
     272             
     273         
    258274        lfh.close() 
    259275     
     
    317333                report.append("Uploaded Files (%d)" % len(self.uploaded_files)) 
    318334                report.append("---------------------") 
    319                 for file in self.uploaded_files.keys(): 
     335                for file in self.uploaded_files: 
    320336                    report.append(file) 
    321337                report.append("") 
     
    325341                report.append("Patched Files (%d)" % len(self.patched_files)) 
    326342                report.append("---------------------") 
    327                 for file in self.patched_files.keys(): 
     343                for file in self.patched_files: 
    328344                    report.append(file) 
    329345                report.append("") 
     
    447463    verbose = False  
    448464    stats = False 
     465    sort = False 
    449466 
    450467    # Parse the options 
    451468    try: 
    452         opts, args = getopt.getopt(sys.argv[1:], "srvhl:c:t:f:",  
     469        opts, args = getopt.getopt(sys.argv[1:], "osrvhl:c:t:f:",  
    453470                        ["help", "logfile=", "configfile=","email-to=",  
    454                          "email-from=","rotate","verbose","stats"]) 
     471                         "email-from=","rotate","verbose","stats","sort"]) 
    455472    except getopt.GetoptError: 
    456473        usage() 
     
    472489        elif(opt in ("--stats", "-s")): 
    473490            stats = True 
     491        elif(opt in ("--sort", "-o")): 
     492            sort = True 
    474493        elif(opt in ("--help", "-h")): 
    475494            usage() 
     
    478497    # Run the reporter 
    479498    bbr = BoxBackupReporter(configfile, logfile, email_to, email_from,  
    480                             rotate, verbose, stats) 
     499                            rotate, verbose, stats, sort) 
    481500    try: 
    482501        bbr.run() 
Note: See TracChangeset for help on using the changeset viewer.