This file is indexed.

/usr/lib/thuban/Thuban/UI/command.py is in thuban 1.2.2-9build1.

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
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright (C) 2001, 2002 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.

"""
Command Objects.

Command objects represent a command that a user can invoke and act as
mediators between the GUI and the application.

This module also defines a command registry that maps command names to
command objects.
"""

__version__ = "$Revision: 2700 $"


from types import TupleType


class Command:

    """
    Represent a single command.

    A command is identified by a name, it has a title (used in menu
    items and buttons, etc) and a callable object that can be invoked
    with the context as a single parameter. The context is an object
    with a few public attributes for the application object, the session
    and the main window.

    Additionally, a command may have functions that can determine
    whether the command can be invoked or whether it is checked in case
    of a toggled command. These functions are called with just the
    context as parameters.
    """

    args = ()
    kwargs = None
    sensitive  = None
    checked = None
    dyntext = None

    def __init__(self, name, title, function, helptext = "", icon = "",
                 args = (), kwargs = None,
                 sensitive = None, checked = None, dyntext = None):
        self.name = name
        self.title = title
        self.function = function
        self.helptext = helptext
        self.icon = icon
        if args != ():
            if type(args) != TupleType:
                args = (args,)
            self.args = args
        if kwargs is not None:
            self.kwargs = kwargs
        if sensitive is not None:
            self.sensitive = sensitive
        if checked is not None:
            self.checked = checked
        if dyntext is not None:
            self.dyntext = dyntext

    def Name(self):
        return self.name

    def Title(self):
        return self.title

    def HelpText(self):
        return self.helptext

    def Icon(self):
        return self.icon

    def Sensitive(self, context):
        if self.sensitive is not None:
            return self.sensitive(context)
        return 1

    def Checked(self, context):
        if self.checked is not None:
            return self.checked(context)
        return 0 # XXX raise an exception?

    def IsCheckCommand(self):
        return self.checked is not None

    def DynText(self, context):
        if self.dyntext is not None:
            return self.dyntext(context)
        return self.Title()

    def HasDynText(self):
        return self.dyntext is not None

    def IsDynamic(self):
        """Return true if the command is in any way dynamic"""
        return (self.sensitive is not None
                or self.checked is not None
                or self.dyntext is not None)

    def IsTool(self):
        """Return whether the command represents a tool.

        This default implementation always returns 0.
        """
        return 0

    def Execute(self, context, args = ()):
        kw = self.kwargs
        if kw is None:
            kw = {}
        if type(args) != TupleType:
            args = (args,)
        #print self.name, self.args, args
        apply(self.function, (context,) + self.args + args, kw)

class ToolCommand(Command):

    """A command tool activating a tool"""

    def IsTool(self):
        """Return whether the command represents a tool, i.e. always 1"""
        return 1


class CommandRegistry:

    """
    A CommandRegistry maps command names to command objects
    """

    def __init__(self):
        self.registry = {}

    def Add(self, script):
        self.registry[script.name] = script

    def AddFunction(self, name, title, function, args = (), sensitive = None):
        self.Add(Command(name, title, function, args = args,
                         sensitive = sensitive))

    def Command(self, name):
        return self.registry.get(name, None)



# The central command registry
registry = CommandRegistry()