Esempio n. 1
0
async def startup():
    # TODO use retry or something
    for _ in range(3):
        try:
            redis = await aioredis.create_redis_pool('/tmp/redis.sock')
        except aioredis.errors.ReplyError as e:
            await asyncio.sleep(10)
        else:
            break
    else:
        raise e
    connect(redis)
Esempio n. 2
0
 def on_buttonTestConnection_clicked(self):
     dbUri = forms._.dbUri
     import orm
     ADAPTERS = dict(sqlite= orm.SqliteAdapter, mysql= orm.MysqlAdapter) # available adapters
     try: # 'sqlite://../mtc.sqlite'
         db = orm.connect(dbUri, ADAPTERS)
         if db is None:
             raise orm.ConnectionError('Could not find suitable DB adapter for the protocol specified.')
         db.execute('SELECT 1;')
     except Exception as exc:
         QtGui.QMessageBox.warning(self, 'Failure', '<b>Connection failure</b><br>%s\n%s' % (dbUri, exc))
     else:
         QtGui.QMessageBox.information(self, 'Success', '<b>Connection success</b><br>%s' % dbUri)
Esempio n. 3
0
    return json.loads(response)


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print('USAGE: server.py path/to/config.xml')
        sys.exit(1)

    # parse the XML configuration
    config_xml = config.parse_config(sys.argv[1])
    clients = config.parse_clients(config_xml)
    smtp_cfg = config.parse_smtp(config_xml)

    # connect to the DB
    db = orm.connect(config.parse_db(config_xml))

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    for client in clients:
        system = db.query(orm.System).filter_by(name=client['ip']).first()
        if not system:
            system = orm.System(name=client['ip'])
            db.add(system)
            db.commit()

        last_event_record_id = 0
        if client['platform'] == 'Windows':
            last_event = db.query(
                orm.WinEventLog).filter_by(system_id=system.id).order_by(
Esempio n. 4
0
 def setUpClass(cls):
     # CREATE USER test WITH PASSWORD 'test';
     # CREATE DATABASE test OWNER test;
     cls.db = orm.connect("postgresql://*****:*****@localhost/test")
Esempio n. 5
0
class Persons(orm.Model):
    last_name = orm.CharField(maxLength=100)
    first_name = orm.CharField(maxLength=100)
    middle_name = orm.CharField(maxLength=100)
    phone_prefix = orm.IntegerField(maxDigits=3)  # phone prefix code of the location
    phone_number = orm.IntegerField(maxDigits=10)
    location = orm.RecordField(Locations)
    street = orm.RecordField(Streets)

    def checkNames(self):
        """An item function, like in Django"""
        pass


db = orm.connect('sqlite://papp/databases/mtc.sqlite')

#print('\nRegions table fields:')
#for field in Regions:
#    print(' ', field)

# implicit join: get all locations and the regions they are part of
#pprint(dbAdapter.select([], (Regions.id == Locations.region_id), orderBy=[Regions.region_type_name, -Regions.region_name], limitBy=(0, 10)))

# explicit join
#pprint(dbAdapter.execute('SELECT persons.*, locations.* FROM persons JOIN locations ON (locations.id = persons.location_id) WHERE (persons.phone_number = 763533) LIMIT 10 OFFSET 0;').fetchall())
#print(dbAdapter.getLastQuery(), '\n')

rows = db.select(Persons.last_name, Persons.first_name, Locations.location_name,
                 Regions.region_name,
                 from_=[Persons, LeftJoin(Locations, Locations.id == Persons.location),
Esempio n. 6
0
class CatalogModel(orm.Model):
    deleted = orm.BooleanField()


class Streets(CatalogModel):
    street_name = orm.CharField(maxLength=50)


##################################################################
test = ('sqlite', 'mysql', 'postgresql')[0]
if test == 'sqlite':
    fd, filePath = tempfile.mkstemp(suffix='.sqlite')
    os.close(fd)
    #    db = orm.connect('sqlite://' + filePath)
    db = orm.connect('sqlite://:memory:')
elif test == 'mysql':
    db = orm.connect('mysql://root@localhost/test')
elif test == 'postgresql':
    db = orm.connect('postgresql://postgres@localhost/test')

db.execute('DROP TABLE IF EXISTS authors')
db.execute('DROP TABLE IF EXISTS books')

query = db.getCreateTableQuery(Authors)
print('\nGetting the CREATE TABLE query for table Authors:\n', query)
for _query in query.split('\n\n'):
    db.execute(_query)

query = db.getCreateTableQuery(Books)
print('\nGetting the CREATE TABLE query for table Books:\n', query)
Esempio n. 7
0
 def test_invalid_connection_string_raises(self):
     with self.assertRaises(Exception):
         orm.connect('')
Esempio n. 8
0
 def test_valid_connection_doesnt_raise(self):
     # note creates in-memory DB
     orm.connect('sqlite://')