コード例 #1
0
def main(channeldict, *args, **kargs):
    output_dir = botslib.join(channeldict['path'])
    botslib.dirshouldbethere(output_dir)
    url = 'http://{}:{}/api/shipping_invoice/'.format(
        channeldict['host'], channeldict['port'])
    custom_headers = {
        'Authorization': 'Token {}'.format(channeldict['parameters']),
        'Content-Type': 'application/json'
    }
    invoices = requests.get(url, headers=custom_headers)

    for invoice in invoices.json():
        filename = botslib.join(output_dir, str(
            transform.unique('Shipping Invoice Get')) + '.json')
        output_file = open(filename, 'wb')
        output_file.write(json.dumps({'Invoice': invoice}))
        output_file.close()

        # Mark invoice as processed
        url = 'http://{}:{}/api/shipping_invoice/{}/processed/'.format(
            channeldict['host'], channeldict['port'], invoice['invoice_id'])
        process_invoice = requests.post(url, headers=custom_headers)
        process_invoice.raise_for_status()

        # Return the filename
        yield filename
コード例 #2
0
def run_ok_tests():
    for test in listofoktests:
        #delete result file (always one result file, fixed name)
        try:
            os.remove(
                botslib.join(botssys, 'outfile/unittesterrors/result.txt'))
        except:
            pass
        #write correct testfile
        shutil.copyfile(
            botslib.join(botssys, 'infile/unittesterrors/input',
                         test['infile']),
            botslib.join(botssys, 'infile/unittesterrors', test['infile']))
        subprocess.call(newcommand)  #run bots
        comparedicts(
            {
                'status': 0,
                'lastreceived': 1,
                'lasterror': 0,
                'lastdone': 1,
                'lastok': 0,
                'lastopen': 0,
                'send': 1,
                'processerrors': 0
            }, getreportlastrun())  #check report
        if not filecmp.cmp(
                botslib.join(botssys, 'infile/unittesterrors/compare',
                             test['infile']),
                botslib.join(botssys, 'outfile/unittesterrors/result.txt')):
            raise Exception('output translation not as expected; test "%s"' %
                            (test['infile']))
コード例 #3
0
ファイル: unittesterrors.py プロジェクト: avkameth/bots.v220
def run_ok_tests():
    for test in listofoktests:
        #delete result file (always one result file, fixed name)
        try:
            os.remove(botslib.join(botssys,'outfile/unittesterrors/result.txt'))
        except:
            pass
        #write correct testfile
        shutil.copyfile(botslib.join(botssys,'infile/unittesterrors/input',test['infile']),botslib.join(botssys,'infile/unittesterrors',test['infile']))
        subprocess.call(newcommand)     #run bots
        comparedicts({'status':0,'lastreceived':1,'lasterror':0,'lastdone':1,'lastok':0,'lastopen':0,'send':1,'processerrors':0},getreportlastrun()) #check report
        if not filecmp.cmp(botslib.join(botssys,'infile/unittesterrors/compare',test['infile']),botslib.join(botssys,'outfile/unittesterrors/result.txt')):
            raise Exception('output translation not as expected; test "%s"'%(test['infile']))
コード例 #4
0
ファイル: unittesterrors.py プロジェクト: avkameth/bots.v220
def run_error_tests():
    for test in listoferrortests:
        #write correct testfile
        shutil.copyfile(botslib.join(botssys,'infile/unittesterrors/input',test['infile']),botslib.join(botssys,'infile/unittesterrors',test['infile']))
        subprocess.call(newcommand)     #run bots
        comparedicts({'status':1,'lastreceived':1,'lasterror':1,'lastdone':0,'lastok':0,'lastopen':0,'send':0,'processerrors':0},getreportlastrun()) #check report
        errortext = geterrorlastrun()
        if removeWS(test['errortext']) != removeWS(errortext):     #check error
            raise Exception('another errortekst; test "%s"'%(test['infile']))
コード例 #5
0
def run_error_tests():
    for test in listoferrortests:
        #write correct testfile
        shutil.copyfile(
            botslib.join(botssys, 'infile/unittesterrors/input',
                         test['infile']),
            botslib.join(botssys, 'infile/unittesterrors', test['infile']))
        subprocess.call(newcommand)  #run bots
        comparedicts(
            {
                'status': 1,
                'lastreceived': 1,
                'lasterror': 1,
                'lastdone': 0,
                'lastok': 0,
                'lastopen': 0,
                'send': 0,
                'processerrors': 0
            }, getreportlastrun())  #check report
        errortext = geterrorlastrun()
        if removeWS(test['errortext']) != removeWS(errortext):  #check error
            raise Exception('another errortekst; test "%s"' % (test['infile']))
コード例 #6
0
ファイル: botsupdatedb.py プロジェクト: jbellomy/bots.v210
def start(configdir='config'):
    #********command line arguments**************************
    for arg in sys.argv[1:]:
        if not arg:
            continue
        if arg.startswith('-c'):
            configdir = arg[2:]
            if not configdir:
                print 'Indicated Bots should use specific .ini file but no file name was given.'
                sys.exit(1)
        elif arg in ["?", "/?"] or arg.startswith('-'):
            showusage()
            sys.exit(0)
        else:  #pick up names of routes to run
            showusage()
    #**************initialise configuration file******************************
    try:
        botsinit.generalinit(configdir)
        botslib.settimeout(
            botsglobal.ini.getint('settings', 'globaltimeout', 10))  #
    except:
        traceback.print_exc()
        print 'Error in reading/initializing ini-file.'
        sys.exit(1)
    #**************initialise logging******************************
    try:
        botsinit.initenginelogging()
    except:
        traceback.print_exc()
        print 'Error in initialising logging system.'
        sys.exit(1)
    else:
        atexit.register(logging.shutdown)
    botsglobal.logger.info('Python version: "%s".', sys.version)
    botsglobal.logger.info('Bots configuration file: "%s".', botsinifile)
    botsglobal.logger.info(
        'Bots database configuration file: "%s".',
        botslib.join(
            'config',
            os.path.basename(
                botsglobal.ini.get('directories', 'tgconfig', 'botstg.cfg'))))
    #**************connect to database**********************************
    try:
        botslib.connect()
    except:
        traceback.print_exc()
        print 'Error connecting to database.'
        sys.exit(1)
    else:
        atexit.register(botsglobal.db.close)

    try:
        cursor = botsglobal.db.cursor()
        cursor.execute(
            '''ALTER TABLE routes ADD COLUMN  notindefaultrun BOOLEAN''', None)
        cursor.execute(
            '''ALTER TABLE channel ADD COLUMN  archivepath VARCHAR(256)''',
            None)
        cursor.execute('''ALTER TABLE partner ADD COLUMN  mail VARCHAR(256)''',
                       None)
        cursor.execute('''ALTER TABLE partner ADD COLUMN  cc VARCHAR(256)''',
                       None)
        cursor.execute('''ALTER TABLE chanpar ADD COLUMN  cc VARCHAR(256)''',
                       None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmasked BOOLEAN''',
                       None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmed BOOLEAN''',
                       None)
        cursor.execute(
            '''ALTER TABLE ta ADD COLUMN  confirmtype VARCHAR(35) DEFAULT '' ''',
            None)
        cursor.execute(
            '''ALTER TABLE ta ADD COLUMN  confirmidta INTEGER DEFAULT 0''',
            None)
        cursor.execute(
            '''ALTER TABLE ta ADD COLUMN  envelope VARCHAR(35) DEFAULT '' ''',
            None)
        cursor.execute(
            '''ALTER TABLE ta ADD COLUMN  botskey VARCHAR(35) DEFAULT '' ''',
            None)
        cursor.execute(
            '''ALTER TABLE ta ADD COLUMN  cc VARCHAR(512) DEFAULT '' ''', None)
        if botsglobal.dbinfo.drivername == 'mysql':
            cursor.execute('''ALTER TABLE ta MODIFY errortext VARCHAR(2048)''',
                           None)
        elif botsglobal.dbinfo.drivername == 'postgres':
            cursor.execute(
                '''ALTER TABLE ta ALTER COLUMN errortext type VARCHAR(2048)''',
                None)
        #else: #sqlite does not allow modifying existing field, but does not check lengths either so this works.
        cursor.execute(
            '''CREATE TABLE confirmrule (
                            id INTEGER PRIMARY KEY,
                            active BOOLEAN,
                            confirmtype VARCHAR(35),
                            ruletype VARCHAR(35),
                            negativerule BOOLEAN,
                            frompartner VARCHAR(35),
                            topartner VARCHAR(35),
                            idchannel VARCHAR(35),
                            idroute VARCHAR(35),
                            editype VARCHAR(35),
                            messagetype VARCHAR(35) )
                            ''', None)
    except:
        traceback.print_exc()
        print 'Error while updating the database. Database is not updated.'
        botsglobal.db.rollback()
        sys.exit(1)

    botsglobal.db.commit()
    cursor.close()
    print 'Database is updated.'
    sys.exit(0)
コード例 #7
0
ファイル: botsupdatedb.py プロジェクト: avkameth/bots.v210
def start(configdir = 'config'):
    #********command line arguments**************************
    for arg in sys.argv[1:]:
        if not arg:
            continue
        if arg.startswith('-c'):
            configdir = arg[2:]
            if not configdir:
                print 'Indicated Bots should use specific .ini file but no file name was given.'
                sys.exit(1)
        elif arg in ["?", "/?"] or arg.startswith('-'):
            showusage()
            sys.exit(0)
        else:   #pick up names of routes to run
            showusage()
    #**************initialise configuration file******************************
    try:
        botsinit.generalinit(configdir)
        botslib.settimeout(botsglobal.ini.getint('settings','globaltimeout',10))    #
    except:
        traceback.print_exc()
        print 'Error in reading/initializing ini-file.'
        sys.exit(1)
    #**************initialise logging******************************
    try:
        botsinit.initenginelogging()
    except:
        traceback.print_exc()
        print 'Error in initialising logging system.'
        sys.exit(1)
    else:
        atexit.register(logging.shutdown)
    botsglobal.logger.info('Python version: "%s".',sys.version)
    botsglobal.logger.info('Bots configuration file: "%s".',botsinifile)
    botsglobal.logger.info('Bots database configuration file: "%s".',botslib.join('config',os.path.basename(botsglobal.ini.get('directories','tgconfig','botstg.cfg'))))
    #**************connect to database**********************************
    try:
        botslib.connect() 
    except:
        traceback.print_exc()
        print 'Error connecting to database.'
        sys.exit(1)
    else:
        atexit.register(botsglobal.db.close)


    try:
        cursor = botsglobal.db.cursor()
        cursor.execute('''ALTER TABLE routes ADD COLUMN  notindefaultrun BOOLEAN''',None)
        cursor.execute('''ALTER TABLE channel ADD COLUMN  archivepath VARCHAR(256)''',None)
        cursor.execute('''ALTER TABLE partner ADD COLUMN  mail VARCHAR(256)''',None)
        cursor.execute('''ALTER TABLE partner ADD COLUMN  cc VARCHAR(256)''',None)
        cursor.execute('''ALTER TABLE chanpar ADD COLUMN  cc VARCHAR(256)''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmasked BOOLEAN''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmed BOOLEAN''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmtype VARCHAR(35) DEFAULT '' ''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  confirmidta INTEGER DEFAULT 0''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  envelope VARCHAR(35) DEFAULT '' ''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  botskey VARCHAR(35) DEFAULT '' ''',None)
        cursor.execute('''ALTER TABLE ta ADD COLUMN  cc VARCHAR(512) DEFAULT '' ''',None)
        if botsglobal.dbinfo.drivername == 'mysql':
            cursor.execute('''ALTER TABLE ta MODIFY errortext VARCHAR(2048)''',None)
        elif botsglobal.dbinfo.drivername == 'postgres':
            cursor.execute('''ALTER TABLE ta ALTER COLUMN errortext type VARCHAR(2048)''',None)
        #else: #sqlite does not allow modifying existing field, but does not check lengths either so this works.
        cursor.execute('''CREATE TABLE confirmrule (
                            id INTEGER PRIMARY KEY,
                            active BOOLEAN,
                            confirmtype VARCHAR(35),
                            ruletype VARCHAR(35),
                            negativerule BOOLEAN,
                            frompartner VARCHAR(35),
                            topartner VARCHAR(35),
                            idchannel VARCHAR(35),
                            idroute VARCHAR(35),
                            editype VARCHAR(35),
                            messagetype VARCHAR(35) )
                            ''',None)
    except:
        traceback.print_exc()
        print 'Error while updating the database. Database is not updated.'
        botsglobal.db.rollback()
        sys.exit(1)
        
    botsglobal.db.commit()
    cursor.close()
    print 'Database is updated.'
    sys.exit(0)