def on_gui_loaded(self): self.hooked = False self.resuming = False # # Initialize the player objects needed # self.player = player.player.ExailePlayer('preview_device') self.queue = player.queue.PlayQueue( self.player, location=os.path.join( xdg.get_data_dir(), 'preview_device_queue.state' ), name='Preview Device Queue' ) # # Initialize the GUI stuff # self._init_gui() # preserve state if settings.get_option('plugin/previewdevice/shown', True): self._init_gui_hooks()
def on_gui_loaded(self): self.hooked = False self.resuming = False # # Initialize the player objects needed # self.player = player.player.ExailePlayer('preview_device') self.queue = player.queue.PlayQueue(self.player, location=os.path.join( xdg.get_data_dir(), 'preview_device_queue.state'), name='Preview Device Queue') # # Initialize the GUI stuff # self._init_gui() # preserve state if settings.get_option('plugin/previewdevice/shown', True): self._init_gui_hooks()
def on_gui_loaded(self): save_on_exit = settings.get_option( 'plugin/history/save_on_exit', history_preferences.save_on_exit_default) shown = settings.get_option('plugin/history/shown', False) # immutable playlist that stores everything we've played self.history_loc = os.path.join(xdg.get_data_dir(), 'history') self.history_playlist = HistoryPlaylist(player.PLAYER) if save_on_exit: self.history_playlist.load_from_location(self.history_loc) self.history_page = HistoryPlaylistPage(self.history_playlist, player.PLAYER) self.history_tab = NotebookTab(main.get_playlist_notebook(), self.history_page) # add menu item to 'view' to display our playlist self.menu = menu.check_menu_item( 'history', '', _('Playback history'), lambda *e: self.is_shown(), self.on_playback_history, ) providers.register('menubar-view-menu', self.menu) # add the history playlist to the primary notebook if save_on_exit and shown: self.show_history(True)
def on_gui_loaded(self): save_on_exit = settings.get_option( 'plugin/history/save_on_exit', history_preferences.save_on_exit_default ) shown = settings.get_option('plugin/history/shown', False) # immutable playlist that stores everything we've played self.history_loc = os.path.join(xdg.get_data_dir(), 'history') self.history_playlist = HistoryPlaylist(player.PLAYER) if save_on_exit: self.history_playlist.load_from_location(self.history_loc) self.history_page = HistoryPlaylistPage(self.history_playlist, player.PLAYER) self.history_tab = NotebookTab(main.get_playlist_notebook(), self.history_page) # add menu item to 'view' to display our playlist self.menu = menu.check_menu_item( 'history', '', _('Playback history'), lambda *e: self.is_shown(), self.on_playback_history, ) providers.register('menubar-view-menu', self.menu) # add the history playlist to the primary notebook if save_on_exit and shown: self.show_history(True)
def quit(self, restart=False): """ Exits Exaile normally. Takes care of saving preferences, databases, etc. :param restart: Whether to directly restart :type restart: bool """ if self.quitting: return self.quitting = True logger.info("Exaile is shutting down...") logger.info("Disabling plugins...") for k, plugin in self.plugins.enabled_plugins.iteritems(): if hasattr(plugin, 'teardown'): try: plugin.teardown(self) except: pass from xl import event # this event should be used by modules that dont need # to be saved in any particular order. modules that might be # touched by events triggered here should be added statically # below. event.log_event("quit_application", self, None) logger.info("Saving state...") self.plugins.save_enabled() if self.gui: self.gui.quit() from xl import covers covers.MANAGER.save() self.collection.save_to_location() # Save order of custom playlists self.playlists.save_order() self.stations.save_order() # save player, queue from xl import player player.QUEUE._save_player_state( os.path.join(xdg.get_data_dir(), 'player.state') ) player.QUEUE.save_to_location( os.path.join(xdg.get_data_dir(), 'queue.state') ) player.PLAYER.stop() from xl import settings settings.MANAGER.save() if restart: logger.info("Restarting...") logger_setup.stop_logging() python = sys.executable if sys.platform == 'win32': # Python Win32 bug: it does not quote individual command line # arguments. Here we do it ourselves and pass the whole thing # as one string. # See https://bugs.python.org/issue436259 (closed wontfix). import subprocess cmd = [python] + sys.argv cmd = subprocess.list2cmdline(cmd) os.execl(python, cmd) else: os.execl(python, python, *sys.argv) logger.info("Bye!") logger_setup.stop_logging() sys.exit(0)
def __init(self): """ Initializes Exaile """ # pylint: disable-msg=W0201 logger.info("Loading Exaile %s on Python %s..." % (__version__, platform.python_version())) logger.info("Loading settings...") try: from xl import settings except common.VersionError: logger.exception("Error loading settings") sys.exit(1) logger.debug("Settings loaded from %s" % settings.location) # display locale information if available try: import locale lc, enc = locale.getlocale() if enc is not None: logger.info("Using %s %s locale" % (lc, enc)) else: logger.info("Using unknown locale") except: pass splash = None if self.options.StartGui: from xl import settings if settings.get_option('gui/use_splash', True): from xlgui.widgets.info import Splash splash = Splash() splash.show() firstrun = settings.get_option("general/first_run", True) if not self.options.NoImport and \ (firstrun or self.options.ForceImport): try: sys.path.insert(0, xdg.get_data_path("migrations")) import migration_200907100931 as migrator del sys.path[0] migrator.migrate(force=self.options.ForceImport) del migrator except: logger.exception("Failed to migrate from 0.2.14") # Migrate old rating options from xl.migrations.settings import rating rating.migrate() # Migrate builtin OSD to plugin from xl.migrations.settings import osd osd.migrate() # Migrate engines from xl.migrations.settings import engine engine.migrate() # TODO: enable audio plugins separately from normal # plugins? What about plugins that use the player? # Gstreamer doesn't initialize itself automatically, and fails # miserably when you try to inherit from something and GST hasn't # been initialized yet. So this is here. from gi.repository import Gst Gst.init(None) # Initialize plugin manager from xl import plugins self.plugins = plugins.PluginsManager(self) if not self.options.SafeMode: logger.info("Loading plugins...") self.plugins.load_enabled() else: logger.info("Safe mode enabled, not loading plugins.") # Initialize the collection logger.info("Loading collection...") from xl import collection try: self.collection = collection.Collection("Collection", location=os.path.join(xdg.get_data_dir(), 'music.db')) except common.VersionError: logger.exception("VersionError loading collection") sys.exit(1) from xl import event # Set up the player and playback queue from xl import player event.log_event("player_loaded", player.PLAYER, None) # Initalize playlist manager from xl import playlist self.playlists = playlist.PlaylistManager() self.smart_playlists = playlist.PlaylistManager('smart_playlists', playlist.SmartPlaylist) if firstrun: self._add_default_playlists() event.log_event("playlists_loaded", self, None) # Initialize dynamic playlist support from xl import dynamic dynamic.MANAGER.collection = self.collection # Initalize device manager logger.info("Loading devices...") from xl import devices self.devices = devices.DeviceManager() event.log_event("device_manager_ready", self, None) # Initialize dynamic device discovery interface # -> if initialized and connected, then the object is not None self.udisks2 = None self.udisks = None self.hal = None if self.options.Hal: from xl import hal udisks2 = hal.UDisks2(self.devices) if udisks2.connect(): self.udisks2 = udisks2 else: udisks = hal.UDisks(self.devices) if udisks.connect(): self.udisks = udisks else: self.hal = hal.HAL(self.devices) self.hal.connect() else: self.hal = None # Radio Manager from xl import radio self.stations = playlist.PlaylistManager('radio_stations') self.radio = radio.RadioManager() self.gui = None # Setup GUI if self.options.StartGui: logger.info("Loading interface...") import xlgui self.gui = xlgui.Main(self) self.gui.main.window.show_all() event.log_event("gui_loaded", self, None) if splash is not None: splash.destroy() restore = True if self.gui: # Find out if the user just passed in a list of songs # TODO: find a better place to put this # using arg[2:] because arg[1:] will include --startgui args = [ Gio.File.new_for_path(arg).get_uri() for arg in self.options.locs ] if len(args) > 0: restore = False self.gui.open_uri(args[0], play=True) for arg in args[1:]: self.gui.open_uri(arg) # kick off autoscan of libraries # -> don't do it in command line mode, since that isn't expected self.gui.rescan_collection_with_progress(True) if restore: player.QUEUE._restore_player_state( os.path.join(xdg.get_data_dir(), 'player.state')) if firstrun: settings.set_option("general/first_run", False) self.loading = False Exaile._exaile = self event.log_event("exaile_loaded", self, None)
def quit(self, restart=False): """ Exits Exaile normally. Takes care of saving preferences, databases, etc. :param restart: Whether to directly restart :type restart: bool """ if self.quitting: return self.quitting = True logger.info("Exaile is shutting down...") logger.info("Disabling plugins...") for k, plugin in self.plugins.enabled_plugins.iteritems(): if hasattr(plugin, 'teardown'): try: plugin.teardown(self) except Exception: pass from xl import event # this event should be used by modules that dont need # to be saved in any particular order. modules that might be # touched by events triggered here should be added statically # below. event.log_event("quit_application", self, None) logger.info("Saving state...") self.plugins.save_enabled() if self.gui: self.gui.quit() from xl import covers covers.MANAGER.save() self.collection.save_to_location() # Save order of custom playlists self.playlists.save_order() self.stations.save_order() # save player, queue from xl import player player.QUEUE._save_player_state( os.path.join(xdg.get_data_dir(), 'player.state')) player.QUEUE.save_to_location( os.path.join(xdg.get_data_dir(), 'queue.state')) player.PLAYER.stop() from xl import settings settings.MANAGER.save() if restart: logger.info("Restarting...") logger_setup.stop_logging() python = sys.executable if sys.platform == 'win32': # Python Win32 bug: it does not quote individual command line # arguments. Here we do it ourselves and pass the whole thing # as one string. # See https://bugs.python.org/issue436259 (closed wontfix). import subprocess cmd = [python] + sys.argv cmd = subprocess.list2cmdline(cmd) os.execl(python, cmd) else: os.execl(python, python, *sys.argv) logger.info("Bye!") logger_setup.stop_logging() sys.exit(0)
def __init(self): """ Initializes Exaile """ # pylint: disable-msg=W0201 logger.info("Loading Exaile %s on Python %s..." % (__version__, platform.python_version())) logger.info("Loading settings...") try: from xl import settings except common.VersionError: logger.exception("Error loading settings") sys.exit(1) logger.debug("Settings loaded from %s" % settings.location) # display locale information if available try: import locale lc, enc = locale.getlocale() if enc is not None: logger.info("Using %s %s locale" % (lc, enc)) else: logger.info("Using unknown locale") except Exception: pass splash = None if self.options.StartGui: if settings.get_option('gui/use_splash', True): from xlgui.widgets.info import Splash splash = Splash() splash.show() firstrun = settings.get_option("general/first_run", True) if not self.options.NoImport and \ (firstrun or self.options.ForceImport): try: sys.path.insert(0, xdg.get_data_path("migrations")) import migration_200907100931 as migrator del sys.path[0] migrator.migrate(force=self.options.ForceImport) del migrator except Exception: logger.exception("Failed to migrate from 0.2.14") # Migrate old rating options from xl.migrations.settings import rating rating.migrate() # Migrate builtin OSD to plugin from xl.migrations.settings import osd osd.migrate() # Migrate engines from xl.migrations.settings import engine engine.migrate() # TODO: enable audio plugins separately from normal # plugins? What about plugins that use the player? # Gstreamer doesn't initialize itself automatically, and fails # miserably when you try to inherit from something and GST hasn't # been initialized yet. So this is here. from gi.repository import Gst Gst.init(None) # Initialize plugin manager from xl import plugins self.plugins = plugins.PluginsManager(self) if not self.options.SafeMode: logger.info("Loading plugins...") self.plugins.load_enabled() else: logger.info("Safe mode enabled, not loading plugins.") # Initialize the collection logger.info("Loading collection...") from xl import collection try: self.collection = collection.Collection("Collection", location=os.path.join( xdg.get_data_dir(), 'music.db')) except common.VersionError: logger.exception("VersionError loading collection") sys.exit(1) from xl import event # Set up the player and playback queue from xl import player event.log_event("player_loaded", player.PLAYER, None) # Initalize playlist manager from xl import playlist self.playlists = playlist.PlaylistManager() self.smart_playlists = playlist.SmartPlaylistManager( 'smart_playlists', collection=self.collection) if firstrun: self._add_default_playlists() event.log_event("playlists_loaded", self, None) # Initialize dynamic playlist support from xl import dynamic dynamic.MANAGER.collection = self.collection # Initalize device manager logger.info("Loading devices...") from xl import devices self.devices = devices.DeviceManager() event.log_event("device_manager_ready", self, None) # Initialize dynamic device discovery interface # -> if initialized and connected, then the object is not None self.udisks2 = None self.udisks = None self.hal = None if self.options.Hal: from xl import hal udisks2 = hal.UDisks2(self.devices) if udisks2.connect(): self.udisks2 = udisks2 else: udisks = hal.UDisks(self.devices) if udisks.connect(): self.udisks = udisks else: self.hal = hal.HAL(self.devices) self.hal.connect() else: self.hal = None # Radio Manager from xl import radio self.stations = playlist.PlaylistManager('radio_stations') self.radio = radio.RadioManager() self.gui = None # Setup GUI if self.options.StartGui: logger.info("Loading interface...") import xlgui self.gui = xlgui.Main(self) self.gui.main.window.show_all() event.log_event("gui_loaded", self, None) if splash is not None: splash.destroy() if firstrun: settings.set_option("general/first_run", False) self.loading = False Exaile._exaile = self event.log_event("exaile_loaded", self, None) restore = True if self.gui: # Find out if the user just passed in a list of songs # TODO: find a better place to put this songs = [ Gio.File.new_for_path(arg).get_uri() for arg in self.options.locs ] if len(songs) > 0: restore = False self.gui.open_uri(songs[0], play=True) for arg in songs[1:]: self.gui.open_uri(arg) # kick off autoscan of libraries # -> don't do it in command line mode, since that isn't expected self.gui.rescan_collection_with_progress(True) if restore: player.QUEUE._restore_player_state( os.path.join(xdg.get_data_dir(), 'player.state'))
from xl import settings, xdg import queue logger = logging.getLogger(__name__) def get_player(*args, **kwargs): pname = settings.get_option("player/engine", "normal") if pname == "normal": logger.debug("Normal playback engine selected.") from xl.player.engine_normal import NormalPlayer return NormalPlayer(*args, **kwargs) elif pname == "unified": logger.debug("Unified playback engine selected.") from xl.player.engine_unified import UnifiedPlayer return UnifiedPlayer(*args, **kwargs) elif pname == 'rtfd_hack': # allows building docs return None else: logger.warning("Couldn't find specified playback engine, " "falling back to normal.") from xl.player.engine_normal import NormalPlayer return NormalPlayer(*args, **kwargs) # TODO: write a better interface than this PLAYER = get_player('player') QUEUE = queue.PlayQueue(PLAYER, 'queue', location=os.path.join(xdg.get_data_dir(), 'queue.state'))
def quit(self, restart=False): """ Exits Exaile normally. Takes care of saving preferences, databases, etc. :param restart: Whether to directly restart :type restart: bool """ if self.quitting: return self.quitting = True logger.info("Exaile is shutting down...") logger.info("Disabling plugins...") for k, plugin in self.plugins.enabled_plugins.iteritems(): if hasattr(plugin, 'teardown'): try: plugin.teardown(self) except: pass from xl import event # this event should be used by modules that dont need # to be saved in any particular order. modules that might be # touched by events triggered here should be added statically # below. event.log_event("quit_application", self, None) logger.info("Saving state...") self.plugins.save_enabled() if self.gui: self.gui.quit() from xl import covers covers.MANAGER.save() self.collection.save_to_location() # Save order of custom playlists self.playlists.save_order() self.stations.save_order() # save player, queue from xl import player player.QUEUE._save_player_state( os.path.join(xdg.get_data_dir(), 'player.state') ) player.QUEUE.save_to_location( os.path.join(xdg.get_data_dir(), 'queue.state') ) player.PLAYER.stop() from xl import settings settings.MANAGER.save() if restart: logger.info("Restarting...") python = sys.executable os.execl(python, python, *sys.argv) logger.info("Bye!") logging.shutdown() sys.exit(0)
def setup_logging(self): console_format = "%(levelname)-8s: %(message)s" loglevel = logging.INFO if self.options.DebugThreads: console_format = "%(threadName)s:" + console_format if self.options.Debug: loglevel = logging.DEBUG console_format = "%(asctime)s,%(msecs)3d:" + console_format console_format += " (%(name)s)" # add module name elif self.options.Quiet: loglevel = logging.WARNING # Logfile level should always be INFO or higher if self.options.Quiet: logfilelevel = logging.INFO else: logfilelevel = loglevel datefmt = "%H:%M:%S" # Logging to terminal logging.basicConfig(level=loglevel, format=console_format, datefmt=datefmt) class FilterLogger(logging.Logger): class Filter(logging.Filter): def filter(self, record): pass_record = True if FilterLogger.module is not None: pass_record = record.name == self.module if FilterLogger.level != logging.NOTSET and pass_record: pass_record = record.levelno == self.level return pass_record module = None level = logging.NOTSET def __init__(self, name): logging.Logger.__init__(self, name) log_filter = self.Filter(name) log_filter.module = FilterLogger.module log_filter.level = FilterLogger.level self.addFilter(log_filter) FilterLogger.module = self.options.ModuleFilter if self.options.LevelFilter is not None: FilterLogger.level = getattr(logging, self.options.LevelFilter) logging.setLoggerClass(FilterLogger) # Create log directory logdir = os.path.join(xdg.get_data_dir(), 'logs') if not os.path.exists(logdir): os.makedirs(logdir) # Try to migrate logs from old location from glob import glob logfiles = glob(os.path.join(xdg.get_config_dir(), 'exaile.log*')) for logfile in logfiles: try: # Try to move to new location os.rename(logfile, os.path.join(logdir, os.path.basename(logfile))) except OSError: # Give up and simply remove os.remove(logfile) # Logging to file; this also automatically rotates the logs logfile = logging.handlers.RotatingFileHandler( os.path.join(logdir, 'exaile.log'), mode='a', backupCount=5) logfile.doRollover() # each session gets its own file logfile.setLevel(logfilelevel) formatter = logging.Formatter( '%(asctime)s %(levelname)-8s: %(message)s (%(name)s)', datefmt=datefmt) logfile.setFormatter(formatter) logging.getLogger("").addHandler(logfile)
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # The developers of the Exaile media player hereby grant permission # for non-GPL compatible GStreamer and Exaile plugins to be used and # distributed together with GStreamer and Exaile. This permission is # above and beyond the permissions granted by the GPL license by which # Exaile is covered. If you modify this code, you may extend this # exception to your version of the code, but you are not obligated to # do so. If you do not wish to do so, delete this exception statement # from your version. """ Allows for playback and queue control """ __all__ = ['adapters', 'gst', 'queue', 'PLAYER', 'QUEUE'] import os from xl import xdg from . import player from . import queue PLAYER = player.ExailePlayer('player') QUEUE = queue.PlayQueue(PLAYER, 'queue', location=os.path.join(xdg.get_data_dir(), 'queue.state'))
def setup_logging(self): console_format = "%(levelname)-8s: %(message)s" loglevel = logging.INFO if self.options.DebugThreads: console_format = "%(threadName)s:" + console_format if self.options.Debug: loglevel = logging.DEBUG console_format = "%(asctime)s,%(msecs)3d:" + console_format console_format += " (%(name)s)" # add module name elif self.options.Quiet: loglevel = logging.WARNING # Logfile level should always be INFO or higher if self.options.Quiet: logfilelevel = logging.INFO else: logfilelevel = loglevel datefmt = "%H:%M:%S" # Logging to terminal logging.basicConfig(level=loglevel, format=console_format, datefmt=datefmt) class FilterLogger(logging.Logger): class Filter(logging.Filter): def filter(self, record): pass_record = True if FilterLogger.module is not None: pass_record = record.name == self.module if FilterLogger.level != logging.NOTSET and pass_record: pass_record = record.levelno == self.level return pass_record module = None level = logging.NOTSET def __init__(self, name): logging.Logger.__init__(self, name) log_filter = self.Filter(name) log_filter.module = FilterLogger.module log_filter.level = FilterLogger.level self.addFilter(log_filter) FilterLogger.module = self.options.ModuleFilter if self.options.LevelFilter is not None: FilterLogger.level = getattr(logging, self.options.LevelFilter) logging.setLoggerClass(FilterLogger) # Create log directory logdir = os.path.join(xdg.get_data_dir(), 'logs') if not os.path.exists(logdir): os.makedirs(logdir) # Try to migrate logs from old location from glob import glob logfiles = glob(os.path.join(xdg.get_config_dir(), 'exaile.log*')) for logfile in logfiles: try: # Try to move to new location os.rename(logfile, os.path.join(logdir, os.path.basename(logfile))) except OSError: # Give up and simply remove os.remove(logfile) # Logging to file; this also automatically rotates the logs logfile = logging.handlers.RotatingFileHandler(os.path.join( logdir, 'exaile.log'), mode='a', backupCount=5) logfile.doRollover() # each session gets its own file logfile.setLevel(logfilelevel) formatter = logging.Formatter( '%(asctime)s %(levelname)-8s: %(message)s (%(name)s)', datefmt=datefmt) logfile.setFormatter(formatter) logging.getLogger("").addHandler(logfile)
def __init(self): """ Initializes Exaile """ logger.info("Loading Exaile %s...", __version__) from gi.repository import GObject from .version import register register('Python', platform.python_version()) register('PyGObject', '%d.%d.%d' % GObject.pygobject_version) logger.info("Loading settings...") try: from xl import settings except common.VersionError: logger.exception("Error loading settings") sys.exit(1) logger.debug("Settings loaded from %s", settings.location) # display locale information if available try: import locale lc, enc = locale.getlocale() if enc is not None: locale_str = '%s %s' % (lc, enc) else: locale_str = _('Unknown') register('Locale', locale_str) except Exception: pass splash = None if self.options.StartGui: if settings.get_option('gui/use_splash', True): from xlgui.widgets.info import Splash splash = Splash() splash.show() firstrun = settings.get_option("general/first_run", True) # Migrate old rating options from xl.migrations.settings import rating rating.migrate() # Migrate builtin OSD to plugin from xl.migrations.settings import osd osd.migrate() # Migrate engines from xl.migrations.settings import engine engine.migrate() # TODO: enable audio plugins separately from normal # plugins? What about plugins that use the player? # Gstreamer doesn't initialize itself automatically, and fails # miserably when you try to inherit from something and GST hasn't # been initialized yet. So this is here. from gi.repository import Gst Gst.init(None) # Initialize plugin manager from xl import plugins self.plugins = plugins.PluginsManager(self) if not self.options.SafeMode: logger.info("Loading plugins...") self.plugins.load_enabled() else: logger.info("Safe mode enabled, not loading plugins.") # Initialize the collection logger.info("Loading collection...") from xl import collection try: self.collection = collection.Collection( "Collection", location=os.path.join(xdg.get_data_dir(), 'music.db') ) except common.VersionError: logger.exception("VersionError loading collection") sys.exit(1) # Migrate covers.db. This can only be done after the collection is loaded. import xl.migrations.database.covers_1to2 as mig mig.migrate() from xl import event # Set up the player and playback queue from xl import player event.log_event("player_loaded", player.PLAYER, None) # Initalize playlist manager from xl import playlist self.playlists = playlist.PlaylistManager() self.smart_playlists = playlist.SmartPlaylistManager( 'smart_playlists', collection=self.collection ) if firstrun: self._add_default_playlists() event.log_event("playlists_loaded", self, None) # Initialize dynamic playlist support from xl import dynamic dynamic.MANAGER.collection = self.collection # Initalize device manager logger.info("Loading devices...") from xl import devices self.devices = devices.DeviceManager() event.log_event("device_manager_ready", self, None) # Initialize dynamic device discovery interface # -> if initialized and connected, then the object is not None self.udisks2 = None if self.options.Hal: from xl import hal udisks2 = hal.UDisks2(self.devices) if udisks2.connect(): self.udisks2 = udisks2 # Radio Manager from xl import radio self.stations = playlist.PlaylistManager('radio_stations') self.radio = radio.RadioManager() self.gui = None # Setup GUI if self.options.StartGui: logger.info("Loading interface...") import xlgui self.gui = xlgui.Main(self) self.gui.main.window.show_all() event.log_event("gui_loaded", self, None) if splash is not None: splash.destroy() if firstrun: settings.set_option("general/first_run", False) self.loading = False Exaile._exaile = self event.log_event("exaile_loaded", self, None) restore = True if self.gui: # Find out if the user just passed in a list of songs # TODO: find a better place to put this songs = [Gio.File.new_for_path(arg).get_uri() for arg in self.options.locs] if len(songs) > 0: restore = False self.gui.open_uri(songs[0], play=True) for arg in songs[1:]: self.gui.open_uri(arg) # kick off autoscan of libraries # -> don't do it in command line mode, since that isn't expected self.gui.rescan_collection_with_progress(True) if restore: player.QUEUE._restore_player_state( os.path.join(xdg.get_data_dir(), 'player.state') )
def quit(self, restart=False): """ Exits Exaile normally. Takes care of saving preferences, databases, etc. :param restart: Whether to directly restart :type restart: bool """ if self.quitting: return self.quitting = True logger.info("Exaile is shutting down...") logger.info("Disabling plugins...") for k, plugin in self.plugins.enabled_plugins.iteritems(): if hasattr(plugin, 'teardown'): try: plugin.teardown(self) except: pass from xl import event # this event should be used by modules that dont need # to be saved in any particular order. modules that might be # touched by events triggered here should be added statically # below. event.log_event("quit_application", self, None) logger.info("Saving state...") self.plugins.save_enabled() if self.gui: self.gui.quit() from xl import covers covers.MANAGER.save() self.collection.save_to_location() # Save order of custom playlists self.playlists.save_order() self.stations.save_order() # save player, queue from xl import player player.QUEUE._save_player_state( os.path.join(xdg.get_data_dir(), 'player.state')) player.QUEUE.save_to_location( os.path.join(xdg.get_data_dir(), 'queue.state')) player.PLAYER.stop() from xl import settings settings.MANAGER.save() if restart: logger.info("Restarting...") python = sys.executable os.execl(python, python, *sys.argv) logger.info("Bye!") logging.shutdown() sys.exit(0)