This file is indexed.

/usr/share/pyshared/DITrack/UI.py is in ditrack 0.8-1.2.

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

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
#
# UI.py - DITrack User Interface
#
# Copyright (c) 2006-2007 The DITrack Project, www.ditrack.org.
#
# $Id: UI.py 1842 2007-08-03 00:01:37Z vss $
# $HeadURL: https://svn.xiolabs.com/ditrack/src/tags/0.8/DITrack/UI.py $
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import sys

class MenuItem:
    def __init__(self, key, descr):
        self.key = key
        self.descr = descr

        self.enabled = True

class Menu:
    def __init__(self, title, items, eof_returns_value=True):
        """
        Create a menu object with TITLE and passed list of MenuItem's ITEMS.
        EOF_RETURNS_VALUE controls what to return in case of reading EOF:
        the first item of ITEMS (if True) or None (otherwise).
        """

        assert(len(items))

        self.eof_returns_value = eof_returns_value
        self.title = title
        self.default = items[0]

        self.key2item = {}
        for i in items:
            self.key2item[i.key] = i

    def run(self):
        assert(len(self.key2item))

        keys = self.key2item.keys()
        keys.sort()

        while 1:
            sys.stdout.write("%s:\n" % self.title)
            for k in keys:
                item = self.key2item[k]
                if not item.enabled: continue

                sys.stdout.write("%s) %s\n" % (k, item.descr))

            sys.stdout.write("> ")

            s = sys.stdin.readline()
            if not s:
                if self.eof_returns_value:
                    return self.default
                else:
                    return None

            s = s.strip()

            if s.isdigit():
                s = int(s)

            if self.key2item.has_key(s):
                if self.key2item[s].enabled:
                    return self.key2item[s]

            sys.stdout.write("Unrecognized input: '%s'\n\n" % str(s))

class EnumMenu:
    def __init__(self, title, items, abort_option=None):
        """
        Creates a menu object with TITLE and ITEMS where the 'hotkey' for each
        item is its sequential number starting with 1. If ABORT_OPTION is True
        an option to abort the choice is included as the last item.
        """

        items_list = []
        for i, v in enumerate(items):
            items_list.append(MenuItem((i + 1), v))

        self.abort_option = None
        if abort_option:
            self.abort_option = MenuItem("a", "abort")
            items_list.append(self.abort_option)

        self.menu = Menu(title, items_list, eof_returns_value=None)

    def run(self):
        """
        Runs the menu.

        In case if the user has aborted the menu (if there was an option) or
        input EOF, None will be returned. Otherwise the selected item's text
        is returned.
        """
        r = self.menu.run()
        if not r: return None

        if self.abort_option and (r == self.abort_option):
            return None

        return r.descr

class TextInput:
    """
    Prints out a prompt, reads user input and returns it stripped (if any).
    """

    def __init__(self, title):
        self.title = title

    def run(self):
        sys.stdout.write("%s:\n> " % self.title)
        str = sys.stdin.readline()

        if not str: return None

        return str.strip()