Commit 419f4b96 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

brainzfs: remove Main class and use functions only

parent 7de91390
......@@ -18,73 +18,69 @@ from translator import Translator
from schedu import Schedu
class Main:
"""Main class, that starts all other parts of the program"""
def _init_database(self, dbfile):
"""Initialize the database. Currently only sqlite
Arguments:
dbfile -- the path of the database
"""
database = 'sqlite:///'
engine = create_engine(database + dbfile,
connect_args={'check_same_thread':False},
#echo = True,
poolclass=StaticPool)
model.init_database(engine)
session_factory = sessionmaker(bind=engine)
session = scoped_session(session_factory)
if database == 'sqlite:///':
#dirty workaroud for sqlite non concurrent mode in python
#remove it once python supports fully concurrency in sqlite
self.session = sqlitequeue.get_Session(session)
else:
self.session = session
def main(self, 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")
parser.add_argument('--version', '-V', action='version',
version='%(prog)s {0}'.format(version))
parser.add_argument('sourcedir', help="filepath of source file directory")
parser.add_argument('mountpoint', help="where it should be mounted")
parser.add_argument('--verbose', '-v', action="store_true", default=False,
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")
arg = parser.parse_args(args[1:])
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-5s %(name)-18s %(message)s',
datefmt='%y-%m-%d %H:%M')
logger = logging.getLogger('main')
logger.info("initializing database")
self._init_database(arg.database)
logger.info("database initialized")
collector = Collector(self.session)
collector.start()
schedu = Schedu(self.session, arg.sourcedir)
schedu.start()
#from model import Recording
#from mbdata.models import Release, ReleaseGroup, Track, Artist, ArtistCredit, ArtistCreditName, Medium
#from sqlalchemy.sql import select
#se = self.session()
#from utils import debug_breakpoint
#debug_breakpoint()
translator = Translator(self.session, arg.mountpoint)
translator.start()
collector.join()
translator.join()
def _init_database(dbfile):
"""Initialize the database. Currently only sqlite
Arguments:
dbfile -- the path of the database
"""
database = 'sqlite:///'
engine = create_engine(database + dbfile,
connect_args={'check_same_thread':False},
#echo = True,
poolclass=StaticPool)
model.init_database(engine)
session_factory = sessionmaker(bind=engine)
session = scoped_session(session_factory)
if database == 'sqlite:///':
#dirty workaroud for sqlite non concurrent mode in python
#remove it once python supports fully concurrency in sqlite
session = sqlitequeue.get_Session(session)
return session
def main(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")
parser.add_argument('--version', '-V', action='version',
version='%(prog)s {0}'.format(version))
parser.add_argument('sourcedir', help="filepath of source file directory")
parser.add_argument('mountpoint', help="where it should be mounted")
parser.add_argument('--verbose', '-v', action="store_true", default=False,
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")
arg = parser.parse_args(args[1:])
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-5s %(name)-18s %(message)s',
datefmt='%y-%m-%d %H:%M')
logger = logging.getLogger('main')
logger.info("initializing database")
session = _init_database(arg.database)
logger.info("database initialized")
collector = Collector(session)
collector.start()
schedu = Schedu(session, arg.sourcedir)
schedu.start()
#from model import Recording
#from mbdata.models import Release, ReleaseGroup, Track, Artist, ArtistCredit, ArtistCreditName, Medium
#from sqlalchemy.sql import select
#se = self.session()
#from utils import debug_breakpoint
#debug_breakpoint()
translator = Translator(session, arg.mountpoint)
translator.start()
collector.join()
translator.join()
if __name__ == "__main__":
Main().main(sys.argv)
main(sys.argv)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment