示例#1
0
    def clean_sourcefile(self):
        """
        Make sure the sourcefile exists and that it's an xls file, and that the name indicates two streetnames.
        """        
        sourcefile_name = self.cleaned_data['sourcefile'].name
        
        # if not os.path.isabs(sourcefile_name):
        #     raise forms.ValidationError("Sourcefile must be an absolute path to an excel file.  Invalid value: %s" % sourcefile_name)
        
       
        if sourcefile_name[-4:].lower() != ".xls" and sourcefile_name[-5:].lower() != ".xlsx":
            raise forms.ValidationError("Sourcefile must be have a .xls|.xlsx suffix.  Invalid value: %s" % sourcefile_name)
        
        # set streetnames
        self.cleaned_data['streetnames'] = CountsWorkbookParser.parseFilename(sourcefile_name)

        if len(self.cleaned_data['streetnames']) not in [2,3]:
            raise forms.ValidationError("Sourcefile name should be of the format streetname1_streetname2.xls or streetname_fromstreetname.tostreetname.xls.  Invalid value: %s" % sourcefile_name)
        
        return self.cleaned_data['sourcefile']
示例#2
0
    def clean_sourcefile(self):
        """
        Make sure the sourcefile exists and that it's an xls file, and that the name indicates two streetnames.
        """
        sourcefile_name = self.cleaned_data["sourcefile"].name

        # if not os.path.isabs(sourcefile_name):
        #     raise forms.ValidationError("Sourcefile must be an absolute path to an excel file.  Invalid value: %s" % sourcefile_name)

        if sourcefile_name[-4:].lower() != ".xls" and sourcefile_name[-5:].lower() != ".xlsx":
            raise forms.ValidationError(
                "Sourcefile must be have a .xls|.xlsx suffix.  Invalid value: %s" % sourcefile_name
            )

        # set streetnames
        self.cleaned_data["streetnames"] = CountsWorkbookParser.parseFilename(sourcefile_name)

        if len(self.cleaned_data["streetnames"]) not in [2, 3]:
            raise forms.ValidationError(
                "Sourcefile name should be of the format streetname1_streetname2.xls or streetname_fromstreetname.tostreetname.xls.  Invalid value: %s"
                % sourcefile_name
            )

        return self.cleaned_data["sourcefile"]
    
    consolehandler = logging.StreamHandler()
    consolehandler.setLevel(logging.DEBUG)
    consolehandler.setFormatter(logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s'))
    logger.addHandler(consolehandler)        
    
    debugFilename = "updateCountsWorkbooks.DEBUG.log"
    debugloghandler = logging.StreamHandler(open(debugFilename, 'w'))
    debugloghandler.setLevel(logging.DEBUG)
    debugloghandler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%Y-%m-%d %H:%M'))
    logger.addHandler(debugloghandler)

    files_to_process = sorted(os.listdir(DIR_TOPROCESS))
    
    for file in files_to_process:
        if file[-4:] !='.xls':
            print "File suffix is not .xls: %s -- skipping" % file[-4:]
            continue
        
        logger.info("")
        logger.info("Processing file %s" % file)

        streetlist = CountsWorkbookParser.parseFilename(file)
        
        # mainline
        if len(streetlist) in [2,3]:
            updateWorkbook(logger, DIR_TOPROCESS, DIR_OLDV10, DIR_NEWV11, file, "MAINLINE" if len(streetlist)==3 else "TURNS")
        else:
            logger.info("  Invalid workbook name %s" % file)
            
示例#4
0
    consolehandler.setFormatter(
        logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s'))
    logger.addHandler(consolehandler)

    debugFilename = "updateCountsWorkbooks.DEBUG.log"
    debugloghandler = logging.StreamHandler(open(debugFilename, 'w'))
    debugloghandler.setLevel(logging.DEBUG)
    debugloghandler.setFormatter(
        logging.Formatter('%(asctime)s %(levelname)s %(message)s',
                          '%Y-%m-%d %H:%M'))
    logger.addHandler(debugloghandler)

    files_to_process = sorted(os.listdir(DIR_TOPROCESS))

    for file in files_to_process:
        if file[-4:] != '.xls':
            print "File suffix is not .xls: %s -- skipping" % file[-4:]
            continue

        logger.info("")
        logger.info("Processing file %s" % file)

        streetlist = CountsWorkbookParser.parseFilename(file)

        # mainline
        if len(streetlist) in [2, 3]:
            updateWorkbook(logger, DIR_TOPROCESS, DIR_OLDV10, DIR_NEWV11, file,
                           "MAINLINE" if len(streetlist) == 3 else "TURNS")
        else:
            logger.info("  Invalid workbook name %s" % file)