This file is indexed.

/usr/bin/pyqi is in pyqi 0.3.2+dfsg-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#! /usr/bin/python

#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

__author__ = "Daniel McDonald"
__copyright__ = "Copyright 2013, The pyqi Project"
__credits__ = ["Greg Caporaso", "Daniel McDonald", "Doug Wendel",
               "Jai Ram Rideout"]
__license__ = "BSD"
__version__ = "0.2.0-dev"
__maintainer__ = "Daniel McDonald"
__email__ = "mcdonadt@colorado.edu"

import importlib
import textwrap
import cProfile
import pstats
from sys import argv, exit, stderr
from pyqi.core.interface import get_command_names, get_command_config
from pyqi.core.interfaces.optparse import optparse_main, optparse_factory
from pyqi.util import get_version_string
from os.path import basename
from os import environ

### we actually have some flexibility here to make the driver interface agnostic as well

TERM_WIDTH = 80
INDENT = 3

def usage(cmd_cfg_mod, command_names):
    """Modeled after git..."""
    # limit to a reasonable number of characters
    valid_cmds = []
    invalid_cmds = []
    for c in command_names:
        cmd_cfg, error_msg = get_command_config(cmd_cfg_mod, c,
                                                exit_on_failure=False)

        if cmd_cfg is None:
            invalid_cmds.append((c, error_msg))
        else:
            desc = cmd_cfg.CommandConstructor.BriefDescription
            valid_cmds.append((c, desc))

    # determine widths
    max_cmd = max(map(lambda x: len(x[0]), valid_cmds + invalid_cmds))
    desc_limit = TERM_WIDTH - (INDENT + max_cmd + INDENT)
    cmd_end = INDENT + max_cmd + INDENT

    print("usage: %s <command> [<args>]\n" % argv[0])
    print("The currently available commands are:")

    # format:
    # indent command indent description
    for c, desc in valid_cmds:
        s = ''.join([' ' * INDENT, c])
        cmd_formatted = s.ljust(cmd_end)
        print(''.join([cmd_formatted, desc[:desc_limit]]))

    if invalid_cmds:
        print("\nThe following commands could not be loaded:")

        for c, error_msg in invalid_cmds:
            s = ''.join([' ' * INDENT, c])
            cmd_formatted = s.ljust(cmd_end)
            print(''.join([cmd_formatted, 'Error: %s' % error_msg]))

    print("\nSee '%s help <command>' for more information on a specific command." % argv[0])
    exit(0)

def get_cmd_obj(cmd_cfg_mod, cmd):
    """Get a ``Command`` object"""
    cmd_cfg, _ = get_command_config(cmd_cfg_mod, cmd)
    version_str = get_version_string(cmd_cfg_mod)

    return optparse_factory(cmd_cfg.CommandConstructor, cmd_cfg.usage_examples, 
                            cmd_cfg.inputs, cmd_cfg.outputs,
                            version_str)

def help_(cmd_cfg_mod, cmd):
    """Dump the help for a ``Command``"""
    cmd_obj = get_cmd_obj(cmd_cfg_mod, cmd)
    optparse_main(cmd_obj, ['help', '-h'])

def assert_command_exists(command_name, command_names, driver_name):
    if command_name not in command_names:
        error_msg = '\n'.join(textwrap.wrap("Unrecognized command %s. Please "
                                            "make sure that you didn't make a "
                                            "typo in the command name." %
                                            command_name, TERM_WIDTH))
        error_msg += '\n\n'
        error_msg += '\n'.join(textwrap.wrap("To see a list of all available "
                                             "commands, run the following "
                                             "command:", TERM_WIDTH))
        stderr.write("%s\n\n%s%s\n\n" % (error_msg, ' ' * INDENT, driver_name))
        exit(1)


if __name__ == '__main__':
    driver_name = 'pyqi'
    cmd_cfg_mod = 'pyqi.interfaces.optparse.config'

    if '--' in argv:
        stop_idx = argv.index('--')

        if '--driver-name' in argv[:stop_idx]:
            idx = argv.index('--driver-name')
            argv.pop(idx)
            driver_name = argv[idx]

            if driver_name.startswith('--'):
                stderr.write("pyqi driver option --driver-name requires a "
                             "value, e.g. --driver-name mydriver\n")
                exit(1)

            argv.pop(idx)
            stop_idx -= 2

        if '--command-config-module' in argv[:stop_idx]:
            idx = argv.index('--command-config-module')
            argv.pop(idx)
            cmd_cfg_mod = argv[idx]

            if cmd_cfg_mod.startswith('--'):
                stderr.write("pyqi driver option --command-config-module "
                             "requires a value, e.g. --command-config-module "
                             "my.command.config.module\n")
                exit(1)

            argv.pop(idx)
            stop_idx -= 2

        if stop_idx != 1:
            # We're not pointing at a command name, so there must have been
            # other stuff that we didn't recognize.
            stderr.write("Unrecognized pyqi driver option(s): %s\n" %
                         ' '.join(argv[1:stop_idx]))
            exit(1)

        argv.pop(stop_idx)

    command_names = get_command_names(cmd_cfg_mod)

    if len(argv) == 1:
        argv[0] = driver_name
        usage(cmd_cfg_mod, command_names)
    else:
        cmd_name = argv[1]

        if cmd_name.lower() in ['help', '--help', '-?', '-h']:
            if not len(argv) > 2:
                argv[0] = driver_name
                usage(cmd_cfg_mod, command_names)

            help_cmd = argv[2]
            assert_command_exists(help_cmd, command_names, driver_name)

            # tears. 
            # .
            # this voodoo is to coerce optparse/argparse to dump the program
            # name at usage and examples correctly.
            argv[0] = ' '.join([driver_name, help_cmd])
            help_(cmd_cfg_mod, help_cmd)
        else:
            assert_command_exists(cmd_name, command_names, driver_name)
            
            # see the note about crying about tears.
            argv[0] = ' '.join([driver_name, cmd_name])
            cmd_obj = get_cmd_obj(cmd_cfg_mod, cmd_name)

            # execute FTW
            if 'PYQI_PROFILE_COMMAND' in environ:
                stats_f = "%s.stats" % cmd_name
                cProfile.run("optparse_main(cmd_obj, argv[1:])", stats_f)
                stats = pstats.Stats(stats_f)
                stats.strip_dirs().sort_stats('cumul').print_stats(25)
            else:
                optparse_main(cmd_obj, argv[1:])