This file is indexed.

/usr/bin/dirt is in dput-ng 1.8.

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
185
186
187
188
189
190
191
192
193
194
#! /usr/bin/python
# D.I.R.T.

# arguments:
#    --blame target
#    --hosts
#    --help-checker
#    --help-processor

from __future__ import print_function

import os
import sys
import json
import argparse

# A little temporary hack for those of us not using virtualenv
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))


from dput.hook import hook_docs
from dput.util import get_configs, load_config, validate_object
from dput.exceptions import DputConfigurationError
from dput.profile import get_blame_map, profiles, load_profile


parser = argparse.ArgumentParser()

parser = argparse.ArgumentParser(description='dput information retrieval tool')
subparsers = parser.add_subparsers(help='sub-command help')

parser_hosts = subparsers.add_parser('hosts',
                        help='print the lists of hosts that dput knows about')
parser_hosts.set_defaults(command="hosts")

parser_blame = subparsers.add_parser('blame',
                        help='get information on where dput is finding keys')
parser_blame.set_defaults(command="blame")
parser_blame.add_argument('-p', '--profile', metavar='PROFILE_NAME',
                         help='name of the hook to retrieve information from',
                         required=True)

parser_list = subparsers.add_parser('list',
                        help='list all the hooks registered to dput')
parser_list.set_defaults(command="list")

parser_info = subparsers.add_parser('info',
                        help='get some help on a hook')
parser_info.set_defaults(command="info")
parser_info.add_argument('-H', '--hook', metavar='HOOK_NAME',
                         help='name of the hook to retrieve information from',
                         required=True)

#XXX: stubbing for now
#group.add_argument(
#    '--remove-hook',
#    nargs=2,
#    action='store',
#    help='Remove a hook from a given profile',
#    metavar='HOOK'
#)
#
#group.add_argument(
#    '--add-hook',
#    nargs=2,
#    action='store',
#    help='Add a hook to a given profile',
#    metavar='HOOK'
#)


args = parser.parse_args()

print("\nWARNING: This command is not completed yet. Interface and behavior "
      "changes are expected in future releases\n")


if args.command == 'blame':
    if args.profile not in profiles():
        print("No such target.")
        sys.exit(1)

    print(json.dumps(get_blame_map(args.profile), sort_keys=True, indent=4))
    sys.exit(0)

if args.command == 'hosts':
    default = load_profile(None)
    print()
    print("Default method: %s" % (default['method']))
    print()
    for config in profiles():
        obj = load_profile("%s:%s" % (config, config))
        #                               ^^^^^^ fake arg for others
        if not "fqdn" in obj:  # likely localhost
            obj['fqdn'] = 'localhost'

        string = "{name} => {fqdn}  (Upload method: {method})".format(**obj)
        print(string)
    print()
    sys.exit(0)


if args.command == 'info':
    try:
        docs = hook_docs(args.hook)
        if docs == "":
            print("Sorry, the author didn't provide help on this module.")
            sys.exit(0)
        print(docs)
    except DputConfigurationError:
        print("No such hook '%s'." % (args.hook))
        sys.exit(1)


if args.command == 'list':
    hook_list = {'pre': {}, 'post': {}}
    for config in get_configs('hooks'):
        hook = load_config('hooks', config)
        validate_object('plugin', hook, "hooks/%s" % (config))

        if 'pre' in hook:
            hook_list['pre'][config] = hook
        if 'post' in hook:
            hook_list['post'][config] = hook
    for hook_type in hook_list:
        print("%s-upload hooks:" % (hook_type))
        for hook in hook_list[hook_type]:
            print("\t%s: %s" % (hook,
                                hook_list[hook_type][hook]['description']))
        print()
    sys.exit(0)

# Dear lord of all that is holy, the kruft below *needs* to be moved into
# proper dput config objects. We should really just grab the local foo, and
# deal with that mess on the fly. Don't put it there until it's factored in
# nicely.
#   - PRT

def _read_file(fpath):
    obj = {}
    if os.path.exists(fpath):
        obj = json.load(open(fpath, 'r'))
    return obj

def _write_file(fpath, obj):
    d = os.path.dirname(fpath)
    if not os.path.exists(d):
        os.makedirs(d)
    open(fpath, 'w').write(json.dumps(obj, sort_keys=True, indent=4))

#if args.add_hook:
#    hook, target = args.add_hook
#    # sanity check target, now.
#    # sanity check hook, now.
#    config = os.path.expanduser(
#        "~/.dput.d/profiles/%s.json" % (target)  # XXX: Do this right.
#    )
#    obj = _read_file(config)
#    if not '+hooks' in obj:
#        obj['+hooks'] = []
#    if hook not in obj['+hooks']:
#        print("Added %s to the config." % (hook))
#        obj['+hooks'].append(hook)
#    else:
#        print("%s is already in the config." % (hook))
#
#    _write_file(config, obj)
#    sys.exit(0)


#if args.remove_hook:
#    hook, target = args.remove_hook
#    # sanity check target, now.
#    # sanity check hook, now.
#    config = os.path.expanduser(
#        "~/.dput.d/profiles/%s.json" % (target)  # XXX: Do this right.
#    )
#    obj = _read_file(config)
#
#    if 'hooks' in obj:
#        if hook in obj['hooks']:
#            obj['hooks'].remove(hook)
#
#    elif '+hooks' in obj:
#        if hook in obj['+hooks']:
#            obj['+hooks'].remove(hook)
#    else:
#        if not '-hooks' in obj:
#            obj['-hooks'] = []
#
#        obj['-hooks'].append(hook)
#
#    _write_file(config, obj)
#    sys.exit(0)