コード例 #1
0
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
コード例 #2
0
ファイル: main.py プロジェクト: dbavscc/ranger
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