Example #1
0
File: db.py Project: hswick/yokadi
 def checkVersion(self):
     """Check version and exit if it is not suitable"""
     version = self.getVersion()
     if version != DB_VERSION:
         sharePath = os.path.abspath(utils.shareDirPath())
         tui.error("Your database version is %d but Yokadi wants version %d." \
             % (version, DB_VERSION))
         print("Please, run the %s/update/update.py script to migrate your database prior to running Yokadi" % \
                 sharePath)
         print("See %s/doc/update.md for details" % sharePath)
         sys.exit(1)
Example #2
0
def connectDatabase(dbFileName, createIfNeeded=True, memoryDatabase=False):
    """Connect to database and create it if needed
    @param dbFileName: path to database file
    @type dbFileName: str
    @param createIfNeeded: Indicate if database must be created if it does not exists (default True)
    @type createIfNeeded: bool
    @param memoryDatabase: create db in memory. Only usefull for unit test. Default is false.
    @type memoryDatabase: bool
    """

    dbFileName = os.path.abspath(dbFileName)

    if sys.platform == 'win32':
        connectionString = 'sqlite:/' + dbFileName[0] + '|' + dbFileName[2:]
    else:
        connectionString = 'sqlite:' + dbFileName

    if memoryDatabase:
        connectionString = "sqlite:/:memory:"

    connection = connectionForURI(connectionString)
    sqlhub.processConnection = connection

    if not os.path.exists(dbFileName) or memoryDatabase:
        if createIfNeeded:
            print "Creating database"
            createTables()
            # Set database version according to current yokadi release
            Config(name=DB_VERSION_KEY,
                   value=str(DB_VERSION),
                   system=True,
                   desc="Database schema release number")
        else:
            print "Database file (%s) does not exist or is not readable. Exiting" % dbFileName
            sys.exit(1)

    # Check version
    version = getVersion()
    if version != DB_VERSION:
        sharePath = os.path.abspath(utils.shareDirPath())
        tui.error("Your database version is %d but Yokadi wants version %d." \
            % (version, DB_VERSION))
        print "Please, run the %s/update/update.py script to migrate your database prior to running Yokadi" % \
                sharePath
        print "See %s/update/README.markdown for details" % sharePath
        sys.exit(1)
Example #3
0
File: db.py Project: bugzy/yokadi
def connectDatabase(dbFileName, createIfNeeded=True, memoryDatabase=False):
    """Connect to database and create it if needed
    @param dbFileName: path to database file
    @type dbFileName: str
    @param createIfNeeded: Indicate if database must be created if it does not exists (default True)
    @type createIfNeeded: bool
    @param memoryDatabase: create db in memory. Only usefull for unit test. Default is false.
    @type memoryDatabase: bool
    """

    dbFileName = os.path.abspath(dbFileName)

    if sys.platform == 'win32':
        connectionString = 'sqlite:/' + dbFileName[0] + '|' + dbFileName[2:]
    else:
        connectionString = 'sqlite:' + dbFileName

    if memoryDatabase:
        connectionString = "sqlite:/:memory:"

    connection = connectionForURI(connectionString)
    sqlhub.processConnection = connection

    if not os.path.exists(dbFileName) or memoryDatabase:
        if createIfNeeded:
            print "Creating database"
            createTables()
            # Set database version according to current yokadi release
            Config(name=DB_VERSION_KEY, value=str(DB_VERSION), system=True, desc="Database schema release number")
        else:
            print "Database file (%s) does not exist or is not readable. Exiting" % dbFileName
            sys.exit(1)

    # Check version
    version = getVersion()
    if version != DB_VERSION:
        sharePath = os.path.abspath(utils.shareDirPath())
        tui.error("Your database version is %d but Yokadi wants version %d." \
            % (version, DB_VERSION))
        print "Please, run the %s/update/update.py script to migrate your database prior to running Yokadi" % \
                sharePath
        print "See %s/update/README.markdown for details" % sharePath
        sys.exit(1)