def connect():
    client = ArangoClient(
        host=os.getenv('ARANGO_HOST'),
        port=os.getenv('ARANGO_PORT'),
        username=os.getenv('ARANGO_USER'),
        password=os.getenv('ARANGO_ROOT_PASSWORD'),
    )
    client.databases()
Beispiel #2
0
def arangoConnect(getIp, getPort, getUser, getPass, getNewdb):
    client = ArangoClient(protocol='http',
                          host=getIp,
                          port=getPort,
                          username=getUser,
                          password=getPass,
                          enable_logging=True)
    print("connected?")
    try:
        client.create_database(getNewdb)
        print('Created new db, ' + getNewdb)
        return (client.databases())
    except:
        print('failed to create new DB, ' + getNewdb)

    print(client.databases())
    return (client.databases())
Beispiel #3
0
#/usr/bin/env python3

from arango import ArangoClient
from datetime import tzinfo

from db_credentials import db_credentials

# Configure your ArangoDB server connection here
conn = ArangoClient(protocol=db_credentials['protocol'],
                    host=db_credentials['host'],
                    port=db_credentials['port'],
                    username=db_credentials['username'],
                    password=db_credentials['password'])

dbName = 'polBotCheck'
if dbName not in conn.databases():
    db = conn.create_database(dbName)
db = conn.db(dbName)


def getCollection(collectionName, edge=False):
    collectionNames = map(lambda c: c['name'], db.collections())
    if collectionName not in collectionNames:
        db.create_collection(collectionName, edge=edge)
    return db.collection(collectionName)


def getVertexCollection(graph, collectionName):
    collectionNames = map(lambda c: c['name'], db.collections())
    if collectionName not in collectionNames:
        graph.create_vertex_collection(collectionName)
def test_empty_arango(app, arango: ArangoClient):
    assert app.config.get('ARANGO_DB') not in arango.databases()
def test_migration(app, arango: ArangoClient):
    assert app.config.get('ARANGO_DB') in arango.databases()
Beispiel #6
0
class ArangoHandler(object):
    def __init__(self,
                 database,
                 protocol='http',
                 host='localhost',
                 port=8529,
                 username='******',
                 password=''):
        self.BATCH_LIMIT = 10000
        self.client = ArangoClient(protocol=protocol,
                                   host=host,
                                   port=port,
                                   username=username,
                                   password=password,
                                   enable_logging=True)
        self.db = self.retrieve_db(database)

    def retrieve_db(self, database_name):
        if self.has_db(database_name):
            return self.client.database(database_name)
        else:
            return self.client.create_database(database_name)

    def has_db(self, database_name):
        database_list = self.client.databases()
        if database_name in database_list:
            return True
        else:
            return False

    def insert_jsonl(self, collection_name, lines):
        collection = self.retrieve_collection(collection_name)

        commit = []
        lines = lines.split(b"\n")
        count = 0
        for line in lines:
            try:
                dictionary = ujson.loads(line)
            except Exception as error:
                logging.error(u"Error loading jsonl: {}".format(line))
                line = lines.pop()
                continue

            key_hash = hashlib.md5(line)
            dictionary['_key'] = key_hash.hexdigest()
            commit.append(dictionary)

            if len(commit) == self.BATCH_LIMIT:
                collection.import_bulk(commit,
                                       sync=True,
                                       on_duplicate="ignore")
                commit[:] = []

            count += 1

        if len(commit) > 0:
            collection.import_bulk(commit, sync=True, on_duplicate="ignore")

        logging.info(u"Records Processed: {}".format(count))

    def retrieve_collection(self, collection_name):
        if self.has_collection(collection_name):
            return self.db.collection(collection_name)
        else:
            return self.db.create_collection(collection_name)

    def has_collection(self, collection_name):
        collection_list = self.db.collections()
        for collection_info in collection_list:
            if collection_info['name'] == collection_name:
                return True
        return False
        if len(header_line) > 1:
            # each header line
            for line in header_line:
                val = line.split(r'=')
                # add the id as the key
                if val[0] == 'ID':
                    # set the
                    elm_ref = structure[val[1]] = {}
                else:
                    # for this id, add the values
                    elm_ref[val[0].lower()] = re.sub('^\"|\"?$', '', val[1])


if len(sys.argv) > 2:
    # Initialize the client for ArangoDB
    client = ArangoClient(protocol='http',
                          host='localhost',
                          port=8529,
                          username='******',
                          password='******',
                          enable_logging=True)
    if sys.argv[2] not in client.databases():
        client.create_database(sys.argv[2])
    # select the database
    db = client.db(sys.argv[2])
    # create our obj
    loader = hapmap_load()
    # start loading variants
    loader.load_vcf(sys.argv[1], db)
else:
    print "please specify a VCF and arango database"