Ejemplo n.º 1
0
 def open(self):
     '''
     Abre la conexion con la base de datos.
     @return: 
     @author: 
     '''
     self.db = config.databaseFromURL(self.url)
     self.conexion = self.db.open()
     self.raiz = self.conexion.root()
Ejemplo n.º 2
0
 def __new__(self, *args, **kwargs):
     db = None
     if 'string' in kwargs:
         db = config.databaseFromString(kwargs['string'])
     if 'file' in kwargs:
         db = config.databaseFromFile(kwargs['file'])
     if 'url' in kwargs:
         db = config.databaseFromURL(kwargs['url'])
     if not db:
         raise ValueError('unable to obtain ZODB object from arguments')
     alsoProvides(db, IZODBDatabase)
     return db
Ejemplo n.º 3
0
    def __init__(self):
        '''
        Constructor, se conecta al Servidor de la BD a través del archivo de configuracion zeo.conf
        en donde se indica la IP:PORT.
        @return: 
        @author: 
        '''
#        self.url = url
        self.url = 'zeo.conf'
        self.db = config.databaseFromURL(self.url)
        self.conexion = self.db.open()
        self.raiz = self.conexion.root()
Ejemplo n.º 4
0
 def __new__(self, *args, **kwargs):
     db = None
     if 'string' in kwargs:
         db = config.databaseFromString(kwargs['string'])
     if 'file' in kwargs:
         db = config.databaseFromFile(kwargs['file'])
     if 'url' in kwargs:
         db = config.databaseFromURL(kwargs['url'])
     if not db:
         raise ValueError('unable to obtain ZODB object from arguments')
     alsoProvides(db, IZODBDatabase)
     return db
Ejemplo n.º 5
0
def establish_bokeep_db(mainwindow, config_path, config, db_exception):
    """Dialog to edit the configuration settings for a BoKeep database, 
    create it at the configured location if not there yet, and also
    exercise control over other settings kept in the bokeep configuration
    (.bo-keep.cfg), and basic things like creating books and enabling
    plugins.

    And the best part is that a BoKeepBookSet for whichever database
    you choose to select (in this dialog) is returned or None
    if this fails

    mainwindow -- if there's a Gtk.Window we can parrent this dialog too,
                  please provide it, otherwise set to None
    config_path -- path the configuration file is found at
    config     -- a  ConfigParser.ConfigParser pre-loaded with the contents
                  of config_path .
    db_exception -- If you experienced some kind of exception while
                    trying to load the BoKeepBookSet without the help of a
                    this function, pass it on to us so we can display
                    the error to the user so they know why they're
                    being forced into a gui to fix things up

    Changes made to config are saved in config_path
    """
    assert(db_exception == None or
           isinstance(db_exception, BoKeepConfigurationDatabaseException))
    if db_exception == None:
        extra_error_info = None
    else:
        extra_error_info = "%s\n%s" %(
            str(db_exception), 
            "BoKeep requires a working database to operate" )
    
    if config.has_option(ZODB_CONFIG_SECTION, ZODB_CONFIG_FILESTORAGE):
        db_access_method = ZODB_CONFIG_FILESTORAGE
        db_path = config.get(ZODB_CONFIG_SECTION, ZODB_CONFIG_FILESTORAGE)
    elif config.has_option(ZODB_CONFIG_SECTION, ZODB_CONFIG_ZCONFIG):
        db_access_method = ZODB_CONFIG_ZCONFIG
        db_path = config.get(ZODB_CONFIG_SECTION, ZODB_CONFIG_ZCONFIG)
    config_dialog = BoKeepConfigDialog(db_path, db_access_method,
                                       config_path, config,
                                       extra_error_info)
    result, new_db_path, new_db_access_method = config_dialog.run()
    
    assert( result == RESPONSE_OK or result==RESPONSE_CANCEL or
            result==RESPONSE_DELETE_EVENT )
    if new_db_path == None or result!=RESPONSE_OK:
        return None

    # should save new_db_path in config if different
    if new_db_path != db_path or \
            new_db_access_method != db_access_method:
        if new_db_access_method == ZODB_CONFIG_FILESTORAGE:
            config.set(ZODB_CONFIG_SECTION, ZODB_CONFIG_FILESTORAGE,
                       new_db_path)
            config.remove_option(ZODB_CONFIG_SECTION, ZODB_CONFIG_ZCONFIG)
        elif new_db_access_method == ZODB_CONFIG_ZCONFIG:
            config.set(ZODB_CONFIG_SECTION, ZODB_CONFIG_ZCONFIG,
                       new_db_path)
            config.remove_option(ZODB_CONFIG_SECTION, ZODB_CONFIG_FILESTORAGE)
        config_fp = file(config_path, 'w')
        config.write(config_fp)
        config_fp.close()

    if new_db_access_method == ZODB_CONFIG_FILESTORAGE:
        return BoKeepBookSet(DB(FileStorage(new_db_path, create=False)))
    elif new_db_access_method == ZODB_CONFIG_ZCONFIG:
        return BoKeepBookSet(databaseFromURL(new_db_path))
Ejemplo n.º 6
0
 def __init__(self):
     self.db = config.databaseFromURL('references.conf')
     self.conn = self.db.open()
     self.root = self.conn.root()