Ejemplo n.º 1
0
    def __init__(self, db_name="d", host = None, port = None):

        self.model_has_been_created = False



        try:

            if not host and not port:
                self.storage = ZODB.FileStorage.FileStorage(file_name=db_name, blob_dir='.blob')
                self.db = ZODB.DB(self.storage)
            else:
                self.storage = ClientStorage.ClientStorage((host,port))
                self.db = ZODB.DB(self.storage)

            self.connection = self.db.open()
            self.root = self.connection.root()

            _init(self)



            self.users = self.root['users']
            self.piadas = self.root['piadas']
            self.admin  = self.root['admin']


            pass




        except Exception as e:
            raise Exception("Database Error - " + str(e))
Ejemplo n.º 2
0
def get_storage():
    try:
        return _thread_data.zodb_storage
    except AttributeError:
        addr = '127.0.0.1', 5001
        storage = _thread_data.zodb_storage = ClientStorage.ClientStorage(addr)
        return storage
Ejemplo n.º 3
0
 def spojiSeNaServer(self):
     #self.spremnik = ClientStorage.ClientStorage(('localhost', 1981))
     self.spremnik = ClientStorage.ClientStorage(('45.63.117.103', 1981))
     self.spremnik.server_sync = True
     self.bp = DB(self.spremnik)
     self.veza = self.bp.open()
     self.root = self.veza.root()
Ejemplo n.º 4
0
 def _get_db(self):
     """
     Open the connection to the database based on the configuration file.
     """
     return DB(
         ClientStorage.ClientStorage((self.server, self.port))
     )
Ejemplo n.º 5
0
    def __init__(self):
        self.query = self.exists
        #if not os.path.exists (self.default_database):
        #os.makedirs (os.path.dirname (self.default_database), exist_ok = True)

        #self.zodb_storage = ZODB.FileStorage.FileStorage (self.default_database)
        self.zodb_storage = ClientStorage.ClientStorage(self.default_database)
        self.zodb = ZODB.DB(self.zodb_storage)
Ejemplo n.º 6
0
 def __init__(self, connectSpecs, root='pps_store'):
     storage = ClientStorage.ClientStorage(connectSpecs)
     db = ZODB.DB(storage)
     self.__conn = db.open()
     dbroot = self.__conn.root()
     if not dbroot.has_key(root):
         dbroot[root] = BTrees.OOBTree.OOBTree()
         get_transaction().commit()
     self.__db = dbroot[root]
Ejemplo n.º 7
0
    def __init__(self, minfo):
        self.connection = None
        self.root = None

        self.storage = ClientStorage.ClientStorage(
            minfo.getRoomBookingDBConnectionParams(),
            username=minfo.getRoomBookingDBUserName(),
            password=minfo.getRoomBookingDBPassword(),
            realm=minfo.getRoomBookingDBRealm())
        self.db = DB(self.storage)
Ejemplo n.º 8
0
def ZKClientStorage(zkaddr, path, *args, **kw):
    zk = zc.zk.ZooKeeper(zkaddr)
    ppath = path + PROVIDERS
    addresses = zk.children(ppath)

    blob_addresses = zk.children(path + '/blobs' + PROVIDERS)
    blob_servers = []

    @blob_addresses
    def update_blob_servers(addrs):
        blob_servers[:] = ['http://%s/' % addr for addr in addrs]

    wait = kw.get('wait', kw.get('wait_for_server_on_startup', True))

    # XXX lots of underware here
    client = ClientStorage(
        zc.zkzeo._client._wait_addresses(
            addresses, zc.zkzeo._client.parse_addr, zkaddr, ppath, wait),
        blob_servers,
        *args, **kw)
    client.zookeeper_blob_addresses = blob_addresses
    return zc.zkzeo._client._client(addresses, client, zkaddr, ppath)
Ejemplo n.º 9
0
    def __init__(self, store_name = 'file:root.db', username='', passwd='', alt_connection=None):
        """Open the F2 object storage, returns the root_object. The store_name may have
           three forms: - file:<local pathname to file storage>
                        - rpc:<host_address>:<port_number>
                        - shared:
           In the 3rd case, a connection is already open on some storage, and is
           passed in parameter alt_connection.
        """
        self.db = None
        self.connection = None
        self.db_root = None

        if store_name.find(':') < 0:
            store_name = 'file:'+store_name

        if store_name[:5] == 'file:' :
            storage = FileStorage.FileStorage(store_name[5:])
            self.db = DB(storage)
            self.connection = self.db.open()
        
        elif store_name[:4] == 'rpc:' :
            server_addr = store_name[4:]
            if server_addr.find(':') >= 0 :
                serv_port = server_addr.split(':')
                serv_port[1] = int(serv_port[1])
                if not serv_port[0]:
                    serv_port[0] = '127.0.0.1'
            else:
                serv_port = [server_addr, 8080]
            storage = ClientStorage.ClientStorage(addr = tuple(serv_port),
                                                  username = username,
                                                  password = passwd)
            self.db = DB(storage)
            self.connection = self.db.open()
        
        elif store_name[:7] == 'shared:' :
            self.connection = alt_connection
            self.db = self.connection.db()
    
        else:
            # nothing known.
            raise F2StorageError('Unsupported storage type (file:, rpc:, or shared:).')
    
        self.db_root = self.connection.root()
        global currentOFFStore, db_root
        currentOFFStore = self     # short circuit on current store for bootstrap
        db_root = self.db_root
        
        if 'F2_Signature' not in self.db_root:
            raise F2StorageError("Empty F2 storage, run the bootstrap process (bootf2.py) before usage.")
Ejemplo n.º 10
0
    def __init__(self, directory=None, server=None):
        self.directory = directory
        if directory:
            if not os.path.isdir(directory):
                os.mkdir(directory)
            blobdir = os.path.join(directory, 'blobstorage')
            if not os.path.isdir(blobdir):
                os.mkdir(blobdir)
            storage = FileStorage(os.path.join(directory, 'zgraph.db'),
                                  blob_dir=blobdir)
        elif server:
            storage = ClientStorage.ClientStorage(server)
        else:
            raise Exception("Can't create storage")

        self.storage = storage
        self.db = ZODB.DB(self.storage, large_record_size=16777216 * 2)
        self.connection = self.db.open()
        self.root = self.connection.root

        if not getattr(self.root, '_initialized', False):
            print 'Initializing ZGraph in', self.directory
            self.root.nodes = IOBTree.IOBTree()
            self.root.edges = IOBTree.IOBTree()
            self.root._edgeid = Length()
            self.root._nodeid = Length()
            self.root.nodecatalog = Catalog(object_store=self.root.nodes)
            self.root.edgecatalog = Catalog(object_store=self.root.edges)
            self.root._initialized = True

        if not hasattr(self.root, 'typeids'):
            print 'adding Graphagus'
            self.addGraphagus()

        self.nodes = self.root.nodes
        self.edges = self.root.edges
        self._edgeid = self.root._edgeid
        self._nodeid = self.root._nodeid
        self.nodecatalog = self.root.nodecatalog
        self.edgecatalog = self.root.edgecatalog

        self.outbytype = self.root.outbytype
        self.inbytype = self.root.inbytype
        self.outbysource = self.root.outbysource
        self.inbytarget = self.root.inbytarget

        self._typeid = self.root._typeid
        self.typeids = self.root.typeids
        self.revtypes = self.root.revtypes
Ejemplo n.º 11
0
def client_storage(sock, *args, **kw):
    """
    Storage client

    :param sock: UNIX or TCP socket
    :param cipher: Encryptor to use (see zerodb.crypto)
    :param bool debug: Output debug messages to the log
    :param transforming_storage: Wrapper-storage to use (TransformingStorage)
    :returns: Storage
    :rtype: TransformingStorage
    """
    if six.PY2 and isinstance(sock, unicode):
        sock = str(sock)
    TransformingStorage = kw.pop('transforming_storage',
                                 transforming.TransformingStorage)
    debug = kw.pop("debug", False)
    return TransformingStorage(ClientStorage(sock, *args, **kw), debug=debug)
Ejemplo n.º 12
0
Archivo: q_db.py Proyecto: akirav/qplan
    def __init__(self, logger, addr):
        self.logger = logger
        #storage = FileStorage.FileStorage(dbfile)
        self.storage = ClientStorage.ClientStorage(addr)
        self.db = DB(self.storage)

        self.conn = self.db.open()
        self.dbroot = self.conn.root()

        # Check whether database is initialized
        for name in [
                'program', 'ob', 'executed_ob', 'exposure', 'saved_state'
        ]:
            key = '%s_db' % name
            if key not in self.dbroot:
                tbl = OOBTree()
                self.dbroot[key] = tbl

                transaction.commit()

        if 'queue_mgmt' not in self.dbroot:
            self.dbroot['queue_mgmt'] = QueueMgmtRec()
            transaction.commit()
Ejemplo n.º 13
0
from ZEO import ClientStorage
from ZODB.FileStorage import FileStorage
from pathquery import PathQuery as pq

runs = int(sys.argv[1])
dbtype = sys.argv[2]

if dbtype.startswith('f'):
    storage = FileStorage('Data.fs')
else:
    clientid = sys.argv[3]
    addr = ('localhost', 1234)
    #storage = ClientStorage.ClientStorage(addr,cache_size=2048*1024*1024,client='shm/p_gclient' +clientid)
    storage = ClientStorage.ClientStorage(addr,
                                          cache_size=512 * 1024 * 1024,
                                          client='querykmcache' + clientid)
    #storage = ClientStorage.ClientStorage(addr,cache_size=0)
    #storage = ClientStorage.ClientStorage(addr)

#db = DB(storage,cache_size=1000000,cache_size_bytes=1024*1024*124)
db = DB(storage, cache_size=200000,
        cache_size_bytes=1024 * 1024 * 124)  #this uses 0.03 secs
#db = DB(storage)
connection = db.open()
root = connection.root()
g = root['graphdb']

fixedtarget = None
maxnum = 1000
def patched_loadBlob(self, oid, serial):
    # Load a blob.  If it isn't present and we have a shared blob
    # directory, then assume that it doesn't exist on the server
    # and return None.

    if self.fshelper is None:
        raise Unsupported("No blob cache directory is configured.")

    blob_filename = self.fshelper.getBlobFilename(oid, serial)
    if self.shared_blob_dir:
        if os.path.exists(blob_filename):
            return blob_filename
        else:
            # create empty file
            create_empty_blob(blob_filename)
        if os.path.exists(blob_filename):
            return blob_filename
        else:
            # We're using a server shared cache.  If the file isn't
            # here, it's not anywhere.
            raise POSKeyError("No blob file", oid, serial)

    if os.path.exists(blob_filename):
        return ClientStorage._accessed(blob_filename)
    else:
        # create empty file
        create_empty_blob(blob_filename)

    if os.path.exists(blob_filename):
        return ClientStorage._accessed(blob_filename)

    # First, we'll create the directory for this oid, if it doesn't exist.
    self.fshelper.createPathForOID(oid)

    # OK, it's not here and we (or someone) needs to get it.  We
    # want to avoid getting it multiple times.  We want to avoid
    # getting it multiple times even accross separate client
    # processes on the same machine. We'll use file locking.

    lock = ClientStorage._lock_blob(blob_filename)
    try:
        # We got the lock, so it's our job to download it.  First,
        # we'll double check that someone didn't download it while we
        # were getting the lock:

        if os.path.exists(blob_filename):
            return ClientStorage._accessed(blob_filename)

        # Ask the server to send it to us.  When this function
        # returns, it will have been sent. (The recieving will
        # have been handled by the asyncore thread.)

        self._server.sendBlob(oid, serial)

        if os.path.exists(blob_filename):
            return ClientStorage._accessed(blob_filename)

        raise POSKeyError("No blob file", oid, serial)

    finally:
        lock.close()
Ejemplo n.º 15
0
import graphagus, sys, random, time, transaction
from ZODB import DB

from ZEO import ClientStorage
from ZODB.FileStorage import FileStorage

dbtype = sys.argv[1]
if dbtype.startswith('f'):
    if len(sys.argv) > 2:
        filename = sys.argv[2]
    else:
        filename = 'Data.fs'
    storage = FileStorage(filename)
else:
    if len(sys.argv) > 2:
        clientid = sys.argv[2]
    else:
        clientid = '1'
    addr = ('localhost', 1234)
    storage = ClientStorage.ClientStorage(addr,
                                          cache_size=1024 * 1024 * 1024,
                                          client='console_cache' + clientid)
db = DB(storage)
connection = db.open()
root = connection.root()
try:
    g = root['graphdb']
except:
    pass
Ejemplo n.º 16
0
 def opendb(self):
     addr = (self.options.host, self.options.port)
     self._storage = ClientStorage.ClientStorage(addr)
     self.db = DB(self._storage)
     self.poollock = Lock()
Ejemplo n.º 17
0
def DB(*args, **kw):
    import ZODB
    return ZODB.DB(ClientStorage(*args, **kw))
Ejemplo n.º 18
0
from ZODB.FileStorage import FileStorage

dbtype = sys.argv[1]
if dbtype.startswith('f'):
    if len(sys.argv)>2:
        filename=sys.argv[2]
    else:
        filename='Test.fs'
    storage = FileStorage(filename)
else:
    if len(sys.argv)>2:
        clientid=sys.argv[2]
    else:
        clientid='1'
    addr = ('localhost',1234)        
    storage = ClientStorage.ClientStorage(addr,cache_size=1024*1024*1024,client='testcache' +clientid)   
db = DB(storage)
connection = db.open()
root = connection.root()

if 1 or not root.has_key('graphdb'):
    root['graphdb']=p_g.GraphDB()
g=root['graphdb']

g.node_catalog['name']=p_g.CatalogFieldIndex(p_g.get_key('name'))
g.node_catalog['lastname']=p_g.CatalogFieldIndex(p_g.get_key('lastname'))

likes = g.typeid('likes')

alice = g.addNode(name='alice')
bob = g.addNode(name='bob')
Ejemplo n.º 19
0
 def __init__(self, addr=('localhost', 9100)):
     self.addr = addr
     self.storage = ClientStorage.ClientStorage(self.addr)
     self.db = DB(self.storage)
     self.conn = self.db.open()
     self.root = self.conn.root()
Ejemplo n.º 20
0
 def __init__(self, storage_name=('localhost', 9100)):
     self.storage = ClientStorage.ClientStorage(storage_name)
     self.db = DB(self.storage)
     self.connection = self.open_connection(self.db)
     self.root = self.get_root(self.connection)
Ejemplo n.º 21
0
"""creates the battle log object. VERY DESTRUCTIVE."""
from ZEO import ClientStorage
from ZODB import DB
import transaction
import persistent.mapping
#from equanimity.world import wField, wPlayer, World

addr = 'localhost', 9101
storage = ClientStorage.ClientStorage(addr)
db = DB(storage)
conn = db.open()
logs = conn.root()


#TODO: index logs by when and where the battle happened.
def create():
    logs['battle'] = persistent.mapping.PersistentMapping()
    transaction.commit()
Ejemplo n.º 22
0
    # it if necessary.
    if not sessions.has_key(channelname):
        print 'Creating new session:', channelname
        sessions[channelname] = ChatSession(channelname)
        transaction.commit()

    session = sessions[channelname]
    return session


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'Usage: %s <channelname>' % sys.argv[0]
        sys.exit(0)

    storage = ClientStorage.ClientStorage(('localhost', 9672))
    db = ZODB.DB(storage)
    conn = db.open()

    s = session = get_chat_session(conn, sys.argv[1])

    messages = ['Hi.', 'Hello', 'Me too', "I'M 3L33T!!!!"]

    while 1:
        # Send a random message
        msg = random.choice(messages)
        session.add_message('%s: pid %i' % (msg, os.getpid()))

        # Display new messages
        for msg in session.new_messages():
            print msg