This file is indexed.

/usr/share/pyshared/circuits/app/env.py is in python-circuits 2.1.0-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
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
# Module:   env
# Date:     10th June 2006
# Author:   James Mills, prologic at shortcircuit dot net dot au

"""Environment Component

An Environment Component that by default sets up a Config and Logger
components and is used to create, load and manage system/application
environments.
"""

from os import mkdir
from os import makedirs
from os.path import abspath, isabs, join as joinpath

from circuits import handler, BaseComponent, Event

from . import config
from .config import Config

from .log import Logger


VERSION = 1

CONFIG = {
    "general": {
        "pidfile": joinpath("%(path)s", "log", "%(name)s.pid"),
    },
    "logging": {
        "debug": "True",
        "type": "file",
        "verbose": "True",
        "level": "DEBUG",
        "file": joinpath("%(path)s", "log", "%(name)s.log"),
    }
}

ERRORS = (
    (0, "No Environment version information",),
    (1, "Environment needs upgrading",),
)


def createFile(filename, data=None):
    fd = open(filename, "w")
    if data:
        fd.write(data)
    fd.close()


class EnvironmentError(Exception):
    """Environment Error"""


class EnvironmentEvent(Event):
    """Environment Event"""

    channels = ("env",)


class Ready(EnvironmentEvent):
    """Ready Environment Event"""


class Create(EnvironmentEvent):
    """Create Environment Event"""

    success = True
    failure = True


class Load(EnvironmentEvent):
    """Load Environment Event"""

    success = True
    failure = True


class Verify(EnvironmentEvent):
    """Verify Environment Event"""

    success = True
    failure = True


class Upgrade(EnvironmentEvent):
    """Upgrade Environment Event"""

    success = True
    failure = True


class Environment(BaseComponent):
    """Base Environment Component

    Creates a new environment component that by default only
    holds configuration and logger components.

    This component can be extended to provide more complex
    system and application environments.
    """

    channel = "env"

    version = VERSION

    def __init__(self, path, envname, channel=channel):
        super(Environment, self).__init__(channel=channel)

        self.path = abspath(path)
        self.envname = envname

    @handler("create", priority=1.0)
    def create(self):
        return self._create()

    @handler("load", priority=1.0)
    def load(self, verify=False):
        if verify:
            return self.fire(Verify())
        else:
            return self._load()

    @handler("verify", priority=1.0)
    def _on_verify(self):
        f = open(joinpath(self.path, "VERSION"), "r")
        version = f.read().strip()
        f.close()

        if not version:
            raise EnvironmentError(*ERRORS[0])
        else:
            if self.version > int(version):
                raise EnvironmentError(*ERRORS[1])

    @handler("verify_success", filter=True)
    def _on_verify_success(self, evt, retval):
        return self._load()

    @handler("load_success", channel="config")
    def _on_config_load_success(self, evt, retval):
        # Create Logger Component
        logname = self.envname
        logtype = self.config.get("logging", "type", "file")
        loglevel = self.config.get("logging", "level", "INFO")
        logfile = self.config.get("logging", "file", "/dev/null")
        logfile = logfile % {"name": self.envname}
        if not isabs(logfile):
            logfile = joinpath(self.path, logfile)
        self.log = Logger(logfile, logname, logtype, loglevel).register(self)
        self.fire(Ready())

    def _create(self):
        # Create the directory structure
        makedirs(self.path)
        mkdir(joinpath(self.path, "log"))
        mkdir(joinpath(self.path, "conf"))

        # Create a few files
        createFile(joinpath(self.path, "VERSION"), "%d" % self.version)
        createFile(
            joinpath(self.path, "README"),
            "This directory contains a %s Environment." % self.envname
        )

        # Setup the default configuration
        configfile = joinpath(self.path, "conf", "%s.ini" % self.envname)
        createFile(configfile)
        self.config = Config(configfile).register(self)
        for section in CONFIG:
            if not self.config.has_section(section):
                self.config.add_section(section)
            for option, value in CONFIG[section].items():
                if type(value) == str:
                    value = value % {
                        "name": self.envname,
                        "path": self.path,
                    }
                self.config.set(section, option, value)
        return self.fire(config.Save(), self.config)

    def _load(self):
        # Create Config Component
        configfile = joinpath(self.path, "conf", "%s.ini" % self.envname)
        self.config = Config(configfile).register(self)
        self.fire(config.Load())
        return True