コード例 #1
0
ファイル: tools.py プロジェクト: ykursad/game-of-graphql
def recreate_game_of_graphql_graph(orientdb_location, username, password):
    """If the Game of GraphQL graph isn't present, construct it from the GamesOfThrones one."""
    exising_config = Config.from_url(
        'plocal://{}/GamesOfThrones'.format(orientdb_location), username,
        password)
    new_config = Config.from_url(
        'plocal://{}/game_of_graphql'.format(orientdb_location), username,
        password)

    data = existing_dataset.load_all_data(exising_config)
    new_dataset.create_game_of_graphql_graph(new_config, data)
コード例 #2
0
ファイル: test_ogm.py プロジェクト: spivachuk/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('animals', 'root', 'root',
                                           initial_drop=True))


        g.create_all(AnimalsNode.registry)
        g.create_all(AnimalsRelationship.registry)
コード例 #3
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('animals', 'root', 'root',
                                           initial_drop=True))


        g.create_all(AnimalsNode.registry)
        g.create_all(AnimalsRelationship.registry)
コード例 #4
0
    def testStrictness(self):
        g = self.g

        # Unknown properties get silently dropped by default
        pentium = g.cpu.create(name='Pentium', version=6)
        loaded_pentium = g.get_vertex(pentium._id)
        # Version is not defined in cpu
        assert not hasattr(pentium, 'version')

        # But in strict mode they generate errors
        g = self.g = Graph(Config.from_url('hardware',
                                           'root',
                                           'root',
                                           initial_drop=False),
                           strict=True)
        g.include(
            g.build_mapping(declarative_node(),
                            declarative_relationship(),
                            auto_plural=True))
        with self.assertRaises(AttributeError):
            pentium = g.cpu.create(name='Pentium', version=6)

        pentium = g.x86cpu.create(name='Pentium', version=6)
        self.assertEquals('Pentium', pentium.name)
        self.assertEquals(6, pentium.version)
コード例 #5
0
 def setUp(self):
     g = self.g = Graph(
         Config.from_url('abstract_classes',
                         'root',
                         'root',
                         initial_drop=True))
     g.client.command('CREATE CLASS AbstractClass EXTENDS V ABSTRACT')
     g.client.command('CREATE CLASS ConcreteClass EXTENDS V')
コード例 #6
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('custom_field', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(ClassFieldNode.registry)
        g.create_all(ClassFieldRelationship.registry)
        g.client.command('ALTER CLASS classfieldvertex CUSTOM test_field_1=test_string_one')
        g.client.command('ALTER CLASS classfieldvertex CUSTOM test_field_2="test string two"')
        g.client.command('ALTER CLASS classfieldedge CUSTOM test_field_1="test string two"')
コード例 #7
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('custom_field', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(ClassFieldNode.registry)
        g.create_all(ClassFieldRelationship.registry)
        g.client.command('ALTER CLASS classfieldvertex CUSTOM test_field_1=test_string_one')
        g.client.command('ALTER CLASS classfieldvertex CUSTOM test_field_2="test string two"')
        g.client.command('ALTER CLASS classfieldedge CUSTOM test_field_1="test string two"')
コード例 #8
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def testConfigs(self):
        configs = [
            'localhost:2424/test_config1',
            'localhost/test_config2',
            'plocal://localhost/test_config3',
            'plocal://localhost:2424/test_config4',
            'memory://localhost/test_config5',
            'memory://localhost:2424/test_config6',
        ]

        for conf in configs:
            # the following line should not raise errors
            Graph(Config.from_url(conf, 'root', 'root', initial_drop=True))
コード例 #9
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def testConfigs(self):
        configs = [
            'localhost:2424/test_config1',
            'localhost/test_config2',
            'plocal://localhost/test_config3',
            'plocal://localhost:2424/test_config4',
            'memory://localhost/test_config5',
            'memory://localhost:2424/test_config6',
        ]

        for conf in configs:
            # the following line should not raise errors
            Graph(Config.from_url(conf, 'root', 'root', initial_drop=True))
コード例 #10
0
 def __init__(self,
              database='/na_server',
              username='******',
              password='******',
              user=None):
     try:
         self.graph = Graph(
             Config.from_url(database,
                             username,
                             password,
                             initial_drop=False,
                             serialization_type=OrientSerialization.Binary))
     except:
         print "WARNING: Serialisation flag ignored"
         self.graph = Graph(
             Config.from_url(database,
                             username,
                             password,
                             initial_drop=False))
     self.graph.include(Node.registry)
     self.graph.include(Relationship.registry)
     self.user = user
     self.query_processor = query_processor(self.graph)
コード例 #11
0
def get_test_graph(graph_name):
    """Generate the test database and return the pyorient client."""
    url = get_orientdb_url(graph_name)
    config = Config.from_url(url, ORIENTDB_USER, ORIENTDB_PASSWORD, initial_drop=True)
    Graph(config, strict=True)

    client = OrientDB('localhost', ORIENTDB_PORT)
    client.connect(ORIENTDB_USER, ORIENTDB_PASSWORD)
    client.db_open(graph_name, ORIENTDB_USER, ORIENTDB_PASSWORD, db_type=DB_TYPE_GRAPH)

    load_schema(client)
    generate_data(client)

    return client
コード例 #12
0
def get_pyorient_client():
    db_url = ''.join([
        'plocal://', server_config.ORIENTDB_HOST, ':2424', '/',
        server_config.ORIENTDB_DB
    ])
    graph = Graph(Config.from_url(db_url, server_config.ORIENTDB_USER,
                                  server_config.ORIENTDB_PASSWORD),
                  strict=True)

    graph.include(
        graph.build_mapping(declarative_node(),
                            declarative_relationship(),
                            auto_plural=False))

    return graph
コード例 #13
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
コード例 #14
0
ファイル: server.py プロジェクト: ykursad/game-of-graphql
def run(host, port, graph_location, graph_user, graph_password):
    """Run the app."""
    # pylint: disable=global-statement
    global graph_config
    # pylint: enable=global-statement
    graph_config = Config.from_url(
        'plocal://{}/game_of_graphql'.format(graph_location), graph_user, graph_password)

    app.logger.info(u'Waiting for OrientDB to come alive...')
    tools.wait_for_orientdb_to_come_alive(graph_location, graph_user, graph_password)

    app.logger.info(u'Recreating the Game of GraphQL graph...')
    tools.recreate_game_of_graphql_graph(graph_location, graph_user, graph_password)

    app.logger.info(u'Starting server...')
    app.run(host=host, port=port, debug=False)
コード例 #15
0
ファイル: tools.py プロジェクト: ykursad/game-of-graphql
def wait_for_orientdb_to_come_alive(orientdb_location, username, password):
    """Block until OrientDB is ready to serve requests."""
    config = Config.from_url(
        'plocal://{}/GamesOfThrones'.format(orientdb_location), username,
        password)

    retries = 100

    for _ in range(retries):
        try:
            # This line will raise a connection error if OrientDB isn't ready yet.
            Graph(config, strict=True)
            return
        except PyOrientConnectionException:
            sleep(1.0)

    raise RuntimeError(u'Could not connect to OrientDB at {}. '
                       u'Giving up after {} retries.'.format(
                           orientdb_location, retries))
コード例 #16
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def testStrictness(self):
        g = self.g

        # Unknown properties get silently dropped by default
        pentium = g.cpu.create(name='Pentium', version=6)
        loaded_pentium = g.get_vertex(pentium._id)
        # Version is not defined in cpu
        assert not hasattr(pentium, 'version')

        # But in strict mode they generate errors
        g = self.g = Graph(Config.from_url('hardware', 'root', 'root'
                                           , initial_drop=False), strict=True)
        g.include(g.build_mapping(
            declarative_node(), declarative_relationship(), auto_plural=True))
        with self.assertRaises(AttributeError):
            pentium = g.cpu.create(name='Pentium', version=6)

        pentium = g.x86cpu.create(name='Pentium', version=6)
        self.assertEquals('Pentium', pentium.name)
        self.assertEquals(6, pentium.version)
コード例 #17
0
def get_test_orientdb_graph(
    graph_name: str,
    load_schema_func: Callable[[OrientDB], None],
    generate_data_func: Callable[[OrientDB], None],
) -> OrientDB:
    """Generate the test database and return the pyorient client."""
    url = get_orientdb_url(graph_name)
    config = Config.from_url(url,
                             ORIENTDB_USER,
                             ORIENTDB_PASSWORD,
                             initial_drop=True)
    Graph(config, strict=True)

    client = OrientDB(host="localhost", port=ORIENTDB_PORT)
    client.connect(ORIENTDB_USER, ORIENTDB_PASSWORD)
    client.db_open(graph_name,
                   ORIENTDB_USER,
                   ORIENTDB_PASSWORD,
                   db_type=DB_TYPE_GRAPH)

    load_schema_func(client)
    generate_data_func(client)

    return client
コード例 #18
0
ファイル: load_flycircuit.py プロジェクト: yiyin/neuroarch
                
                # Add content to new node:
                self.g_orient.client.command('update %s content %s' % \
                                         (nm._id, json.dumps(content)))

                
                self.logger.info('created node: {0}({1})'.format(nm.element_type, nm.name))
                
                # Connect nodes
                self.g_orient.Owns.create(npl, n)
                self.g_orient.HasData.create(n, arb)
                self.g_orient.HasData.create(n, nm)
                if nt:
                    self.g_orient.HasData.create(n, nt)
                    self.g_orient.Owns.create(ds_fc, n)
                self.g_orient.Owns.create(ds_fc, nm)
                self.g_orient.Owns.create(ds_fc, arb)

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('/na_server','root', 'root', 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)

    
    vl = NTHULoader(g_orient)

    vl.load_neurons('all_female_neurons.txt','flycircuit1.1')
コード例 #19
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_unicode', 'root', 'root',
                                           initial_drop=True))

        g.create_all(UnicodeNode.registry)
コード例 #20
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_datetime', 'root', 'root',
                                           initial_drop=True))

        g.create_all(DateTimeNode.registry)
コード例 #21
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
 def setUp(self):
     g = self.g = Graph(Config.from_url('classes', 'root', 'root'
                                        , initial_drop=True))
コード例 #22
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('money', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(MoneyNode.registry)
        g.create_all(MoneyRelationship.registry)
コード例 #23
0
util for drop specific class
"""
import os

import django
from django.conf import settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ops_platform.settings")
django.setup()
from pyorient import PyOrientSQLParsingException

from ngpyorient.graph import NgGraph
from ngpyorient.utils import write_error


from pyorient.ogm import Config

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

try:
    graph.drop_class_simple_by_class_name(sys.argv[1], sys.argv[2])
except PyOrientSQLParsingException as e:
    write_error(e)
except IndexError as e:
    write_error("you should specify classname and type(vertex or edge)")
graph.client.close()
コード例 #24
0
ファイル: ogm.py プロジェクト: infom/DeeBeeTee
from pyorient.ogm import Graph, Config
from pyorient.ogm.property import String, Float, DateTime
from pyorient.ogm.declarative import declarative_node, declarative_relationship
# Initialize Graph Database

graph = Graph(
    Config.from_url('plocal://localhost:2424//DeeBeeTee', 'deebeetee',
                    'deebeetee'))

Node = declarative_node()
Relationship = declarative_relationship()


class TransactionsRel(Relationship):
    element_plural = 'tx'
    element_type = 'tx'
    since = DateTime()
    tx = Float()


class Person(Node):
    element_plural = 'person'
    element_type = 'person'

    uid = String(indexed=True)
    name = String(indexed=True)

    credit_balance = Float(default=0.0, indexed=True)
    debit_balance = Float(default=0.0, indexed=True)
    balance = Float(default=0.0, indexed=True)
コード例 #25
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('hardware', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(HardwareNode.registry)
        g.create_all(HardwareRelationship.registry)
コード例 #26
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
 def setUp(self):
     g = self.g = Graph(Config.from_url('test_embedded_defaults', 'root', 'root',
                                        initial_drop=True))
コード例 #27
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_embedded', 'root', 'root',
                                           initial_drop=True))

        g.create_all(EmbeddedNode.registry)
コード例 #28
0
ファイル: load_flycircuit.py プロジェクト: TK-21st/neuroarch
            # Connect nodes
            self.g_orient.Owns.create(npl, n)
            self.g_orient.HasData.create(n, arb)
            #                self.g_orient.HasData.create(n, nm)
            if nt:
                self.g_orient.HasData.create(n, nt)
                self.g_orient.Owns.create(ds_fc, n)


#               self.g_orient.Owns.create(ds_fc, nm)
            self.g_orient.Owns.create(ds_fc, arb)

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('/na_server',
                        'root',
                        'root',
                        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)

    vl = NTHULoader(g_orient)

    vl.load_neurons('all_female_neurons.txt', 'flycircuit1.1')
コード例 #29
0
import pyorient.ogm
from pyorient.ogm import Graph, Config


# Connect to Database
a = Config.from_url(
   'plocal://localhost:2424/test',
   'root', 'c208lilje')

print(a.user)
print(a.cred)
print(a.db_name)
print(a.host)
print(a.port)
print(a.storage)
コード例 #30
0
ファイル: test_ogm.py プロジェクト: gaoxuesong/pyorient
 def setUp(self):
     g = self.g = Graph(Config.from_url('abstract_classes', 'root', 'root'
                                        , initial_drop=True))
     g.client.command('CREATE CLASS AbstractClass EXTENDS V ABSTRACT')
     g.client.command('CREATE CLASS ConcreteClass EXTENDS V')
コード例 #31
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('money', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(MoneyNode.registry)
        g.create_all(MoneyRelationship.registry)
コード例 #32
0
        'HOST': config.get('postgresdbConf', 'DB_HOST'),
        'PORT': config.get('postgresdbConf', 'DB_PORT'),
    },
    'orientdb': {
        'NAME': config.get('orientdbConf', 'DB_NAME'),
        'USER': config.get('orientdbConf', 'DB_USER'),
        'PASSWORD': config.get('orientdbConf', 'DB_PASS'),
        'HOST': config.get('orientdbConf', 'DB_HOST'),
        'PORT': config.get('orientdbConf', 'DB_PORT'),
    }
}

Config.from_url('plocal://' + DATABASES['orientdb']['HOST'] + ':' +
                str(DATABASES['orientdb']['PORT']) + '/' +
                DATABASES['orientdb']['NAME'] + '',
                '' + DATABASES['orientdb']['USER'] + '',
                '' + DATABASES['orientdb']['PASSWORD'] + '',
                initial_drop=False,
                serialization_type=OrientSerialization.Binary)
graph = Graph(
    Config.from_url('' + DATABASES['orientdb']['HOST'] + '/' +
                    DATABASES['orientdb']['NAME'] + '',
                    '' + DATABASES['orientdb']['USER'] + '',
                    '' + DATABASES['orientdb']['PASSWORD'] + '',
                    initial_drop=False))
Node = declarative.declarative_node()
Relationship = declarative.declarative_relationship()

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
コード例 #33
0
 def get_new_connection(self, conn_params):
     config = Config.from_url(*conn_params)
     conn = NgGraph(config)
     return conn
コード例 #34
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_embedded', 'root', 'root',
                                           initial_drop=True))

        g.create_all(EmbeddedNode.registry)
コード例 #35
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
 def setUp(self):
     g = self.g = Graph(Config.from_url('test_embedded_defaults', 'root', 'root',
                                        initial_drop=True))
コード例 #36
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('hardware', 'root', 'root'
                                           , initial_drop=True))

        g.create_all(HardwareNode.registry)
        g.create_all(HardwareRelationship.registry)
コード例 #37
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
 def setUp(self):
     g = self.g = Graph(Config.from_url('classes', 'root', 'root'
                                        , initial_drop=True))
コード例 #38
0
ファイル: LPULoader.py プロジェクト: vivvyk/NeuroMynerva
        connect_lpu_pat(lpu0_ports_sels, lpu0_lpu_ports_data,
                        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')
コード例 #39
0

def convert_complicate_list(a):
    tmp = []
    for region in a['regions']:
        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')
コード例 #40
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_datetime', 'root', 'root',
                                           initial_drop=True))

        g.create_all(DateTimeNode.registry)
コード例 #41
0
"""
Assign neuron and synapse model parameters.
"""

import logging
import sys

import numpy as np
from pyorient.ogm import Graph, Config

import neuroarch.models as models
import neuroarch.query as query
import neuroarch.nxtools as nxtools

from cx_config import cx_db
graph = Graph(Config.from_url(cx_db, 'admin', 'admin',
                              initial_drop=False))
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')

def leaky_iaf_params(lpu, extern):
    """
    Generate LeakyIAF params.
    """
    k = 1000
    assert isinstance(extern, bool)
    if lpu == 'BU' or lpu == 'bu':
        return {'extern': extern,
コード例 #42
0
ファイル: test_ogm.py プロジェクト: brucetony/pyorient
    def setUp(self):
        g = self.g = Graph(Config.from_url('test_unicode', 'root', 'root',
                                           initial_drop=True))

        g.create_all(UnicodeNode.registry)