def process_options(self): """If options were passed, perform action on them.""" for o, a in self.opts: if o in ("-t", "--toggle"): self.toggle_arg = True elif o in ("-p", "--popup"): self.popup_arg = True elif o in ("-v", "--version"): self.print_version() sys.exit() elif o in ("-h", "--help"): self.print_usage() sys.exit() elif o in ("--visible"): self.start_visibility = True elif o in ("--hidden"): self.start_visibility = False elif o in ("--profile"): self.arg_profile = a if self.toggle_arg or self.popup_arg: import dbus_plugin as dbus if not dbus.using_dbus(): print _( "The toggle and popup arguments require D-Bus. Aborting.") sys.exit(1) dbus.execute_remote_commands(self.toggle_arg, self.popup_arg)
def process_options(self): """If options were passed, perform action on them.""" for o, a in self.opts: if o in ("-t", "--toggle"): self.toggle_arg = True elif o in ("-p", "--popup"): self.popup_arg = True elif o in ("-v", "--version"): self.print_version() sys.exit() elif o in ("-h", "--help"): self.print_usage() sys.exit() elif o in ("--visible"): self.start_visibility = True elif o in ("--hidden"): self.start_visibility = False elif o in ("--profile"): self.arg_profile = a if self.toggle_arg or self.popup_arg: import dbus_plugin as dbus if not dbus.using_dbus(): print _("The toggle and popup arguments require D-Bus. Aborting.") sys.exit(1) dbus.execute_remote_commands(self.toggle_arg, self.popup_arg)
def parse(self, argv): """Parse the command line arguments. Separates options and arguments from the given argument list, checks their validity.""" # toggle and popup need d-bus and don't always need gui # version and help don't need anything and exit without gui # hidden and visible are only applicable when gui is launched # profile and no-start don't need anything _usage = "\n".join(( _("%prog [OPTION]... [COMMAND]...") + "\n", _("Commands:"), " play %s" % _("play song in playlist"), " pause %s" % _("pause currently playing song"), " stop %s" % _("stop currently playing song"), " next %s" % _("play next song in playlist"), " prev %s" % _("play previous song in playlist"), " pp %s" % _("toggle play/pause; plays if stopped"), " repeat %s" % _("toggle repeat mode"), " random %s" % _("toggle random mode"), " info %s" % _("display current song info"), " status %s" % _("display MPD status"), )) _version = "%prog " + version parser = OptionParser(usage=_usage, version=_version) parser.add_option("-p", "--popup", dest="popup", action="store_true", help=_("popup song notification (requires D-Bus)")) parser.add_option( "-t", "--toggle", dest="toggle", action="store_true", help= _("toggles whether the app is minimized to the tray or visible (requires D-Bus)" )) parser.add_option("-n", "--no-start", dest="start", action="store_false", help=_("don't start app if D-Bus commands fail")) parser.add_option("--hidden", dest="start_visibility", action="store_false", help=_("start app hidden (requires systray)")) parser.add_option("--visible", dest="start_visibility", action="store_true", help=_("start app visible (requires systray)")) parser.add_option("--profile", dest="profile", metavar="NUM", help=_("start with profile NUM"), type=int) options, self.cmds = parser.parse_args(argv[1:]) if options.toggle: options.start_visibility = True if options.popup and options.start_visibility is None: options.start_visibility = False self.start_visibility = options.start_visibility self.arg_profile = options.profile for cmd in self.cmds: if cmd in mpd_cmds: self.skip_gui = True else: parser.error(_("unknown command %s") % cmd) if options.toggle or options.popup: import dbus_plugin as dbus if not dbus.using_dbus(): print _("toggle and popup options require D-Bus. Aborting.") sys.exit(1) dbus.execute_remote_commands(options.toggle, options.popup, options.start)
def parse(self, argv): """Parse the command line arguments. Separates options and arguments from the given argument list, checks their validity.""" # toggle and popup need d-bus and don't always need gui # version and help don't need anything and exit without gui # hidden and visible are only applicable when gui is launched # profile and no-start don't need anything _usage = "\n".join((_("%prog [OPTION]... [COMMAND]...")+"\n", _("Commands:"), " play %s" % _("play song in playlist"), " pause %s" % _("pause currently playing song"), " stop %s" % _("stop currently playing song"), " next %s" % _("play next song in playlist"), " prev %s" % _("play previous song in playlist"), " pp %s" % _("toggle play/pause; plays if stopped"), " repeat %s" % _("toggle repeat mode"), " random %s" % _("toggle random mode"), " info %s" % _("display current song info"), " status %s" % _("display MPD status"), )) _version = "%prog " + version.VERSION parser = OptionParser(usage=_usage, version=_version) parser.add_option("-p", "--popup", dest="popup", action="store_true", help=_("popup song notification (requires D-Bus)")) parser.add_option("-t", "--toggle", dest="toggle", action="store_true", help=_("toggles whether the app is minimized to the tray or visible (requires D-Bus)")) parser.add_option("-n", "--no-start", dest="start", action="store_false", help=_("don't start app if D-Bus commands fail")) parser.add_option("--hidden", dest="start_visibility", action="store_false", help=_("start app hidden (requires systray)")) parser.add_option("--visible", dest="start_visibility", action="store_true", help=_("start app visible (requires systray)")) parser.add_option("--profile", dest="profile", metavar="NUM", help=_("start with profile NUM"), type=int) options, self.cmds = parser.parse_args(argv[1:]) if options.toggle: options.start_visibility = True if options.popup and options.start_visibility is None: options.start_visibility = False self.start_visibility = options.start_visibility self.arg_profile = options.profile for cmd in self.cmds: if cmd in mpd_cmds: self.skip_gui = True else: parser.error(_("unknown command %s") % cmd) if options.toggle or options.popup: import dbus_plugin as dbus if not dbus.using_dbus(): print _("toggle and popup options require D-Bus. Aborting.") sys.exit(1) dbus.execute_remote_commands(options.toggle, options.popup, options.start)
def parse(self, argv): """Parse the command line arguments. Separates options and arguments from the given argument list, checks their validity.""" # toggle and popup need d-bus and don't always need gui # version and help don't need anything and exit without gui # hidden and visible are only applicable when gui is launched # profile and no-start don't need anything _usage = '\n'.join((_('%prog [OPTION]... [COMMAND]...\n'), _('Commands:'), ' play %s' % _('play song in playlist'), ' pause %s' % _('pause currently playing song'), ' stop %s' % _('stop currently playing song'), ' next %s' % _('play next song in playlist'), ' prev %s' % _('play previous song in playlist'), ' pp %s' % _('toggle play/pause; plays if stopped'), ' repeat %s' % _('toggle repeat mode'), ' random %s' % _('toggle random mode'), ' single %s' % _('toggle single mode'), ' consume %s' % _('toggle consume mode'), ' info %s' % _('display current song info'), ' status %s' % _('display MPD status'), )) # the mpd commands need a connection to server and exit without gui mpd_cmds = ['play', 'pause', 'stop', 'next', 'prev', 'pp', 'info', 'status', 'repeat', 'random', 'single', 'consume'] _version = '%%prog %s' % (version.version(), ) parser = OptionParser(usage=_usage, version=_version) parser.add_option('-p', '--popup', dest='popup', action='store_true', help=_('popup song notification (requires D-Bus)')) parser.add_option('-t', '--toggle', dest='toggle', action='store_true', help=_('toggles whether the app is minimized to the tray ' 'or visible (requires D-Bus)')) parser.add_option('-n', '--no-start', dest='start', action='store_false', help=_('don\'t start app if D-Bus commands fail')) parser.add_option('--hidden', dest='start_visibility', action='store_false', help=_('start app hidden (requires systray)')) parser.add_option('--visible', dest='start_visibility', action='store_true', help=_('start app visible (requires systray)')) parser.add_option('--profile', dest='profile', metavar='NUM', help=_('start with profile NUM'), type=int) parser.add_option('--verbose', dest='verbose', metavar='LVL', help=_('use the verbose level LVL (0-3)'), type=int) parser.add_option('--file', dest='infile', metavar='FILE', help=_('log in file instead of term'), type=str) options, self.cmds = parser.parse_args(argv[1:]) self.arg_verbose = options.verbose self.arg_infile = options.infile self.verbose_arg() if options.toggle: options.start_visibility = True if options.popup and options.start_visibility is None: options.start_visibility = False self.start_visibility = options.start_visibility self.arg_profile = options.profile for cmd in self.cmds: if cmd in mpd_cmds: self.skip_gui = True else: parser.error(_('unknown command %s') % cmd) if options.toggle or options.popup: import dbus_plugin as dbus if not dbus.using_dbus(): aprint(1, _('toggle and popup options require D-Bus. Aborting.')) sys.exit(1) dbus.execute_remote_commands(options.toggle, options.popup, options.start)