예제 #1
0
def db_setup(HOST: str, USER: str, dbname: str, PASSW: str, PORT: str,
             keep: bool):
    """sets up database
    :param HOST: OGM Graph ref
    :param USER: OGM Graph ref
    :param dbname: OGM Graph ref
    :param PASSW: OGM Graph ref
    :param PORT: OGM Graph ref
    :param keep: boolean value to keep or destroy database
    """
    print('(connecting to db)')
    clear_database = ''
    if (not keep):
        clear_database = input(
            'Are you sure you want to delete the database? (Y/N)')

    if clear_database in ['Y', 'y', 'Yes', 'yes', 'YES']:
        print('(dropping database)')
        g = Graph(Config.from_url(dbname, USER, PASSW, initial_drop=True))
        g.create_all(Node.registry)
        g.create_all(Relationships.registry)
    else:
        print('(keeping database)')
        g = Graph(Config.from_url(dbname, USER, PASSW, initial_drop=False))
        SchemaNode = declarative_node()
        SchemaRelationship = declarative_relationship()
        classes_from_schema = g.build_mapping(SchemaNode,
                                              SchemaRelationship,
                                              auto_plural=True)
        g.include(classes_from_schema)

    g.client.command(
        "ALTER DATABASE DATETIMEFORMAT \"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\"")

    print('our db g', g)
    return g
예제 #2
0
        tmp.append(list(region))
    a['regions'] = tmp
    return a


# init db
# initial_drop = True

# test
# cx_db = 'localhost:8889/cx'
graph = Graph(Config.from_url(cx_db, 'root', 'root',
                              initial_drop=initial_drop))
# models.create_efficiently(graph, models.Node.registry)
# models.create_efficiently(graph, models.Relationship.registry)
if initial_drop:
    graph.create_all(models.Node.registry)
    graph.create_all(models.Relationship.registry)
else:
    graph.include(models.Node.registry)
    graph.include(models.Relationship.registry)

logging.basicConfig(level=logging.DEBUG,
                    stream=sys.stdout,
                    format='%(asctime)s %(name)s %(levelname)s %(message)s')
logger = logging.getLogger('cx')

logger.info('Start to Load Biological Data')

CX_Neuropils = ['PB', 'EB', 'NO', 'no', 'BU', 'bu', 'LAL', 'lal']

neuropil_name_to_node = {}
예제 #3
0
                "data": "version number"
            }
        ],
        "created": "2017-03-13T14:02:10.000Z",
        "modified": "2017-03-13T14:02:10.000Z",
        "labels": ["infrastructure"]
    }
    # with monkeytype.trace():

    config = Config(host="127.0.0.1", user="******", db_name="test_embedded", storage="plocal", cred="OrientPW",
                    port=2424, initial_drop=True)

    # graph = Graph(Config.from_url('localhost/g-test', 'root', 'root', initial_drop=True))
    # graph = Graph(Config.from_url('localhost/g-test', 'root', 'root'))
    graph = Graph(config)
    graph.create_all(Node.registry)
    print("create_all done for nodes")
    # print(result)
    graph.create_all(Relationships.registry)
    print("create_all done for Relationships")
    # print(result)
    # try:
    #     result = graph.assets.create(**asset)
    #     print("created an asset")
    #     print(result)
    #     print("Querying...")
    #     result = graph.assets.query(name=asset["name"]).one()
    #     print(dir(result))
    # except Exception as e:
    #     print('Exception:')
    #     print(e)
예제 #4
0
                        lpu0_pat_ports_data)
        connect_lpu_pat(lpu1_ports_sels, lpu1_lpu_ports_data,
                        lpu1_pat_ports_data)


if __name__ == '__main__':
    logging.basicConfig(
        level=logging.DEBUG,
        stream=sys.stdout,
        format='%(asctime)s %(name)s %(levelname)s %(message)s')
    #g_orient = Graph(Config.from_url('/vision_demo','admin', 'admin', initial_drop=True)) # set to True to erase the database
    g_orient = Graph(
        Config.from_url('/ampa/bionet/databases/development/na_server',
                        'admin',
                        'admin',
                        initial_drop=False,
                        serialization_type=OrientSerialization.Binary)
    )  # set to True to erase the database
    g_orient.create_all(Node.registry)
    g_orient.create_all(Relationship.registry)

    #g_orient.include(Node.registry)
    #g_orient.include(Relationship.registry)

    vl = NetworkXLoader(g_orient)

    # Load LPU data:

    vl.logger.info('Loading sample Lamina circuit...')
    vl.load_lpu('lamina.gexf.gz', 'LAM')
"""
util for create classes
"""
import os

import django
from django.conf import settings

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite_orientdb.settings")
django.setup()
from pyorient.ogm import Graph, Config
from ngpyorient.ng_node import NgNode
from ngpyorient.ng_relationship import NgRelationship

config = Config.from_url(
    settings.DATABASES_NG["default"]["URL"],
    settings.DATABASES_NG["default"]["USER"],
    settings.DATABASES_NG["default"]["PASSWORD"],
)
graph = Graph(config)

# NgNode.registry.pop("ngnode")
# NgRelationship.registry.pop("ngrelationship")

graph.create_all(NgNode.registry)
graph.create_all(NgRelationship.registry)
graph.client.close()