Beispiel #1
0
def init():
    config_name = _Config(current_app.config['CONFIG_FILE'])
    config = _Config(current_app.config['CONFIG_FOLDER'] + '/config_' + config_name.cfg['PROFILE']['id'] + '.ini')
    log = _Log(config.cfg['GLOBAL']['logfile'])
    db_type = config.cfg['DATABASE']['databasetype']
    db = _Database(log, db_type, conn=get_db().conn)
    xml = _Xml(config, db)
    file_name = config.cfg['GLOBAL']['tmppath'] + 'tmp'
    locale = _Locale(config)
    files = _Files(
        file_name,
        int(config.cfg['GLOBAL']['resolution']),
        int(config.cfg['GLOBAL']['compressionquality']),
        xml,
        log,
        config.cfg['GLOBAL']['convertpdftotiff'],
        locale,
        config
    )
    ocr = _PyTesseract(locale.localeOCR, log, config)
    splitter = _Splitter(config, db, locale)
    ws = ''

    if config.cfg['GED']['enabled'] == 'True':
        ws = _WebServices(
            config.cfg['GED']['host'],
            config.cfg['GED']['user'],
            config.cfg['GED']['password'],
            log,
            config
        )

    return db, config, locale, ws, xml, files, ocr, splitter
Beispiel #2
0
def init():
    configName = _Config(current_app.config['CONFIG_FILE'])
    Config = _Config(current_app.config['CONFIG_FOLDER'] + '/config_' +
                     configName.cfg['PROFILE']['id'] + '.ini')
    Log = _Log(Config.cfg['GLOBAL']['logfile'])
    db = _Database(Log, None, get_db())
    Locale = _Locale(Config)
    configFile = current_app.config[
        'CONFIG_FOLDER'] + '/config_' + configName.cfg['PROFILE']['id'] + '.ini'

    return db, Config, Locale, configName, configFile
Beispiel #3
0
def launch(args):
    start = time.time()

    # Init all the necessary classes
    config_name = _Config(args['config'])
    cfg_name = config_name.cfg['PROFILE'][
        'cfgpath'] + '/config_' + config_name.cfg['PROFILE']['id'] + '.ini'

    if not os.path.exists(cfg_name):
        sys.exit('Config file couldn\'t be found')

    config = _Config(config_name.cfg['PROFILE']['cfgpath'] + '/config_' +
                     config_name.cfg['PROFILE']['id'] + '.ini')

    tmp_folder = tempfile.mkdtemp(
        dir=config.cfg['SPLITTER']['tmpbatchpath']) + '/'
    file_name = tempfile.NamedTemporaryFile(dir=tmp_folder).name

    locale = _Locale(config)
    log = _Log(config.cfg['GLOBAL']['logfile'])
    ocr = _PyTesseract(locale.localeOCR, log, config)
    db_type = config.cfg['DATABASE']['databasetype']
    db_user = config.cfg['DATABASE']['postgresuser']
    db_pwd = config.cfg['DATABASE']['postgrespassword']
    db_name = config.cfg['DATABASE']['postgresdatabase']
    db_host = config.cfg['DATABASE']['postgreshost']
    db_port = config.cfg['DATABASE']['postgresport']
    database = _Database(log, db_type, db_name, db_user, db_pwd, db_host,
                         db_port, config.cfg['DATABASE']['databasefile'])
    splitter = _Splitter(config, database, locale)
    xml = _Xml(config, database)
    files = _Files(file_name, int(config.cfg['GLOBAL']['resolution']),
                   int(config.cfg['GLOBAL']['compressionquality']), xml, log,
                   config.cfg['GLOBAL']['convertpdftotiff'], locale)

    # Connect to database
    database.connect()

    # Start process
    if args['file'] is not None:
        path = args['file']
        if check_file(files, path, config, log) is not False:
            # Process the file and send it to Maarch
            OCForInvoices_splitter.process(path, log, splitter, files, ocr,
                                           tmp_folder, config)

    # Close database
    database.conn.close()

    end = time.time()
    log.info('Process end after ' + timer(start, end) + '')
Beispiel #4
0
def init():
    # Init all the necessary classes
    config_name = _Config(current_app.config['CONFIG_FILE'])
    config = _Config(config_name.cfg['PROFILE']['cfgpath'] + '/config_' +
                     config_name.cfg['PROFILE']['id'] + '.ini')
    db_type = config.cfg['DATABASE']['databasetype']
    db_name = config.cfg['DATABASE']['postgresdatabase']
    db_user = config.cfg['DATABASE']['postgresuser']
    db_pwd = config.cfg['DATABASE']['postgrespassword']
    db_host = config.cfg['DATABASE']['postgreshost']
    db_port = config.cfg['DATABASE']['postgresport']

    log = _Log(config.cfg['GLOBAL']['logfile'])
    db = _Database(log, db_type, db_name, db_user, db_pwd, db_host, db_port,
                   config.cfg['DATABASE']['databasefile'])

    return {'db': db, 'type': db_type, 'log': log}
Beispiel #5
0
def init():
    # Init all the necessary classes
    configName = _Config(current_app.config['CONFIG_FILE'])
    Config = _Config(configName.cfg['PROFILE']['cfgpath'] + '/config_' +
                     configName.cfg['PROFILE']['id'] + '.ini')
    dbType = Config.cfg['DATABASE']['databasetype']
    dbName = Config.cfg['DATABASE']['postgresdatabase']
    dbUser = Config.cfg['DATABASE']['postgresuser']
    dbPwd = Config.cfg['DATABASE']['postgrespassword']
    dbHost = Config.cfg['DATABASE']['postgreshost']
    dbPort = Config.cfg['DATABASE']['postgresport']

    Log = _Log(Config.cfg['GLOBAL']['logfile'])
    db = _Database(Log, dbType, dbName, dbUser, dbPwd, dbHost, dbPort,
                   Config.cfg['DATABASE']['databasefile'])

    return {'db': db, 'type': dbType, 'log': Log}
Beispiel #6
0
def init():
    configName = _Config(current_app.config['CONFIG_FILE'])
    Cfg = _Config(current_app.config['CONFIG_FOLDER'] + '/config_' +
                  configName.cfg['PROFILE']['id'] + '.ini')
    Log = _Log(Cfg.cfg['GLOBAL']['logfile'])
    dbType = Cfg.cfg['DATABASE']['databasetype']
    db = _Database(Log, dbType, conn=get_db().conn)
    Xml = _Xml(Cfg, db)
    fileName = Cfg.cfg['GLOBAL']['tmppath'] + 'tmp'
    Files = _Files(fileName, int(Cfg.cfg['GLOBAL']['resolution']),
                   int(Cfg.cfg['GLOBAL']['compressionquality']), Xml, Log,
                   Cfg.cfg['GLOBAL']['convertpdftotiff'])
    Locale = _Locale(Cfg)
    Ocr = _PyTesseract(Locale.localeOCR, Log, Cfg)
    splitter = _Splitter(Cfg, db, Locale)
    ws = ''

    if Cfg.cfg['GED']['enabled'] == 'True':
        ws = _WebServices(Cfg.cfg['GED']['host'], Cfg.cfg['GED']['user'],
                          Cfg.cfg['GED']['password'], Log, Cfg)

    return db, Cfg, Locale, ws, Xml, Files, Ocr, splitter
    if not os.path.exists(args['config']):
        sys.exit('Config file couldn\'t be found')

    configName = _Config(args['config'])
    Config = _Config(configName.cfg['PROFILE']['cfgpath'] + '/config_' +
                     configName.cfg['PROFILE']['id'] + '.ini')
    Log = _Log(Config.cfg['GLOBAL']['logfile'])
    Spreadsheet = _Spreadsheet(Log, Config)
    dbType = Config.cfg['DATABASE']['databasetype']
    dbUser = Config.cfg['DATABASE']['postgresuser']
    dbPwd = Config.cfg['DATABASE']['postgrespassword']
    dbname = Config.cfg['DATABASE']['postgresdatabase']
    dbhost = Config.cfg['DATABASE']['postgreshost']
    dbport = Config.cfg['DATABASE']['postgresport']
    Database = _Database(Log, dbType, dbname, dbUser, dbPwd, dbhost, dbport,
                         Config.cfg['DATABASE']['databasefile'])

    # Load the referencials into array before inject it into database
    # Read MIME type from file

    #TODO
    # Add the MIME type into a config file
    mime = mimetypes.guess_type(Spreadsheet.referencialSuppplierSpreadsheet)[0]
    if mime in [
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    ]:
        contentSupplierSheet = Spreadsheet.read_excel_sheet(
            Spreadsheet.referencialSuppplierSpreadsheet)
    else:
        contentSupplierSheet = Spreadsheet.read_ods_sheet(
            Spreadsheet.referencialSuppplierSpreadsheet)
def launch(args):
    start = time.time()

    # Init all the necessary classes
    configName = _Config(args['config'])
    cfgName = configName.cfg['PROFILE'][
        'cfgpath'] + '/config_' + configName.cfg['PROFILE']['id'] + '.ini'

    if not os.path.exists(cfgName):
        sys.exit('Config file couldn\'t be found')

    Config = _Config(configName.cfg['PROFILE']['cfgpath'] + '/config_' +
                     configName.cfg['PROFILE']['id'] + '.ini')

    tmpFolder = tempfile.mkdtemp(
        dir=Config.cfg['SPLITTER']['tmpbatchpath']) + '/'
    fileName = tempfile.NamedTemporaryFile(dir=tmpFolder).name

    Locale = _Locale(Config)
    Log = _Log(Config.cfg['GLOBAL']['logfile'])
    Ocr = _PyTesseract(Locale.localeOCR, Log, Config)
    dbType = Config.cfg['DATABASE']['databasetype']
    dbUser = Config.cfg['DATABASE']['postgresuser']
    dbPwd = Config.cfg['DATABASE']['postgrespassword']
    dbName = Config.cfg['DATABASE']['postgresdatabase']
    dbHost = Config.cfg['DATABASE']['postgreshost']
    dbPort = Config.cfg['DATABASE']['postgresport']
    Database = _Database(Log, dbType, dbName, dbUser, dbPwd, dbHost, dbPort,
                         Config.cfg['DATABASE']['databasefile'])
    Splitter = _Splitter(Config, Database, Locale)
    Xml = _Xml(Config, Database)
    Files = _Files(fileName, int(Config.cfg['GLOBAL']['resolution']),
                   int(Config.cfg['GLOBAL']['compressionquality']), Xml, Log,
                   Config.cfg['GLOBAL']['convertpdftotiff'])

    # Connect to database
    Database.connect()

    # Start process
    if args['file'] is not None:
        path = args['file']
        if check_file(Files, path, Config, Log) is not False:
            # Process the file and send it to Maarch
            OCForInvoices_splitter.process(path, Log, Splitter, Files, Ocr,
                                           tmpFolder)

    elif args['path'] is not None:
        path = args['path']
        for file in os.listdir(path):
            if check_file(Files, path + file, Config, Log) is not False:
                # Create the Queue to store files
                q = queue.Queue()

                # Find file in the wanted folder (default or exported pdf after qrcode separation)
                q = OCForInvoices_splitter.process(path + file, Log, Splitter,
                                                   Files, Ocr, tmpFolder)

                if not q:
                    continue

    # Empty the tmp dir to avoid residual file
    # recursive_delete(tmpFolder, Log)
    # Close database
    Database.conn.close()

    end = time.time()
    Log.info('Process end after ' + timer(start, end) + '')
def launch(args):
    start = time.time()

    # Init all the necessary classes
    config_name = _Config(args['config'])
    config = config_name.cfg['PROFILE'][
        'cfgpath'] + '/config_' + config_name.cfg['PROFILE']['id'] + '.ini'

    if not os.path.exists(config):
        sys.exit('config file couldn\'t be found')

    config = _Config(config)
    locale = _Locale(config)

    if args.get('isMail') is not None and args['isMail'] is True:
        log = _Log((args['log']))
        log.info('Process attachment n°' + args['cpt'] + '/' +
                 args['nb_of_attachments'])
    else:
        log = _Log(config.cfg['GLOBAL']['logfile'])

    ocr = _PyTesseract(locale.localeOCR, log, config)
    db_type = config.cfg['DATABASE']['databasetype']
    db_user = config.cfg['DATABASE']['postgresuser']
    db_pwd = config.cfg['DATABASE']['postgrespassword']
    db_name = config.cfg['DATABASE']['postgresdatabase']
    db_host = config.cfg['DATABASE']['postgreshost']
    db_port = config.cfg['DATABASE']['postgresport']
    database = _Database(log, db_type, db_name, db_user, db_pwd, db_host,
                         db_port, config.cfg['DATABASE']['databasefile'])
    xml = _Xml(config, database)

    tmp_folder = tempfile.mkdtemp(dir=config.cfg['GLOBAL']['tmppath'])
    filename = tempfile.NamedTemporaryFile(dir=tmp_folder).name

    separator_qr = SeparatorQR(log, config, tmp_folder)

    if args.get('isMail') is None or args.get('isMail') is False:
        separator_qr.enabled = str2bool(config.cfg['SEPARATORQR']['enabled'])

    files = _Files(filename, int(config.cfg['GLOBAL']['resolution']),
                   int(config.cfg['GLOBAL']['compressionquality']), xml, log,
                   config.cfg['GLOBAL']['convertpdftotiff'], locale, config)

    if config.cfg['GED']['enabled'] != 'False':
        webservices = _WebServices(config.cfg['GED']['host'],
                                   config.cfg['GED']['user'],
                                   config.cfg['GED']['password'], log, config)
    else:
        webservices = False

    # Connect to database
    database.connect()

    # Start process
    if 'path' in args and args['path'] is not None:
        path = args['path']
        if separator_qr.enabled:
            for fileToSep in os.listdir(path):
                if check_file(files, path + fileToSep, config, log):
                    separator_qr.run(path + fileToSep)
            path = separator_qr.output_dir_pdfa if str2bool(
                separator_qr.convert_to_pdfa
            ) is True else separator_qr.output_dir

        for file in os.listdir(path):
            if check_file(
                    files, path + file, config,
                    log) is not False and not os.path.isfile(path + file +
                                                             '.lock'):
                os.mknod(path + file + '.lock')
                log.info('Lock file created : ' + path + file + '.lock')

                # Find file in the wanted folder (default or exported pdf after qrcode separation)
                typo = ''
                # if config.cfg['AI-CLASSIFICATION']['enabled'] == 'True':
                #     typo = get_typo(config, path + file, log)

                OCForInvoices_process.process(path + file, log, config, files,
                                              ocr, locale, database,
                                              webservices, typo)

                try:
                    os.remove(path + file + '.lock')
                    log.info('Lock file removed : ' + path + file + '.lock')
                except FileNotFoundError:
                    pass

    elif 'file' in args and args['file'] is not None:
        path = args['file']
        typo = ''
        if separator_qr.enabled:
            if check_file(files, path, config, log) is not False:
                separator_qr.run(path)
            path = separator_qr.output_dir_pdfa if str2bool(
                separator_qr.convert_to_pdfa
            ) is True else separator_qr.output_dir

            for file in os.listdir(path):
                # if config.cfg['AI-CLASSIFICATION']['enabled'] == 'True':
                #     typo = get_typo(config, path + file, log)

                if check_file(files, path + file, config, log) is not False:
                    # Process the file and send it to Maarch
                    OCForInvoices_process.process(path + file, log, config,
                                                  files, ocr, locale, database,
                                                  webservices, typo)
        elif config.cfg['SEPARATE-BY-DOCUMENT']['enabled'] == 'True':
            list_of_files = separator_qr.split_document_every_two_pages(path)
            for file in list_of_files:
                # if config.cfg['AI-CLASSIFICATION']['enabled'] == 'True':
                #     typo = get_typo(config, file, log)

                if check_file(files, file, config, log) is not False:
                    # Process the file and send it to Maarch
                    OCForInvoices_process.process(file, log, config, files,
                                                  ocr, locale, database,
                                                  webservices, typo)
            os.remove(path)
        else:
            # if config.cfg['AI-CLASSIFICATION']['enabled'] == 'True':
            #     typo = get_typo(config, path, log)

            if check_file(files, path, config, log) is not False:
                # Process the file and send it to Maarch
                OCForInvoices_process.process(path, log, config, files, ocr,
                                              locale, database, webservices,
                                              typo)

    # Empty the tmp dir to avoid residual file
    recursive_delete(
        [tmp_folder, separator_qr.output_dir, separator_qr.output_dir_pdfa],
        log)

    # Close database
    database.conn.close()

    end = time.time()
    log.info('Process end after ' + timer(start, end) + '')
    if not os.path.exists(args['config']):
        sys.exit('Config file couldn\'t be found')

    config_name = _Config(args['config'])
    config = _Config(config_name.cfg['PROFILE']['cfgpath'] + '/config_' +
                     config_name.cfg['PROFILE']['id'] + '.ini')
    log = _Log(config.cfg['GLOBAL']['logfile'])
    spreadsheet = _Spreadsheet(log, config)
    db_type = config.cfg['DATABASE']['databasetype']
    db_user = config.cfg['DATABASE']['postgresuser']
    db_pwd = config.cfg['DATABASE']['postgrespassword']
    db_name = config.cfg['DATABASE']['postgresdatabase']
    db_host = config.cfg['DATABASE']['postgreshost']
    db_port = config.cfg['DATABASE']['postgresport']
    database = _Database(log, db_type, db_name, db_user, db_pwd, db_host,
                         db_port, config.cfg['DATABASE']['databasefile'])

    file = spreadsheet.referencialSuppplierSpreadsheet
    if args['file']:
        if os.path.exists(args['file']):
            file = args['file']

    mime = mimetypes.guess_type(file)[0]
    contentSupplierSheet = None
    existingMimeType = False
    if mime in [
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    ]:
        contentSupplierSheet = spreadsheet.read_excel_sheet(file)
        existingMimeType = True
    elif mime in ['application/vnd.oasis.opendocument.spreadsheet']: