Esempio n. 1
0
 def __init__(self, package_path, report_path):
     self.report_path = report_path
     if not os.path.exists(report_path):
         os.makedirs(report_path)
     self.package_path = package_path
     self.name = os.path.basename(package_path)
     self.package_sender_email = ''
     files = ['detailed.log', 'error.log', 'summarized.txt']
     self.report_files = [report_path + '/' + self.name + '_' + f for f in files]
     log_filename, err_filename, summary_filename = self.report_files
     self.report = Report(log_filename, err_filename, summary_filename, 0, False)
     self.report_files_to_send = [summary_filename, err_filename]
     self.identify_files()
Esempio n. 2
0
class Package:
    def __init__(self, package_path, report_path):
        self.report_path = report_path
        if not os.path.exists(report_path):
            os.makedirs(report_path)
        self.package_path = package_path
        self.name = os.path.basename(package_path)
        self.package_sender_email = ''
        files = ['detailed.log', 'error.log', 'summarized.txt']
        self.report_files = [report_path + '/' + self.name + '_' + f for f in files]
        log_filename, err_filename, summary_filename = self.report_files
        self.report = Report(log_filename, err_filename, summary_filename, 0, False)
        self.report_files_to_send = [summary_filename, err_filename]
        self.identify_files()
        
    def read_package_sender_email(self):
        if os.path.exists(self.package_path + '/email.txt'):
            f = open(self.package_path + '/email.txt', 'r')
            content = f.readlines()
            f.close()

            content = [item for item in content if item]
            self.package_sender_email = ','.join(content).replace('\n', '').replace('\r', '').replace(';', ',').replace('\xef\xbb\xbf', '').rstrip()

        return self.package_sender_email

    
    def fix_extensions(self):        
        for f in os.listdir(self.package_path):
            extension = f[f.rfind('.'):]
            if extension != extension.lower():
                new_f = f[0:len(f)-len(extension)] + f[len(f)-len(extension):].lower()
                new_name = self.package_path + '/' + new_f
                os.rename(self.package_path + '/' + f, new_name)
                if os.path.exists(new_name):
                    self.report.write('Fixed extension of ' + new_name, False, False, False)
                else:
                    self.report.write('Unable to fix extension of ' + new_name, True, False, False)

    def return_matching_files(self, startswith, extension = ''):
        #pattern = xml_name.replace('.xml', '-')
        def filename_matches(filename, startswith):
            return filename.startswith(startswith + '.') or filename.startswith(startswith + '-')
            
        startswith = startswith.replace('.fixed', '')
        if '/' in startswith:
            startswith = os.path.basename(startswith) 
        startswith = startswith[0:startswith.rfind('.')]

        if len(extension)>0 and extension[0:1] != '.':
            extension = '.' + extension 

        self.report.write('startswith=' + startswith)
        self.report.write('extension=' + extension)
        self.report.write('files in ' + self.package_path)
        self.report.write('\n'.join(os.listdir(self.package_path)))

        if len(startswith)>0 and len(extension)>0:
            filenames = [ filename for filename in os.listdir(self.package_path) if filename_matches(filename, startswith) and filename.endswith(extension) ]
        elif len(startswith) == 0 and len(extension) == 0:
            filenames = os.listdir(self.package_path)
        elif len(extension)> 0 :
            filenames = [ filename for filename in os.listdir(self.package_path) if filename.endswith(extension) ]
        elif len(startswith) > 0:
            filenames = [ filename for filename in os.listdir(self.package_path) if filename_matches(filename, startswith) ]
        self.report.write(','.join(filenames))
        return filenames



    def identify_files(self):
        self.fix_extensions()
        
        self.package_files = os.listdir(self.package_path)        
        self.package_pdf_files = self.return_matching_files('', '.pdf')
        self.package_xml_files = self.return_matching_files('', '.xml')

        unmatched_pdf = [ pdf for pdf in self.package_pdf_files if not pdf.replace('.pdf', '.xml') in self.package_xml_files ]

        self.report.write('XML Files: ' + str(len(self.package_xml_files)), True)
        self.report.write('PDF Files: ' + str(len(self.package_pdf_files)), True)

        if len(self.package_xml_files) == 0:
            self.report.write('All the files in the package: ' + '\n' + '\n'.join(self.package_files), True, True, False)

        if len(unmatched_pdf) > 0:
            self.report.write('PDF files which there is no corresponding XML file: ' + '\n' + '\n'.join(unmatched_pdf), True, True, False)

        self.report.write('XML Files: \n' + '\n'.join(sorted(self.package_xml_files)), True)
        
    
    def check_pdf_file(self, xml_filename):
        pdf_filename = xml_filename.replace('.xml', '.pdf')
        if not os.path.exists(pdf_filename):
            self.report.write(' ! WARNING: Expected ' + os.path.basename(pdf_filename), True, True)
Esempio n. 3
0
        err_filename = config.parameters['ERROR_FILENAME']
        summary_filename = config.parameters['SUMMARY_REPORT']

        debug_depth = config.parameters['DEBUG_DEPTH']
        display_on_screen = config.parameters['DISPLAY_MESSAGES_ON_SCREEN']

        now = datetime.now().isoformat()[11:16].replace(':', '-')
        report_path = config.parameters['REPORT_PATH'] + '/' + now

        if not os.path.exists(report_path):
            os.makedirs(report_path)

        files = [log_filename, err_filename, summary_filename]

        log_filename, err_filename, summary_filename = [report_path + '/gerapadrao-' + f for f in files]
        report = Report(log_filename, err_filename, summary_filename, int(debug_depth), (display_on_screen == 'yes'))

        proc_title_db = config.parameters['PROC_DB_TITLE_FILENAME']
        proc_issue_db = config.parameters['PROC_DB_ISSUE_FILENAME']

        if not os.path.exists(os.path.dirname(proc_title_db)):
            os.makedirs(os.path.dirname(proc_title_db))

        if not os.path.exists(os.path.dirname(proc_issue_db)):
            os.makedirs(os.path.dirname(proc_issue_db))

        cisis = CISIS(config.parameters['CISIS_PATH'])
        email_service = EmailService('', config.parameter('SENDER_EMAIL'), 'localhost', config.parameter('IS_AVAILABLE_EMAIL_SERVICE') == 'yes')
        report_sender_config = ReportSenderConfiguration(config.parameter('BCC_EMAIL'), config.parameter('FLAG_SEND_EMAIL_TO_XML_PROVIDER') == 'yes', config.parameter('ALERT_FORWARD'), config.parameter('FLAG_ATTACH_REPORTS'))
        report_sender = ReportSender(email_service, report_sender_config)
        template = EmailMessageTemplate(config.parameter('EMAIL_SUBJECT_PREFIX_GERAPADRAO'), config.parameter('EMAIL_TEXT_GERAPADRAO'))
Esempio n. 4
0
class Package:
    def __init__(self, package_path, report_path):
        
        self.report_path = report_path
        if not os.path.exists(report_path):
            os.makedirs(report_path)

        self.package_path = package_path
        self.name = os.path.basename(package_path)
        
        self.package_sender_email = ''
        

        files = ['detailed.log', 'error.log', 'summarized.txt'] 
        self.report_files = [ report_path + '/' +  self.name + '_' + f for f in files ]
        log_filename, err_filename, summary_filename = self.report_files
        self.report = Report(log_filename, err_filename, summary_filename, 0, False) 
        self.report_files_to_send = [ summary_filename, err_filename ]
        
        
    def read_package_sender_email(self):
        if os.path.exists(self.package_path + '/email.txt'):
            f = open(self.package_path + '/email.txt', 'r')
            self.package_sender_email = f.read()
            self.package_sender_email = self.package_sender_email.replace(';', ',')
            f.close()
        return self.package_sender_email

    
    def fix_extensions(self):        
        for f in os.listdir(self.package_path):
            extension = f[f.rfind('.'):]
            if extension != extension.lower():
                new_f = f[0:len(f)-len(extension)] + f[len(f)-len(extension):].lower()
                new_name = self.package_path + '/' + new_f
                os.rename(self.package_path + '/' + f, new_name)
                if os.path.exists(new_name):
                    self.report.write('Fixed extension of ' + new_name, False, False, False)
                else:
                    self.report.write('Unable to fix extension of ' + new_name, True, False, False)

    def return_matching_files(self, startswith, extension = ''):
        #pattern = xml_name.replace('.xml', '-')

        startswith = startswith.replace('.fixed', '')
        if '/' in startswith:
            startswith = os.path.basename(startswith) 
        startswith = startswith[0:startswith.rfind('.')]

        if len(extension)>0 and extension[0:1] != '.':
            extension = '.' + extension 

        self.report.write('startswith=' + startswith)
        self.report.write('extension=' + extension)
        self.report.write('files in ' + self.package_path)
        self.report.write('\n'.join(os.listdir(self.package_path)))

        if len(startswith)>0 and len(extension)>0:
            filenames = [ filename for filename in os.listdir(self.package_path) if filename.startswith(startswith) and filename.endswith(extension) ]
        elif len(startswith) == 0 and len(extension) == 0:
            filenames = os.listdir(self.package_path)
        elif len(extension)> 0 :
            filenames = [ filename for filename in os.listdir(self.package_path) if  filename.endswith(extension) ]
        elif len(startswith) > 0:
            filenames = [ filename for filename in os.listdir(self.package_path) if filename.startswith(startswith) ]
        self.report.write(','.join(filenames))
        return filenames
        # instancing reports
        log_filename = config.parameters['LOG_FILENAME']
        err_filename = config.parameters['ERROR_FILENAME']
        summary_filename = config.parameters['SUMMARY_REPORT']

        debug_depth = config.parameters['DEBUG_DEPTH']
        display_on_screen = config.parameters['DISPLAY_MESSAGES_ON_SCREEN']

        report_path = config.parameters['REPORT_PATH'] + '/' + return_path_based_on_date()
        if not os.path.exists(report_path):
            os.makedirs(report_path)
    
        files = [ log_filename, err_filename, summary_filename]
    
        log_filename, err_filename, summary_filename = [ report_path + '/' + f for f in files ]
        report = Report(log_filename, err_filename, summary_filename, int(debug_depth), (display_on_screen == 'yes')) 
    
        proc_title_db = config.parameters['PROC_DB_TITLE_FILENAME']
        proc_issue_db = config.parameters['PROC_DB_ISSUE_FILENAME']

        if not os.path.exists(os.path.dirname(proc_title_db)):
            os.makedirs(os.path.dirname(proc_title_db ))
            
        if not os.path.exists(os.path.dirname(proc_issue_db)):
            os.makedirs(os.path.dirname(proc_issue_db ))
                

        cisis = CISIS(config.parameters['CISIS_PATH'])

        tracker = Tracker(config.parameter('GERAPADRAO_TRACKER_PATH'), config.parameter('GERAPADRAO_TRACKER_NAME'))