Beispiel #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-o', '--org')
    parser.add_argument('-p', '--products')
    parser.add_argument('-s', '--statement')
    parser.add_argument('-t', '--transactions')
    args = parser.parse_args()

    database = db.connect()
    with pytransact.context.ReadonlyContext(database):
        try:
            org, = blm.accounting.Org._query(id=args.org).run()
        except ValueError:
            name = args.org.decode('utf8')
            # Many orgs may have the same name - oh, well, just pick one
            org = blm.accounting.Org._query(name=name).run()[0]

    if args.products:
        print('Importing iZettle products from %s' % args.products)
        import_products_file(org.id[0], args.products)

    if args.statement:
        print('Parsing statement: %s' % args.statement)
        parse_statement_xlsx(args.statement)

    if args.transactions:
        print('Importing iZettle transactions from %s' % args.transactions)
        import_transactions(org.id[0], args.transactions)
Beispiel #2
0
def main(out=sys.stdout):
    parser = argparse.ArgumentParser()
    parser.add_argument('--test-sign', action='store_true')

    args = parser.parse_args()

    signer_host = config.config.get('bankgiro', 'signer_host')
    me = socket.getfqdn()
    if args.test_sign:
        if me == signer_host and os.path.exists('/dev/bgsigner'):
            raise SystemExit('Can not test sign on signer host.')
    else:
        if me != signer_host:
            if sys.stderr.isatty():
                raise SystemExit('Must run in in test mode on non signer host.')
            else:
                raise SystemExit(1)
        if not os.path.exists('/dev/bgsigner'):
            raise SystemExit('/dev/bgsigner missing on signer host.')

    database = db.connect()
    createOrders(database)

    upload_host = config.config.get('bankgiro', 'upload_host')
    if me == upload_host:
        sendOrders(database, out=out)
Beispiel #3
0
def main():
    database = db.connect()
    interested = 'bootstrap-%s' % ObjectId()
    with CommitContext(database) as ctx:
        ctx.set_read_preference(pymongo.ReadPreference.PRIMARY)
        op = CallBlm('accounting', 'bootstrap', [])
        ctx.runCommit([op], interested=interested)
    result, error = wait_for_commit(database, interested)
    if error:
        raise error
Beispiel #4
0
def import_products(org, products):
    import blm.members
    database = db.connect()
    interested = 'izettle-import-%s' % bson.objectid.ObjectId()
    with pytransact.commit.CommitContext(database) as ctx:
        ctx.setMayChange(True)
        op = CallBlm('members', 'import_izettle_products', [[org], [products]])
        ctx.runCommit([op], interested=interested)
        result, errors = pytransact.commit.wait_for_commit(
            database, interested=interested)
        assert not errors, errors
Beispiel #5
0
def import_transactions(org, transactionsfilename):
    with open(transactionsfilename) as f:
        filedata = f.read().encode('base64')
    import blm.members
    database = db.connect()
    interested = 'izettle-import-%s' % bson.objectid.ObjectId()
    with pytransact.commit.CommitContext(database) as ctx:
        ctx.setMayChange(True)
        op = CallBlm('members', 'import_izettle_payments', [[org], [filedata]])
        ctx.runCommit([op], interested=interested)
        result, errors = pytransact.commit.wait_for_commit(
            database, interested=interested)
        assert not errors, errors
Beispiel #6
0
def main():
    database = db.connect()
    database.local.foo.find().count()  # force connection to initialize
    with ReadonlyContext(database):
        users = len(blm.accounting.User._query().run())
        activeusers = len(
            blm.accounting.User._query(lastAccess=Greater(time.time() -
                                                          24 * 60 * 60)).run())
        orgs = len(blm.accounting.Org._query().run())
        suborgs = len(
            blm.accounting.Org._query(subscriptionLevel='subscriber').run())

        log.info(
            'users: %(users)s active: %(activeusers)s orgs: %(orgs)s subscribers: %(suborgs)s',
            locals())
Beispiel #7
0
def import_products_file(org, filename):
    import blm.members
    with open(filename) as f:
        products = f.read().encode('base64')

    database = db.connect()
    interested = 'izettle-import-%s' % bson.objectid.ObjectId()
    with pytransact.commit.CommitContext(database) as ctx:
        ctx.setMayChange(True)
        op = CallBlm('members', 'import_izettle_products_file',
                     [[org], [products]])
        ctx.runCommit([op], interested=interested)
        result, errors = pytransact.commit.wait_for_commit(
            database, interested=interested)
        assert not errors, errors
Beispiel #8
0
def is_up():
    database = db.connect(
        connectTimeoutMS=1000,
        serverSelectionTimeoutMS=2000,
    )
    try:
        # Force connection to db by running query, as MongoClient
        # connects lazily
        database.foo.find().next()
    except StopIteration:
        pass
    conn = database.client
    if conn.primary is None:
        raise RuntimeError('No primary')
    if {conn.primary} | conn.secondaries | conn.arbiters != conn.nodes:
        raise RuntimeError(
            'Confusing node information. Primary: %s, '
            'secondaries: %s, arbiters: %s, nodes: %s' %
            (conn.primary, conn.secondaries, conn.arbiters, conn.nodes))
    print(':'.join(map(str, conn.primary)))
Beispiel #9
0
    b'#TRANS': ('T* L N [D] [T] [N] [T]', Parser.transaction),
    b'#RTRANS': ('T* L N [D] [T] [N] [T]', Parser.added_transaction),
    b'#BTRANS': ('T* L N [D] [T] [N] [T]', Parser.deleted_transaction),
    b'#KSUMMA': ('[T]', Parser.no_op),

    # Non standard Open End extensions
    b'#AVSLUTAT': ('', Parser.closed),  # the accounting year is closed
    b'#SERIE': ('T [T]', Parser.series),
    b'#MOMSKOD': ('T T', Parser.vatcode),
}

if __name__ == '__main__':
    import bson, locale, sys
    locale.setlocale(locale.LC_CTYPE, '')
    enc = locale.getpreferredencoding()
    database = db.connect()
    for fname in sys.argv[1:]:
        fname = fname.decode(enc)
        sys.stdout.write('Importing %s ' % fname)
        sys.stdout.flush()
        interested = bson.objectid.ObjectId()
        with commit.CommitContext(database) as ctx:
            ctx.setMayChange(True)
            importer = SIEImporter()
            importer.parseFile(fname)
            accountingId = importer.accounting.id[0]
            ctx.runCommit([], interested=interested)
        result, errors = commit.wait_for_commit(database,
                                                interested=interested)
        assert not errors
        sys.stdout.write('done, created: %s\n' % accountingId)
Beispiel #10
0
def main():
    database = db.connect()
    if pytransact.utils.is_localhost_primary(database.client):
        process(database)
Beispiel #11
0
    def test_connect(self, monkeypatch):
        database1 = db.connect()
        database2 = db.connect()

        assert database1 is database2