def parse_arguments(): """Parse the program arguments""" from optparse import OptionParser, SUPPRESS_HELP from ranger import __version__ from ranger.ext.openstruct import OpenStruct from os.path import expanduser if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' else: default_confdir = '~/.config/ranger' usage = '%prog [options] [path/filename]' minor_version = __version__[2:] # assumes major version number is <10 if '.' in minor_version: minor_version = minor_version[:minor_version.find('.')] version_tag = ' (stable)' if int(minor_version) % 2 == 0 else ' (testing)' if __version__.endswith('.0'): version_string = 'ranger ' + __version__[:-2] + version_tag else: version_string = 'ranger ' + __version__ + version_tag parser = OptionParser(usage=usage, version=version_string) parser.add_option('-d', '--debug', action='store_true', help="activate debug mode") parser.add_option('-c', '--clean', action='store_true', help="don't touch/require any config files. ") parser.add_option('--fail-if-run', action='store_true', # COMPAT help=SUPPRESS_HELP) parser.add_option('--copy-config', type='string', metavar='which', help="copy the default configs to the local config directory. " "Possible values: all, apps, commands, keys, options, scope") parser.add_option('--fail-unless-cd', action='store_true', help="experimental: return the exit code 1 if ranger is" \ "used to run a file (with `ranger filename`)") parser.add_option('-r', '--confdir', type='string', metavar='dir', default=default_confdir, help="the configuration directory. (%default)") parser.add_option('-m', '--mode', type='int', default=0, metavar='n', help="if a filename is supplied, run it with this mode") parser.add_option('-f', '--flags', type='string', default='', metavar='string', help="if a filename is supplied, run it with these flags.") parser.add_option('--choosefile', type='string', metavar='TARGET', help="Makes ranger act like a file chooser. When opening " "a file, it will quit and write the name of the selected " "file to TARGET.") parser.add_option('--choosedir', type='string', metavar='TARGET', help="Makes ranger act like a directory chooser. When ranger quits" ", it will write the name of the last visited directory to TARGET") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = expanduser(arg.confdir) if arg.fail_if_run: arg.fail_unless_cd = arg.fail_if_run del arg['fail_if_run'] return arg
def parse_arguments(): """Parse the program arguments""" from optparse import OptionParser from ranger import __version__ from ranger.ext.openstruct import OpenStruct from os.path import expanduser if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' else: default_confdir = CONFDIR parser = OptionParser(usage=USAGE, version='ranger %s%s' \ % (__version__, " (stable)" if STABLE else "")) parser.add_option('-d', '--debug', action='store_true', help="activate debug mode") parser.add_option('-c', '--clean', action='store_true', help="don't touch/require any config files. ") parser.add_option('--copy-config', type='string', metavar='which', help="copy the default configs to the local config directory. " "Possible values: all, rc, apps, commands, options, scope") parser.add_option('--fail-unless-cd', action='store_true', help="experimental: return the exit code 1 if ranger is" \ "used to run a file (with `ranger filename`)") parser.add_option('-r', '--confdir', type='string', metavar='dir', default=default_confdir, help="the configuration directory. (%default)") parser.add_option('-m', '--mode', type='int', default=0, metavar='n', help="if a filename is supplied, run it with this mode") parser.add_option('-f', '--flags', type='string', default='', metavar='string', help="if a filename is supplied, run it with these flags.") parser.add_option('--choosefile', type='string', metavar='TARGET', help="Makes ranger act like a file chooser. When opening " "a file, it will quit and write the name of the selected " "file to TARGET.") parser.add_option('--choosefiles', type='string', metavar='TARGET', help="Makes ranger act like a file chooser for multiple files " "at once. When opening a file, it will quit and write the name " "of all selected files to TARGET.") parser.add_option('--choosedir', type='string', metavar='TARGET', help="Makes ranger act like a directory chooser. When ranger quits" ", it will write the name of the last visited directory to TARGET") parser.add_option('--list-unused-keys', action='store_true', help="List common keys which are not bound to any action.") parser.add_option('--selectfile', type='string', metavar='filepath', help="Open ranger with supplied file selected.") parser.add_option('--list-tagged-files', type='string', default=None, metavar='tag', help="List all files which are tagged with the given tag, default: *") parser.add_option('--profile', action='store_true', help="Print statistics of CPU usage on exit.") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = expanduser(arg.confdir) return arg
def parse_arguments(): """Parse the program arguments""" from optparse import OptionParser, SUPPRESS_HELP from os.path import expanduser from ranger import CONFDIR, USAGE, VERSION from ranger.ext.openstruct import OpenStruct if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' else: default_confdir = CONFDIR parser = OptionParser(usage=USAGE, version=VERSION) parser.add_option('-d', '--debug', action='store_true', help="activate debug mode") parser.add_option('-c', '--clean', action='store_true', help="don't touch/require any config files. ") parser.add_option('-r', '--confdir', type='string', metavar='dir', default=default_confdir, help="change the configuration directory. (%default)") parser.add_option('--copy-config', type='string', metavar='which', help="copy the default configs to the local config directory. " "Possible values: all, rc, rifle, commands, scope") parser.add_option('--fail-unless-cd', action='store_true', help=SUPPRESS_HELP) # COMPAT parser.add_option('-m', '--mode', type='int', default=0, metavar='n', help=SUPPRESS_HELP) # COMPAT parser.add_option('-f', '--flags', type='string', default='', metavar='string', help=SUPPRESS_HELP) # COMPAT parser.add_option('--choosefile', type='string', metavar='TARGET', help="Makes ranger act like a file chooser. When opening " "a file, it will quit and write the name of the selected " "file to TARGET.") parser.add_option('--choosefiles', type='string', metavar='TARGET', help="Makes ranger act like a file chooser for multiple files " "at once. When opening a file, it will quit and write the name " "of all selected files to TARGET.") parser.add_option('--choosedir', type='string', metavar='TARGET', help="Makes ranger act like a directory chooser. When ranger quits" ", it will write the name of the last visited directory to TARGET") parser.add_option('--selectfile', type='string', metavar='filepath', help="Open ranger with supplied file selected.") parser.add_option('--list-unused-keys', action='store_true', help="List common keys which are not bound to any action.") parser.add_option('--list-tagged-files', type='string', default=None, metavar='tag', help="List all files which are tagged with the given tag, default: *") parser.add_option('--profile', action='store_true', help="Print statistics of CPU usage on exit.") parser.add_option('--cmd', action='append', type='string', metavar='COMMAND', help="Execute COMMAND after the configuration has been read. " "Use this option multiple times to run multiple commands.") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = expanduser(arg.confdir) if arg.fail_unless_cd: # COMPAT sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n" "It was used to faciliate using ranger as a file launcher.\n" "Now, please use the standalone file launcher 'rifle' instead.\n") return arg
def parse_arguments(): """Parse the program arguments""" from optparse import OptionParser, SUPPRESS_HELP from os.path import expanduser from ranger import CONFDIR, CACHEDIR, USAGE, VERSION from ranger.ext.openstruct import OpenStruct if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' else: default_confdir = CONFDIR if 'XDG_CACHE_HOME' in os.environ and os.environ['XDG_CACHE_HOME']: default_cachedir = os.environ['XDG_CACHE_HOME'] + '/ranger' else: default_cachedir = CACHEDIR parser = OptionParser(usage=USAGE, version=VERSION) parser.add_option('-d', '--debug', action='store_true', help="activate debug mode") parser.add_option('-c', '--clean', action='store_true', help="don't touch/require any config files. ") parser.add_option('-r', '--confdir', type='string', metavar='dir', default=default_confdir, help="change the configuration directory. (%default)") parser.add_option( '--copy-config', type='string', metavar='which', help="copy the default configs to the local config directory. " "Possible values: all, rc, rifle, commands, commands_full, scope") parser.add_option('--fail-unless-cd', action='store_true', help=SUPPRESS_HELP) # COMPAT parser.add_option('-m', '--mode', type='int', default=0, metavar='n', help=SUPPRESS_HELP) # COMPAT parser.add_option('-f', '--flags', type='string', default='', metavar='string', help=SUPPRESS_HELP) # COMPAT parser.add_option( '--choosefile', type='string', metavar='TARGET', help="Makes ranger act like a file chooser. When opening " "a file, it will quit and write the name of the selected " "file to TARGET.") parser.add_option( '--choosefiles', type='string', metavar='TARGET', help="Makes ranger act like a file chooser for multiple files " "at once. When opening a file, it will quit and write the name " "of all selected files to TARGET.") parser.add_option( '--choosedir', type='string', metavar='TARGET', help="Makes ranger act like a directory chooser. When ranger quits" ", it will write the name of the last visited directory to TARGET") parser.add_option('--selectfile', type='string', metavar='filepath', help="Open ranger with supplied file selected.") parser.add_option( '--list-unused-keys', action='store_true', help="List common keys which are not bound to any action.") parser.add_option( '--list-tagged-files', type='string', default=None, metavar='tag', help="List all files which are tagged with the given tag, default: *") parser.add_option('--profile', action='store_true', help="Print statistics of CPU usage on exit.") parser.add_option( '--cmd', action='append', type='string', metavar='COMMAND', help="Execute COMMAND after the configuration has been read. " "Use this option multiple times to run multiple commands.") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = expanduser(arg.confdir) arg.cachedir = expanduser(default_cachedir) if arg.fail_unless_cd: # COMPAT sys.stderr.write( "Warning: The option --fail-unless-cd is deprecated.\n" "It was used to faciliate using ranger as a file launcher.\n" "Now, please use the standalone file launcher 'rifle' instead.\n") return arg
def parse_arguments(): """Parse the program arguments""" from optparse import OptionParser, SUPPRESS_HELP from ranger import __version__ from ranger.ext.openstruct import OpenStruct from os.path import expanduser if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' else: default_confdir = '~/.config/ranger' usage = '%prog [options] [path/filename]' minor_version = __version__[2:] # assumes major version number is <10 if '.' in minor_version: minor_version = minor_version[:minor_version.find('.')] version_tag = ' (stable)' if int(minor_version) % 2 == 0 else ' (testing)' if __version__.endswith('.0'): version_string = 'ranger ' + __version__[:-2] + version_tag else: version_string = 'ranger ' + __version__ + version_tag parser = OptionParser(usage=usage, version=version_string) parser.add_option('-d', '--debug', action='store_true', help="activate debug mode") parser.add_option('-c', '--clean', action='store_true', help="don't touch/require any config files. ") parser.add_option( '--fail-if-run', action='store_true', # COMPAT help=SUPPRESS_HELP) parser.add_option( '--copy-config', type='string', metavar='which', help="copy the default configs to the local config directory. " "Possible values: all, apps, commands, keys, options, scope") parser.add_option('--fail-unless-cd', action='store_true', help="experimental: return the exit code 1 if ranger is" \ "used to run a file (with `ranger filename`)") parser.add_option('-r', '--confdir', type='string', metavar='dir', default=default_confdir, help="the configuration directory. (%default)") parser.add_option('-m', '--mode', type='int', default=0, metavar='n', help="if a filename is supplied, run it with this mode") parser.add_option( '-f', '--flags', type='string', default='', metavar='string', help="if a filename is supplied, run it with these flags.") parser.add_option( '--choosefile', type='string', metavar='TARGET', help="Makes ranger act like a file chooser. When opening " "a file, it will quit and write the name of the selected " "file to TARGET.") parser.add_option( '--choosedir', type='string', metavar='TARGET', help="Makes ranger act like a directory chooser. When ranger quits" ", it will write the name of the last visited directory to TARGET") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = expanduser(arg.confdir) if arg.fail_if_run: arg.fail_unless_cd = arg.fail_if_run del arg['fail_if_run'] return arg