Exemplo n.º 1
0
 def command(self):
     self._setup_logging()
     self._load_migrations()
     from .runner import run_migration, reset_migration, show_status, set_status
     bind = create_engine(self.options.connection_url)
     if self.options.database is None:
         datastores = [
             create_datastore(db, bind=bind)
             for db in bind.conn.database_names()
             if db not in ('admin', 'local') ]
     else:
         datastores = [ create_datastore(self.options.database, bind=bind) ]
     for ds in datastores:
         self.log.info('Migrate DB: %s', ds.database)
         if self.options.status_only:
             show_status(ds)
         elif self.options.force:
             set_status(ds, self._target_versions())
         elif self.options.reset:
             reset_migration(ds, dry_run=self.options.dry_run)
         else:
             run_migration(ds, self._target_versions(), dry_run=self.options.dry_run)
         try:
             ds.conn.disconnect()
             ds._conn = None
         except: # MIM doesn't do this
             pass
Exemplo n.º 2
0
 def setUp(self):
     M.doc_session.bind = ming.create_datastore(
         'test',
         bind=ming.create_engine(
             use_class=lambda *a, **kw: mim.Connection.get()))
     mim.Connection.get().clear_all()
     self.doubler = Function.decorate('double')(self._double)
Exemplo n.º 3
0
def setup_database():
    global datastore, database_setup
    if not database_setup:
        datastore = create_datastore(
            os.environ.get('MONGOURL', 'mim:///depottest'))
        mainsession.bind = datastore
        ming.odm.Mapper.compile_all()
Exemplo n.º 4
0
    def setUp(self):
        Mapper._mapper_by_classname.clear()
        self.datastore = create_datastore('mim:///test_db')
        self.session = ODMSession(bind=self.datastore)

        class Parent(MappedClass):
            class __mongometa__:
                name = 'parent'
                session = self.session

            _id = FieldProperty(int)
            children = RelationProperty('Child')

        class Child(MappedClass):
            class __mongometa__:
                name = 'child'
                session = self.session

            _id = FieldProperty(int)
            parents = RelationProperty('Parent')
            _parents = ForeignIdProperty('Parent', uselist=True)

        Mapper.compile_all()
        self.Parent = Parent
        self.Child = Child
Exemplo n.º 5
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.session = ODMSession(bind=self.datastore)
     class Parent(MappedClass):
         class __mongometa__:
             name='parent'
             session = self.session
         _id = FieldProperty(S.ObjectId)
         children = ForeignIdProperty('Child', uselist=True)
         field_with_default_id = ForeignIdProperty(
             'Child',
             uselist=True,
             if_missing=lambda:[bson.ObjectId('deadbeefdeadbeefdeadbeef')])
         field_with_default = RelationProperty('Child', 'field_with_default_id')
     class Child(MappedClass):
         class __mongometa__:
             name='child'
             session = self.session
         _id = FieldProperty(S.ObjectId)
         parent_id = ForeignIdProperty(Parent)
         field_with_default_id = ForeignIdProperty(
             Parent,
             if_missing=lambda:bson.ObjectId('deadbeefdeadbeefdeadbeef'))
         field_with_default = RelationProperty('Parent', 'field_with_default_id')
     Mapper.compile_all()
     self.Parent = Parent
     self.Child = Child
Exemplo n.º 6
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.session = ODMSession(bind=self.datastore)
     class BasicMapperExtension(MapperExtension):
         def after_insert(self, instance, state, session):
             assert 'clean'==state.status
         def before_insert(self, instance, state, session):
             assert 'new'==state.status
         def before_update(self, instance, state, session):
             assert 'dirty'==state.status
         def after_update(self, instance, state, session):
             assert 'clean'==state.status
     class Basic(MappedClass):
         class __mongometa__:
             name='basic'
             session = self.session
             extensions = [BasicMapperExtension, MapperExtension]
         _id = FieldProperty(S.ObjectId)
         a = FieldProperty(int)
         b = FieldProperty([int])
         c = FieldProperty(dict(
                 d=int, e=int))
     Mapper.compile_all()
     self.Basic = Basic
     self.session.remove(self.Basic)
Exemplo n.º 7
0
def create_session(login, password, path):
    global session
    if session == None:
        session = ThreadLocalODMSession(
            bind=create_datastore('mongodb://%s:%s@%s' %
                                  (login, password, path)))
    return session
Exemplo n.º 8
0
 def setUp(self):
     self.bind = create_datastore('mim:///testdb')
     self.bind.conn.drop_all()
     self.bind.db.coll.insert({'_id':'foo', 'a':2, 'c':[1,2,3],
                               'z': {'egg': 'spam', 'spam': 'egg'}})
     for r in range(4):
         self.bind.db.rcoll.insert({'_id':'r%s' % r, 'd':r})
Exemplo n.º 9
0
    def setUp(self):
        Mapper._mapper_by_classname.clear()
        self.datastore = create_datastore('mim:///test_db')
        self.doc_session = Session(self.datastore)
        self.odm_session = ODMSession(self.doc_session)

        class Base(MappedClass):
            class __mongometa__:
                name = 'test_doc'
                session = self.odm_session
                polymorphic_on = 'type'
                polymorphic_identity = 'base'

            _id = FieldProperty(S.ObjectId)
            type = FieldProperty(str, if_missing='base')
            a = FieldProperty(int)

        class Derived(Base):
            class __mongometa__:
                polymorphic_identity = 'derived'

            type = FieldProperty(str, if_missing='derived')
            b = FieldProperty(int)

        Mapper.compile_all()
        self.Base = Base
        self.Derived = Derived
Exemplo n.º 10
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)

        class Parent(object):
            pass

        class Child(object):
            pass

        parent = collection('parent', session, Field('_id', int))
        child = collection('child', session, Field('_id', int),
                           Field('parent_id', int))
        mapper(Parent,
               parent,
               self.session,
               properties=dict(children=RelationProperty(Child)))
        mapper(Child,
               child,
               self.session,
               properties=dict(parent_id=ForeignIdProperty(Parent),
                               parent=RelationProperty(Parent)))
        self.Parent = Parent
        self.Child = Child
Exemplo n.º 11
0
 def test_replica_set(self, MockConn):
     from pymongo import MongoClient
     result = create_datastore(
         'mongodb://localhost:23,localhost:27017,localhost:999/test_db',
         replicaSet='foo')
     print(result.bind._conn_args[0])
     assert result.bind._conn_args[0].startswith('mongodb://localhost:23,localhost:27017,localhost:999')
Exemplo n.º 12
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)
        base = collection('test_doc',
                          session,
                          Field('_id', S.ObjectId),
                          Field('type', str, if_missing='base'),
                          Field('a', int),
                          polymorphic_on='type',
                          polymorphic_identity='base')
        derived = collection(base,
                             Field('type', str, if_missing='derived'),
                             Field('b', int),
                             polymorphic_identity='derived')

        class Base(object):
            pass

        class Derived(Base):
            pass

        mapper(Base, base, self.session)
        mapper(Derived, derived, self.session)
        self.Base = Base
        self.Derived = Derived
Exemplo n.º 13
0
    def get_session(self):
        if 'session_uri' not in self.config_values:
            self.set_session_uri("mongodb://localhost:27017/mldatahub")

        if self.session is None:
            self.session = ThreadLocalODMSession(bind=create_datastore(self.config_values['session_uri']))
        return self.session
Exemplo n.º 14
0
    def setUp(self):
        self.bind = create_datastore('mim:///luna')
        self.db = self.bind.db.luna
        self.path = path

        if not os.path.exists(self.path):
            os.makedirs(self.path)
Exemplo n.º 15
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.session = ODMSession(bind=self.datastore)
     class GrandParent(MappedClass):
         class __mongometa__:
             name='grand_parent'
             session=self.session
         _id = FieldProperty(int)
     class Parent(MappedClass):
         class __mongometa__:
             name='parent'
             session = self.session
         _id = FieldProperty(int)
         grandparent_id = ForeignIdProperty('GrandParent')
         grandparent = RelationProperty('GrandParent')
         children = RelationProperty('Child')
     class Child(MappedClass):
         class __mongometa__:
             name='child'
             session = self.session
         _id = FieldProperty(int)
         parent_id = ForeignIdProperty('Parent', allow_none=True)
         parent = RelationProperty('Parent')
     Mapper.compile_all()
     self.GrandParent = GrandParent
     self.Parent = Parent
     self.Child = Child
Exemplo n.º 16
0
def connecting_datastore():
    from ming import create_datastore

    datastore = create_datastore('mongodb://localhost:27017/tutorial')
    datastore
    # The connection is actually performed lazily
    # the first time db is accessed
    datastore.db
    datastore
Exemplo n.º 17
0
def includeme(config):
    engine = create_datastore(os.getenv(config.registry.settings['mongo_url_env'], 'openrosetta'))
    session.bind = engine
    Mapper.compile_all()

    for mapper in Mapper.all_mappers():
        session.ensure_indexes(mapper.collection)

    config.add_tween('openrosetta.models.ming_autoflush_tween', over=EXCVIEW)
Exemplo n.º 18
0
 def setUp(self):
     self.bind = create_datastore('mim:///testdb')
     self.bind.conn.drop_all()
     self.bind.db.coll.insert(
         {'_id':'foo', 'a':2,
          'b': { 'c': 1, 'd': 2, 'e': [1,2,3],
                 'f': [ { 'g': 1 }, { 'g': 2 } ] },
          'x': {} })
     self.coll = self.bind.db.coll
Exemplo n.º 19
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     basic = collection('basic', session)
     class Basic(object):
         pass                    
     self.session.mapper(Basic, basic)
     self.basic = basic
     self.Basic = Basic
Exemplo n.º 20
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     basic = collection('basic', session)
     class Basic(object):
         pass
     self.session.mapper(Basic, basic)
     self.basic = basic
     self.Basic = Basic
Exemplo n.º 21
0
def connection_session():
    from ming import create_datastore
    from ming.odm import ThreadLocalODMSession

    session = ThreadLocalODMSession(
        bind=create_datastore('mongodb://localhost:27017/tutorial')
    )
    session
    # The database and datastore are still available
    # through the session as .db and .bind
    session.db
    session.bind
Exemplo n.º 22
0
 def create_ming_datastore(conf):
     from ming import create_datastore
     url = conf['ming.url']
     database = conf.get('ming.db', '')
     try:
         connection_options = get_partial_dict('ming.connection', conf)
     except AttributeError:
         connection_options = {}
     if database and url[-1] != '/':
         url += '/'
     ming_url = url + database
     return create_datastore(ming_url, **connection_options)
Exemplo n.º 23
0
    def setUp(self):
        self.bind = create_datastore('mim:///luna')
        self.db = self.bind.db.luna
        self.path = '/tmp/luna'

        if not os.path.exists(self.path):
            os.makedirs(self.path)

        cluster = luna.Cluster(mongo_db=self.db,
                               create=True,
                               path=self.path,
                               user=getpass.getuser())
Exemplo n.º 24
0
 def create_ming_datastore(conf):
     from ming import create_datastore
     url = conf['ming.url']
     database = conf.get('ming.db', '')
     try:
         connection_options = get_partial_dict('ming.connection', conf)
     except AttributeError:
         connection_options = {}
     if database and url[-1] != '/':
         url += '/'
     ming_url = url + database
     return create_datastore(ming_url, **connection_options)
Exemplo n.º 25
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.session = ThreadLocalODMSession(Session(bind=self.datastore))
     class Parent(MappedClass):
         class __mongometa__:
             name='parent'
             session = self.session
         _id = FieldProperty(S.ObjectId)
     Mapper.compile_all()
     self.Parent = Parent
     self.create_app =  TestApp(MingMiddleware(self._wsgi_create_object))
     self.remove_app =  TestApp(MingMiddleware(self._wsgi_remove_object))
     self.remove_exc =  TestApp(MingMiddleware(self._wsgi_remove_object_exc))
Exemplo n.º 26
0
 def __init__(self, path=None, dbtype='auto'):
     """
     path   - Path to store sandbox files.
     dbtype - Type of the dabatabse. [auto|mongo|ming]
     """
     if 'LUNA_TEST_DBTYPE' in os.environ:
         dbtype = os.environ['LUNA_TEST_DBTYPE']
     if not path:
         self.path = tempfile.mkdtemp(prefix='luna')
     else:
         # can cause race condition, but ok
         if not os.path.exists(path):
             os.makedirs(path)
         self.path = path
     self._dbconn = None
     self._mingdatastore = None
     self._mongopath = self.path + "/mongo"
     if not os.path.exists(self._mongopath):
         os.makedirs(self._mongopath)
     self._mongoprocess = None
     if dbtype == 'auto':
         try:
             self._start_mongo()
             self.dbtype = 'mongo'
         except OSError:
             self._mingdatastore = ming.create_datastore('mim:///' +
                                                         str(uuid.uuid4()))
             self._dbconn = self._mingdatastore.db.luna
             self.dbtype = 'ming'
     elif dbtype == 'mongo':
         self._start_mongo()
         self.dbtype = 'mongo'
     else:
         self._mingdatastore = ming.create_datastore('mim:///' +
                                                     str(uuid.uuid4()))
         self._dbconn = self._mingdatastore.db.luna
         self.dbtype = 'ming'
     self._create_luna_homedir()
Exemplo n.º 27
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)
        basic = collection('basic', session, Field('_id', S.ObjectId),
                           Field('a', int), Field('b', [int]),
                           Field('c', dict(d=int, e=int)))

        class Basic(object):
            pass

        self.session.mapper(Basic, basic)
        self.basic = basic
        self.Basic = Basic
Exemplo n.º 28
0
 def __init__(self, path = None, dbtype = 'auto'):
     """
     path   - Path to store sandbox files.
     dbtype - Type of the dabatabse. [auto|mongo|ming]
     """
     if 'LUNA_TEST_DBTYPE' in os.environ:
         dbtype = os.environ['LUNA_TEST_DBTYPE']
     if not path:
         self.path = tempfile.mkdtemp(prefix='luna')
     else:
         # can cause race condition, but ok
         if not os.path.exists(path):
             os.makedirs(path)
         self.path = path
     self._dbconn = None
     self._mingdatastore = None
     self._mongopath = self.path + "/mongo"
     if not os.path.exists(self._mongopath):
         os.makedirs(self._mongopath)
     self._mongoprocess = None
     if dbtype == 'auto':
         try:
             self._start_mongo()
             self.dbtype = 'mongo'
         except OSError:
             self._mingdatastore = ming.create_datastore('mim:///' + str(uuid.uuid4()))
             self._dbconn = self._mingdatastore.db.luna
             self.dbtype = 'ming'
     elif dbtype == 'mongo':
         self._start_mongo()
         self.dbtype = 'mongo'
     else:
         self._mingdatastore = ming.create_datastore('mim:///' + str(uuid.uuid4()))
         self._dbconn = self._mingdatastore.db.luna
         self.dbtype = 'ming'
     self._create_luna_homedir()
Exemplo n.º 29
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        self.session = ODMSession(bind=self.datastore)

        class TestCollection(MappedClass):
            class __mongometa__:
                name='test_collection'
                session = self.session
            _id = FieldProperty(int)

            children = RelationProperty('TestCollection')
            _children = ForeignIdProperty('TestCollection', uselist=True)
            parents = RelationProperty('TestCollection', via=('_children', False))

        Mapper.compile_all()
        self.TestCollection = TestCollection
Exemplo n.º 30
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     basic = collection(
         'basic', session,
         Field('_id', S.ObjectId),
         Field('a', int),
         Field('b', [int]),
         Field('c', dict(
                 d=int, e=int)))
     class Basic(object):
         pass                    
     self.session.mapper(Basic, basic)
     self.basic = basic
     self.Basic = Basic
Exemplo n.º 31
0
    def setUp(self):
        Mapper._mapper_by_classname.clear()
        self.datastore = create_datastore('mim:///test_db')
        self.session = ODMSession(bind=self.datastore)

        class Basic(MappedClass):
            class __mongometa__:
                name = 'hook'
                session = self.session

            _id = FieldProperty(S.ObjectId)
            a = FieldProperty(int)

        Mapper.compile_all()
        self.Basic = Basic
        self.session.remove(self.Basic)
Exemplo n.º 32
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        self.session = ThreadLocalODMSession(Session(bind=self.datastore))

        class Parent(MappedClass):
            class __mongometa__:
                name = 'parent'
                session = self.session

            _id = FieldProperty(S.ObjectId)

        Mapper.compile_all()
        self.Parent = Parent
        self.create_app = TestApp(MingMiddleware(self._wsgi_create_object))
        self.remove_app = TestApp(MingMiddleware(self._wsgi_remove_object))
        self.remove_exc = TestApp(MingMiddleware(self._wsgi_remove_object_exc))
Exemplo n.º 33
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.session = ODMSession(bind=self.datastore)
     class Basic(MappedClass):
         class __mongometa__:
             name='basic'
             session = self.session
         _id = FieldProperty(S.ObjectId)
         a = FieldProperty(int)
         b = FieldProperty([int])
         c = FieldProperty(dict(
                 d=int, e=int))
         d = FieldPropertyWithMissingNone(str, if_missing=S.Missing)
         e = FieldProperty(str, if_missing=S.Missing)
     Mapper.compile_all()
     self.Basic = Basic
     self.session.remove(self.Basic)
Exemplo n.º 34
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        self.session = ThreadLocalODMSession(Session(bind=self.datastore))

        class TestRelationParent(MappedClass):
            """This class _must_ have a unique class name or it will conflict
                with other tests."""
            class __mongometa__:
                name = 'parent'
                session = self.session

            _id = FieldProperty(S.ObjectId)

        Mapper.compile_all()
        self.Parent = TestRelationParent
        self.create_app = TestApp(MingMiddleware(self._wsgi_create_object))
        self.remove_app = TestApp(MingMiddleware(self._wsgi_remove_object))
        self.remove_exc = TestApp(MingMiddleware(self._wsgi_remove_object_exc))
Exemplo n.º 35
0
    def setUp(self):
        self.bind = create_datastore('mim:///luna')
        self.db = self.bind.db.luna
        self.path = '/tmp/luna'

        if not os.path.exists(self.path):
            os.makedirs(self.path)

        cluster = luna.Cluster(mongo_db=self.db,
                               create=True,
                               path=self.path,
                               user=getpass.getuser())
        self.net = luna.Network(name='test',
                                mongo_db=self.db,
                                create=True,
                                NETWORK='172.16.1.0',
                                PREFIX='24',
                                ns_hostname='controller',
                                ns_ip='172.16.1.254')
Exemplo n.º 36
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     class Parent(object): pass
     class Child(object): pass
     parent = collection(
         'parent', session,
         Field('_id', int))
     child = collection(
         'child', session,
         Field('_id', int),
         Field('parent_id', int))
     mapper(Parent, parent, self.session, properties=dict(
             children=RelationProperty(Child)))
     mapper(Child, child, self.session, properties=dict(
             parent_id=ForeignIdProperty(Parent),
             parent = RelationProperty(Parent)))
     self.Parent = Parent
     self.Child = Child
Exemplo n.º 37
0
    def setUp(self):
        Mapper._mapper_by_classname.clear()
        self.datastore = create_datastore('mim:///test_db')
        self.session = ODMSession(bind=self.datastore)
        self.hooks_called = defaultdict(list)
        tc = self

        class Basic(MappedClass):
            class __mongometa__:
                name = 'hook'
                session = self.session

                def before_save(instance):
                    tc.hooks_called['before_save'].append(instance)

            _id = FieldProperty(S.ObjectId)
            a = FieldProperty(int)

        Mapper.compile_all()
        self.Basic = Basic
        self.session.remove(self.Basic)
Exemplo n.º 38
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     self.doc_session = Session(self.datastore)
     self.odm_session = ODMSession(self.doc_session)
     class Base(MappedClass):
         class __mongometa__:
             name='test_doc'
             session = self.odm_session
             polymorphic_on='type'
             polymorphic_identity='base'
         _id = FieldProperty(S.ObjectId)
         type=FieldProperty(str, if_missing='base')
         a=FieldProperty(int)
     class Derived(Base):
         class __mongometa__:
             polymorphic_identity='derived'
         type=FieldProperty(str, if_missing='derived')
         b=FieldProperty(int)
     Mapper.compile_all()
     self.Base = Base
     self.Derived = Derived
Exemplo n.º 39
0
    def setupClass(cls):
        if ming is None:
            raise SkipTest('Ming not available...')

        cls.basic_session = Session(create_datastore('mim:///'))
        cls.s = ODMSession(cls.basic_session)

        class Author(MappedClass):
            class __mongometa__:
                session = cls.s
                name = 'wiki_author'

            _id = FieldProperty(schema.ObjectId)
            name = FieldProperty(str)
            pages = RelationProperty('WikiPage')

        class WikiPage(MappedClass):
            class __mongometa__:
                session = cls.s
                name = 'wiki_page'

            _id = FieldProperty(schema.ObjectId)
            title = FieldProperty(str)
            text = FieldProperty(str)
            order = FieldProperty(int)
            author_id = ForeignIdProperty(Author)
            author = RelationProperty(Author)

        cls.Author = Author
        cls.WikiPage = WikiPage
        Mapper.compile_all()

        cls.author = Author(name='author1')
        author2 = Author(name='author2')

        WikiPage(title='Hello', text='Text', order=1, author=cls.author)
        WikiPage(title='Another', text='Text', order=2, author=cls.author)
        WikiPage(title='ThirdOne', text='Text', order=3, author=author2)
        cls.s.flush()
        cls.s.clear()
Exemplo n.º 40
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     base = collection(
         'test_doc', session,
         Field('_id', S.ObjectId),
         Field('type', str, if_missing='base'),
         Field('a', int),
         polymorphic_on='type',
         polymorphic_identity='base')
     derived = collection(
         base, 
         Field('type', str, if_missing='derived'),
         Field('b', int),
         polymorphic_identity='derived')
     class Base(object): pass
     class Derived(Base): pass
     mapper(Base, base, self.session)
     mapper(Derived, derived, self.session)
     self.Base = Base
     self.Derived = Derived
Exemplo n.º 41
0
 def setUp(self):
   self.mg = ming.create_datastore('mim://', db='nba', **kwargs)
   self.nbam = NBAMongo(self.mg.db)
   self.games = []
   self.standings = []
   self._get_scoreboard()
Exemplo n.º 42
0
#  Copyright      : Copyright (c) 2012-2015 David Fischer. All rights reserved.
#
#**********************************************************************************************************************#
#
# This file is part of David Fischer's pytoolbox Project.
#
# This project is free software: you can redistribute it and/or modify it under the terms of the EUPL v. 1.1 as provided
# by the European Commission. This project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See the European Union Public License for more details.
#
# You should have received a copy of the EUPL General Public License along with this project.
# If not, see he EUPL licence v1.1 is available in 22 languages:
#     22-07-2013, <https://joinup.ec.europa.eu/software/page/eupl/licence-eupl>
#
# Retrieved from https://github.com/davidfischer-ch/pytoolbox.git

from __future__ import absolute_import, division, print_function, unicode_literals

from ming import create_datastore, Session
from ming.odm import ThreadLocalODMSession

from .. import module

_all = module.All(globals())

bind = create_datastore('mim://')
doc_session = Session(bind)
odm_session = ThreadLocalODMSession(doc_session=doc_session)
Exemplo n.º 43
0
from ming import Session, create_datastore
from ming import Document, Field, schema
import json
import urllib2

bind = create_datastore('mongodb://localhost/paperMiningTest')
session = Session(bind)

class Paper(Document):

    class __mongometa__:
        session = session
        name = 'paperCoCitation'

    id = Field(str) 
    cocitation = Field([]) #put cite paper id

if __name__ == '__main__':
    baseUrl = "http://140.118.175.209/paper/cocitation.php?ids="
    with open('paperId.json') as data_file:
        data = json.load(data_file)
    for paperId in data["CitationId"]:
        url = baseUrl + str(paperId)
        arr = = json.load(urllib2.urlopen(url))
        if len(arr) is not 0:
            cocitationRelationDic = arr[0]
            paperRel = Paper(dict(id = cocitationRelationDic["id"],cocitation = cocitationRelationDic["co_citation"]))
            paperRel.m.save()
            print paperRel
        else:
            print "No cocitation"
Exemplo n.º 44
0
 def setUp(self):
     self.bind = create_datastore('mim:///testdb')
     self.bind.conn.drop_all()
Exemplo n.º 45
0
 def setUp(self):
     self.bind = create_datastore('mim:///testdb')
     self.bind.conn.drop_all()
     self.bind.db.coll.insert({'_id':'foo', 'a':2, 'c':[1,2,3]})
     for r in range(4):
         self.bind.db.rcoll.insert({'_id':'r%s' % r, 'd':r})
Exemplo n.º 46
0
from ming import create_datastore
from ming.odm import ThreadLocalODMSession
from litminer import config

auth = dict(config["mongodb"])
uri = auth.pop("uri",None)

session = ThreadLocalODMSession(
    bind=create_datastore(uri=uri,authenticate=auth)
)
Exemplo n.º 47
0
# coding=utf-8

from ming import create_datastore, Session
from ming.odm import ODMSession
import os


session = Session()
session.bind = create_datastore(os.environ.get('MONGO_URL'))
odm_session = ODMSession(session)
Exemplo n.º 48
0
 def setUp(self):
     self.ds = create_datastore("mim:///test")
     self.Session = Session(bind=self.ds)
     self.TestFS = fs.filesystem("test_fs", self.Session)
Exemplo n.º 49
0
        import json
        self.set_raw(name, key, json.dumps(value)) 
        
    def incr(self, name, key, amount=1):
        val = self.get(name, key)
        if val:
            val += amount
        else:
            val = amount
        self.set(name, key, val)
        return val  
    
from stubo.cache import Cache
from stubo.model.db import Scenario
import ming
mg = ming.create_datastore('mim://')

class DummyScenario(Scenario):
    
    def __init__(self):
        dbname = testdb_name()
        client = getattr(mg.conn, dbname)
        Scenario.__init__(self, db=client)
        
    def __call__(self, **kwargs):
        return self  
    
    # derive these methods as ming hasn't implemented '$regex' matching
    
    def get_all(self, name=None):
        if name and isinstance(name, dict) and '$regex' in name:
Exemplo n.º 50
0
 def create_ming_datastore():
     return create_datastore(os.environ.get('MONGOURL', 'mongodb://127.0.0.1:27017/test_db'))
Exemplo n.º 51
0
 def setUp(self):
     self.bind = create_datastore('mim:///testdb')
     self.bind.conn.drop_all()
     self.doc = {'_id':'foo', 'a':2, 'c':[1,2,3]}
     self.bind.db.coll.insert(self.doc)
Exemplo n.º 52
0
 def initialize_collection(self):
     client = ming.create_datastore(self.get_property('url')).conn
     return client[self.get_property('database')][self.get_property(
         'collection')]
Exemplo n.º 53
0
    def __init__(self, mongo_uri):

        if mongo_uri[0]=='$':
            mongo_uri = os.getenv(mongo_uri[1:])
        self.mongo_engine = create_datastore(mongo_uri)