def __init__(self): super(SmewtDaemon, self).__init__() # Note: put log file in data dir instead of log dir so that it is # accessible through the user/ folder static view self.logfile = utils.path(smewt.dirs.user_data_dir, "Smewt.log") setupLogging(filename=self.logfile, with_time=True, with_thread=True) if smewt.config.PERSISTENT_CACHE: self.loadCache() # get a TaskManager for all the import tasks self.taskManager = TaskManager() # get our main graph DB self.loadDB() # get our collections: series and movies for now self.episodeCollection = Collection( name="Series", # import episodes and their subtitles too validFiles=[Episode.isValidEpisode, Subtitle.isValidSubtitle], mediaTagger=EpisodeTagger, dataGraph=self.database, taskManager=self.taskManager, ) self.movieCollection = Collection( name="Movie", # import movies and their subtitles too validFiles=[Movie.isValidMovie, Subtitle.isValidSubtitle], mediaTagger=MovieTagger, dataGraph=self.database, taskManager=self.taskManager, ) if config.REGENERATE_THUMBNAILS: # launch the regeneration of the thumbnails, but only after everything # is setup and we are able to serve requests Timer(3, self.regenerateSpeedDialThumbnails).start() if self.database.config.get("tvuMldonkeyPlugin"): # load up the feed watcher self.feedWatcher = FeedWatcher(self) # FIXME: this should go into a plugin.init() method from smewt.plugins import mldonkey mldonkey.send_command("vm") # do not rescan as it would be too long and we might delete some files that # are on an unaccessible network share or an external HDD self.taskManager.add(FuncTask("Update collections", self.updateCollections))
class SmewtDaemon(object): def __init__(self): super(SmewtDaemon, self).__init__() # Note: put log file in data dir instead of log dir so that it is # accessible through the user/ folder static view self.logfile = utils.path(smewt.dirs.user_data_dir, "Smewt.log") setupLogging(filename=self.logfile, with_time=True, with_thread=True) if smewt.config.PERSISTENT_CACHE: self.loadCache() # get a TaskManager for all the import tasks self.taskManager = TaskManager() # get our main graph DB self.loadDB() # get our collections: series and movies for now self.episodeCollection = Collection( name="Series", # import episodes and their subtitles too validFiles=[Episode.isValidEpisode, Subtitle.isValidSubtitle], mediaTagger=EpisodeTagger, dataGraph=self.database, taskManager=self.taskManager, ) self.movieCollection = Collection( name="Movie", # import movies and their subtitles too validFiles=[Movie.isValidMovie, Subtitle.isValidSubtitle], mediaTagger=MovieTagger, dataGraph=self.database, taskManager=self.taskManager, ) if config.REGENERATE_THUMBNAILS: # launch the regeneration of the thumbnails, but only after everything # is setup and we are able to serve requests Timer(3, self.regenerateSpeedDialThumbnails).start() if self.database.config.get("tvuMldonkeyPlugin"): # load up the feed watcher self.feedWatcher = FeedWatcher(self) # FIXME: this should go into a plugin.init() method from smewt.plugins import mldonkey mldonkey.send_command("vm") # do not rescan as it would be too long and we might delete some files that # are on an unaccessible network share or an external HDD self.taskManager.add(FuncTask("Update collections", self.updateCollections)) def quit(self): log.info("SmewtDaemon quitting...") self.taskManager.finishNow() try: self.feedWatcher.quit() except AttributeError: pass self.saveDB() if smewt.config.PERSISTENT_CACHE: self.saveCache() log.info("SmewtDaemon quitting OK!") def _cacheFilename(self): return utils.path(smewt.dirs.user_cache_dir, "Smewt.cache", createdir=True) def loadCache(self): cache.load(self._cacheFilename()) def saveCache(self): cache.save(self._cacheFilename()) def clearCache(self): cache.clear() cacheFile = self._cacheFilename() log.info("Deleting cache file: %s" % cacheFile) try: os.remove(cacheFile) except OSError: pass def loadDB(self): dbfile = smewt.settings.get("database_file") if not dbfile: dbfile = utils.path(smewt.dirs.user_data_dir, "Smewt.database", createdir=True) smewt.settings.set("database_file", dbfile) log.info("Loading database from: %s", dbfile) self.database = VersionedMediaGraph() try: self.database.load(dbfile) except: log.warning("Could not load database %s", dbfile) def saveDB(self): dbfile = smewt.settings.get("database_file") log.info("Saving database to %s", dbfile) self.database.save(dbfile) def clearDB(self): log.info("Clearing database...") self.database.clear_keep_config() self.database.save(smewt.settings.get("database_file")) def updateCollections(self): self.episodeCollection.update() self.movieCollection.update() def rescanCollections(self): self.episodeCollection.rescan() self.movieCollection.rescan() def _regenerateSpeedDialThumbnails(self): import shlex, subprocess from PIL import Image from StringIO import StringIO webkit2png = subprocess.call(["which", "webkit2png"], stdout=subprocess.PIPE) == 0 if not webkit2png: log.warning( 'webkit2png not found. please run: "python setup.py install" from within the 3rdparty/webkit2png folder' ) return def gen(path, filename): width, height = 200, 150 log.info("Creating %dx%d screenshot for %s..." % (width, height, path)) filename = utils.path(smewt.dirs.user_data_dir, "speeddial", filename, createdir=True) cmd = 'webkit2png -g 1000 600 "http://localhost:6543%s"' % path screenshot, _ = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE).communicate() im = Image.open(StringIO(screenshot)) im.thumbnail((width, height), Image.ANTIALIAS) im.save(filename, "PNG") gen("/movies", "allmovies.png") gen("/movies/table", "moviestable.png") gen("/movies/recent", "recentmovies.png") gen("/series", "allseries.png") gen("/series/suggestions", "episodesuggestions.png") gen("/feeds", "feeds.png") def regenerateSpeedDialThumbnails(self): self.taskManager.add(FuncTask("Regenerate thumbnails", self._regenerateSpeedDialThumbnails))