Esempio n. 1
0
def ctmain():
    utils.fix_output_encoding()
    settings = ComicTaggerSettings()

    opts = Options()
    opts.parseCmdLineArgs()

    # manage the CV API key
    if opts.cv_api_key:
        if opts.cv_api_key != settings.cv_api_key:
            settings.cv_api_key = opts.cv_api_key
            settings.save()
    if opts.only_set_key:
        print("Key set")
        return

    ComicVineTalker.api_key = settings.cv_api_key

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    if not qt_available and not opts.no_gui:
        opts.no_gui = True
        print >> sys.stderr, "PyQt4 is not available.  ComicTagger is limited to command-line mode."

    if opts.no_gui:
        cli.cli_mode(opts, settings)
    else:
        app = QtGui.QApplication(sys.argv)

        if platform.system() != "Linux":
            img = QtGui.QPixmap(ComicTaggerSettings.getGraphic('tags.png'))

            splash = QtGui.QSplashScreen(img)
            splash.show()
            splash.raise_()
            app.processEvents()

        try:
            tagger_window = TaggerWindow(opts.file_list, settings, opts=opts)
            tagger_window.show()

            if platform.system() != "Linux":
                splash.finish(tagger_window)

            sys.exit(app.exec_())
        except Exception as e:
            QtGui.QMessageBox.critical(
                QtGui.QMainWindow(),
                "Error",
                "Unhandled exception in app:\n" +
                traceback.format_exc())
Esempio n. 2
0
def ctmain():
    utils.fix_output_encoding()
    settings = ComicTaggerSettings()

    opts = Options()
    opts.parseCmdLineArgs()

    # manage the CV API key
    if opts.cv_api_key:
        if opts.cv_api_key != settings.cv_api_key:
            settings.cv_api_key = opts.cv_api_key
            settings.save()
    if opts.only_set_key:
        print "Key set"
        return

    ComicVineTalker.api_key = settings.cv_api_key

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    if not qt_available and not opts.no_gui:
        opts.no_gui = True
        print "PyQt4 is not available.  ComicTagger is limited to command-line mode."

    if opts.no_gui:
        cli.cli_mode(opts, settings)
    else:
        app = QtGui.QApplication(sys.argv)

        if platform.system() != "Linux":
            img = QtGui.QPixmap(ComicTaggerSettings.getGraphic('tags.png'))

            splash = QtGui.QSplashScreen(img)
            splash.show()
            splash.raise_()
            app.processEvents()

        try:
            tagger_window = TaggerWindow(opts.file_list, settings, opts=opts)
            tagger_window.show()

            if platform.system() != "Linux":
                splash.finish(tagger_window)

            sys.exit(app.exec_())
        except Exception, e:
            QtGui.QMessageBox.critical(
                QtGui.QMainWindow(), "Error",
                "Unhandled exception in app:\n" + traceback.format_exc())
Esempio n. 3
0
        logging.info("Monitor: Added {0} comics".format(self.add_count))
        logging.info("Monitor: Removed {0} comics".format(self.remove_count))
            
        if self.quit_when_done:
            self.quit = True

    def doEventProcessing(self, eventList):
        logging.debug(u"Monitor: event_list:{0}".format(eventList))

        
if __name__ == '__main__':
    
    if len(sys.argv) < 2:
        print >> sys.stderr, "usage:  {0} comic_folder ".format(sys.argv[0])
        sys.exit(-1)    

    
    utils.fix_output_encoding()
    
    dm = DataManager()
    dm.create()
    m = Monitor(dm, sys.argv[1:])
    m.quit_when_done = True
    m.start()
    m.scan()

    #while True:
    #   time.sleep(10)

    m.stop()
Esempio n. 4
0
    def __init__(self, config, opts):
        utils.fix_output_encoding()   
        
        self.config = config
        self.opts = opts
        
        self.port = self.config['general']['port']
        self.webroot = self.config['general']['webroot']
        
        self.comicArchiveList = []
        
        #if len(self.config['general']['folder_list']) == 0:
        #    logging.error("No folders on either command-line or config file.  Quitting.")
        #    sys.exit(-1)
        
        self.dm = DataManager()
        self.library = Library(self.dm.Session)
        
        if opts.reset or opts.reset_and_run:
            logging.info( "Deleting any existing database!")
            self.dm.delete()
            
        # quit on a standard reset
        if opts.reset:
            sys.exit(0)
            
        try:
            self.dm.create()
        except SchemaVersionException as e:
            msg = "Couldn't open database.  Probably the schema has changed."
            logging.error(msg)
            utils.alert("Schema change", msg)
            sys.exit(-1)
            
        
        try:
            self.listen(self.port, no_keep_alive = True)
        except Exception as e:
            logging.error(e)
            msg = "Couldn't open socket on port {0}.  (Maybe ComicStreamer is already running?)  Quitting.".format(self.port)
            logging.error(msg)
            utils.alert("Port not available", msg)
            sys.exit(-1)

        logging.info( "Stream server running on port {0}...".format(self.port))
        
        #http_server = tornado.httpserver.HTTPServer(self, no_keep_alive = True, ssl_options={
        #    "certfile": "server.crt",
        #    "keyfile": "server.key",
        #})
        #http_server.listen(port+1)        
         
        self.version = csversion.version

        handlers = [
            # Web Pages
            (self.webroot + r"/", MainHandler),
            (self.webroot + r"/(.*)\.html", GenericPageHandler),
            (self.webroot + r"/about", AboutPageHandler),
            (self.webroot + r"/control", ControlPageHandler),
            (self.webroot + r"/configure", ConfigPageHandler),
            (self.webroot + r"/log", LogPageHandler),
            (self.webroot + r"/comiclist/browse", ComicListBrowserHandler),
            (self.webroot + r"/folders/browse(/.*)*", FoldersBrowserHandler),
            (self.webroot + r"/entities/browse(/.*)*", EntitiesBrowserHandler),
            (self.webroot + r"/comic/([0-9]+)/reader", ReaderHandler),
            (self.webroot + r"/login", LoginHandler),
            # Data
            (self.webroot + r"/dbinfo", DBInfoAPIHandler),
            (self.webroot + r"/version", VersionAPIHandler),
            (self.webroot + r"/deleted", DeletedAPIHandler),
            (self.webroot + r"/comic/([0-9]+)", ComicAPIHandler),
            (self.webroot + r"/comiclist", ComicListAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/page/([0-9]+|clear)/bookmark", ComicBookmarkAPIHandler ),
            (self.webroot + r"/comic/([0-9]+)/page/([0-9]+)", ComicPageAPIHandler ),
            (self.webroot + r"/comic/([0-9]+)/thumbnail", ThumbnailAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/file", FileAPIHandler),
            (self.webroot + r"/entities(/.*)*", EntityAPIHandler),
            (self.webroot + r"/folders(/.*)*", FolderAPIHandler),
            (self.webroot + r"/command", CommandAPIHandler),
            (self.webroot + r"/scanstatus", ScanStatusAPIHandler),
            #(r'/favicon.ico', tornado.web.StaticFileHandler, {'path': os.path.join(AppFolders.appBase(), "static","images")}),
            (self.webroot + r'/.*', UnknownHandler),
            
        ]

        settings = dict(
            template_path=os.path.join(AppFolders.appBase(), "templates"),
            static_path=os.path.join(AppFolders.appBase(), "static"),
            static_url_prefix=self.webroot + "/static/",
            debug=True,
            #autoreload=False,
            login_url=self.webroot + "/login",
            cookie_secret=self.config['security']['cookie_secret'],
            xsrf_cookies=True,
        )

        tornado.web.Application.__init__(self, handlers, **settings)

        if not opts.no_monitor:     
            logging.debug("Going to scan the following folders:")
            for l in self.config['general']['folder_list']:
                logging.debug(u"   {0}".format(repr(l)))

            self.monitor = Monitor(self.dm, self.config['general']['folder_list'])
            self.monitor.start()
            self.monitor.scan()
            
        self.bookmarker = Bookmarker(self.dm)
        self.bookmarker.start()

        if opts.launch_browser and self.config['general']['launch_browser']:
            if ((platform.system() == "Linux" and os.environ.has_key('DISPLAY')) or
                    (platform.system() == "Darwin" and not os.environ.has_key('SSH_TTY')) or
                    platform.system() == "Windows"):
                webbrowser.open("http://localhost:{0}".format(self.port), new=0)
Esempio n. 5
0
 def go(self):
     utils.fix_output_encoding()
     self.apiServer = None
     
     #Configure logging
     # root level        
     logger = logging.getLogger()    
     logger.setLevel(logging.DEBUG)
     formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
     
     log_file = os.path.join(AppFolders.logs(), "ComicStreamer.log")
     if not os.path.exists(os.path.dirname(log_file)):
         os.makedirs(os.path.dirname(log_file))
     fh = logging.handlers.RotatingFileHandler(log_file, maxBytes=1048576, backupCount=4, encoding="UTF8")
     fh.setLevel(logging.DEBUG)
     fh.setFormatter(formatter)
     logger.addHandler(fh)
     
     # By default only do info level to console
     sh = logging.StreamHandler(sys.stdout)
     sh.setLevel(logging.INFO)
     sh.setFormatter(formatter)
     logger.addHandler(sh)
 
     config = ComicStreamerConfig()
     opts = Options()
     opts.parseCmdLineArgs()
 
     # set file logging according to config file
     #fh.setLevel(config['general']['loglevel'])
         
     # turn up the log level, if requested
     if opts.debug:
         sh.setLevel(logging.DEBUG)
     elif opts.quiet:
         sh.setLevel(logging.CRITICAL)
 
     config.applyOptions(opts)
     
     self.apiServer = APIServer(config, opts)
 
     self.apiServer.logFileHandler = fh
     self.apiServer.logConsoleHandler = sh
     
     signal.signal(signal.SIGINT, self.signal_handler)
 
 
     bonjour = BonjourThread(self.apiServer.port)
     bonjour.start()
 
     if getattr(sys, 'frozen', None):
         # A frozen app will run a GUI
         self.apiServer.runInThread()
    
         logging.info("starting GUI loop")    
         if platform.system() == "Darwin":
             from gui_mac import MacGui
             MacGui(self.apiServer).run()
     
         elif platform.system() == "Windows":
             from gui_win import WinGui
             WinGui(self.apiServer).run()
             self.apiServer.shutdown()
     else:
         #from gui_qt import QtBasedGui
         #self.apiServer.runInThread()
         #QtBasedGui(self.apiServer).run()			
         #self.apiServer.shutdown()
         self.apiServer.run()
         
     logging.info("gui shoudld be done now")
Esempio n. 6
0
    def __init__(self, config, opts):
        utils.fix_output_encoding()

        self.config = config
        self.opts = opts

        self.port = self.config['general']['port']
        self.webroot = self.config['general']['webroot']

        self.comicArchiveList = []

        #if len(self.config['general']['folder_list']) == 0:
        #    logging.error("No folders on either command-line or config file.  Quitting.")
        #    sys.exit(-1)

        self.dm = DataManager()
        self.library = Library(self.dm.Session)

        if opts.reset or opts.reset_and_run:
            logging.info("Deleting any existing database!")
            self.dm.delete()

        # quit on a standard reset
        if opts.reset:
            sys.exit(0)

        try:
            self.dm.create()
        except SchemaVersionException as e:
            msg = "Couldn't open database.  Probably the schema has changed."
            logging.error(msg)
            utils.alert("Schema change", msg)
            sys.exit(-1)

        try:
            self.listen(self.port, no_keep_alive=True)
        except Exception as e:
            logging.error(e)
            msg = "Couldn't open socket on port {0}.  (Maybe ComicStreamer is already running?)  Quitting.".format(
                self.port)
            logging.error(msg)
            utils.alert("Port not available", msg)
            sys.exit(-1)

        logging.info("Stream server running on port {0}...".format(self.port))

        #http_server = tornado.httpserver.HTTPServer(self, no_keep_alive = True, ssl_options={
        #    "certfile": "server.crt",
        #    "keyfile": "server.key",
        #})
        #http_server.listen(port+1)

        self.version = csversion.version

        handlers = [
            # Web Pages
            (self.webroot + r"/", MainHandler),
            (self.webroot + r"/(.*)\.html", GenericPageHandler),
            (self.webroot + r"/about", AboutPageHandler),
            (self.webroot + r"/control", ControlPageHandler),
            (self.webroot + r"/configure", ConfigPageHandler),
            (self.webroot + r"/log", LogPageHandler),
            (self.webroot + r"/comiclist/browse", ComicListBrowserHandler),
            (self.webroot + r"/folders/browse(/.*)*", FoldersBrowserHandler),
            (self.webroot + r"/entities/browse(/.*)*", EntitiesBrowserHandler),
            (self.webroot + r"/comic/([0-9]+)/reader", ReaderHandler),
            (self.webroot + r"/login", LoginHandler),
            # Data
            (self.webroot + r"/dbinfo", DBInfoAPIHandler),
            (self.webroot + r"/version", VersionAPIHandler),
            (self.webroot + r"/deleted", DeletedAPIHandler),
            (self.webroot + r"/comic/([0-9]+)", ComicAPIHandler),
            (self.webroot + r"/comiclist", ComicListAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/page/([0-9]+|clear)/bookmark",
             ComicBookmarkAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/page/([0-9]+)",
             ComicPageAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/thumbnail", ThumbnailAPIHandler),
            (self.webroot + r"/comic/([0-9]+)/file", FileAPIHandler),
            (self.webroot + r"/entities(/.*)*", EntityAPIHandler),
            (self.webroot + r"/folders(/.*)*", FolderAPIHandler),
            (self.webroot + r"/command", CommandAPIHandler),
            (self.webroot + r"/scanstatus", ScanStatusAPIHandler),
            #(r'/favicon.ico', tornado.web.StaticFileHandler, {'path': os.path.join(AppFolders.appBase(), "static","images")}),
            (self.webroot + r'/.*', UnknownHandler),
        ]

        settings = dict(
            template_path=os.path.join(AppFolders.appBase(), "templates"),
            static_path=os.path.join(AppFolders.appBase(), "static"),
            static_url_prefix=self.webroot + "/static/",
            debug=True,
            #autoreload=False,
            login_url=self.webroot + "/login",
            cookie_secret=self.config['security']['cookie_secret'],
            xsrf_cookies=True,
        )

        tornado.web.Application.__init__(self, handlers, **settings)

        if not opts.no_monitor:
            logging.debug("Going to scan the following folders:")
            for l in self.config['general']['folder_list']:
                logging.debug(u"   {0}".format(repr(l)))

            self.monitor = Monitor(self.dm,
                                   self.config['general']['folder_list'])
            self.monitor.start()
            self.monitor.scan()

        self.bookmarker = Bookmarker(self.dm)
        self.bookmarker.start()

        if opts.launch_browser and self.config['general']['launch_browser']:
            if ((platform.system() == "Linux"
                 and os.environ.has_key('DISPLAY'))
                    or (platform.system() == "Darwin"
                        and not os.environ.has_key('SSH_TTY'))
                    or platform.system() == "Windows"):
                webbrowser.open("http://localhost:{0}".format(self.port),
                                new=0)
Esempio n. 7
0
        logging.info("Monitor: Added {0} comics".format(self.add_count))
        logging.info("Monitor: Removed {0} comics".format(self.remove_count))

        if self.quit_when_done:
            self.quit = True

    def doEventProcessing(self, eventList):
        logging.debug(u"Monitor: event_list:{0}".format(eventList))


if __name__ == '__main__':

    if len(sys.argv) < 2:
        print >> sys.stderr, "usage:  {0} comic_folder ".format(sys.argv[0])
        sys.exit(-1)

    utils.fix_output_encoding()

    dm = DataManager()
    dm.create()
    m = Monitor(dm, sys.argv[1:])
    m.quit_when_done = True
    m.start()
    m.scan()

    #while True:
    #   time.sleep(10)

    m.stop()
Esempio n. 8
0
    def go(self):
        utils.fix_output_encoding()
        self.apiServer = None

        opts = Options()
        opts.parseCmdLineArgs()

        #Configure logging
        # root level
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(message)s')

        log_file = os.path.join(AppFolders.logs(), "ComicStreamer.log")
        if not os.path.exists(os.path.dirname(log_file)):
            os.makedirs(os.path.dirname(log_file))
        fh = logging.handlers.RotatingFileHandler(log_file,
                                                  maxBytes=1048576,
                                                  backupCount=4,
                                                  encoding="UTF8")
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(formatter)
        logger.addHandler(fh)

        # By default only do info level to console
        sh = logging.StreamHandler(sys.stdout)
        sh.setLevel(logging.INFO)
        sh.setFormatter(formatter)
        logger.addHandler(sh)

        # set file logging according to config file
        #fh.setLevel(config['general']['loglevel'])

        # turn up the log level, if requested
        if opts.debug:
            sh.setLevel(logging.DEBUG)
        elif opts.quiet:
            sh.setLevel(logging.CRITICAL)
        config = ComicStreamerConfig()
        config.applyOptions(opts)

        self.apiServer = APIServer(config, opts)

        self.apiServer.logFileHandler = fh
        self.apiServer.logConsoleHandler = sh

        signal.signal(signal.SIGINT, self.signal_handler)

        if getattr(sys, 'frozen', None):
            # A frozen app will run a GUI
            self.apiServer.runInThread()

            logging.debug("UI: Started")
            if platform.system() == "Darwin":
                from gui_mac import MacGui
                MacGui(self.apiServer).run()

            elif platform.system() == "Windows":
                from gui_win import WinGui
                WinGui(self.apiServer).run()
                self.apiServer.shutdown()
        else:
            #from gui_qt import QtBasedGui
            #self.apiServer.runInThread()
            #QtBasedGui(self.apiServer).run()
            #self.apiServer.shutdown()
            self.apiServer.run()

        logging.info("UI: Stopped")