@@ -18,18 +18,32 @@ from collector import Collector
fromtranslatorimportTranslator
fromscheduimportSchedu
version="0.1-alpha"
schema_version=1
def_init_database(dbfile):
def_init_database(dbfile,migrate=False):
"""Initialize the database. Currently only sqlite
Arguments:
dbfile -- the path of the database
"""
logger=logging.getLogger('main')
database='sqlite:///'
engine=create_engine(database+dbfile,
connect_args={'check_same_thread':False},
#echo = True,
poolclass=StaticPool)
db_version=model.get_version(engine)
ifdb_version>0anddb_version<schema_version:
ifmigrate:
model.migrate(engine,db_version,schema_version)
else:
logger.error('Your database is too old for this version of the program. Please apply the "--migrate" flag to migrate the database to the new version. This process is not invertable.')
sys.exit(1)
ifschema_version<db_version:
logger.error('Your database was created by a newer version of this program and is incompatible with this version. Please update your program.')
sys.exit(1)
model.init_database(engine)
session_factory=sessionmaker(bind=engine)
session=scoped_session(session_factory)
...
...
@@ -37,6 +51,7 @@ def _init_database(dbfile):
#dirty workaroud for sqlite non concurrent mode in python
#remove it once python supports fully concurrency in sqlite
session=sqlitequeue.get_Session(session)
model.write_version(session,schema_version)
returnsession
...
...
@@ -55,7 +70,6 @@ def check(opt, f):
defmain(args):
"""Main method. Parses cmdline arguments and starts the program."""
version="0.1-alpha"
parser=argparse.ArgumentParser(add_help=True,
description="Create a directory structure of music with" \
"symlinks based on musicbrainz data. Setting commandline options is only temporary. Change the config file to set option permanently.")
...
...
@@ -67,6 +81,7 @@ def main(args):
help="change to loglevel to info")
parser.add_argument('--database','-d',default="music.db",help="path of the database")
parser.add_argument('--logfile','-l',help="log into a logfile")
parser.add_argument('--migrate','-m',action="store_true",default=False,help="migrate to a newer database schema. This cannot be undone.")