This file is indexed.

/usr/share/pyshared/cream/manifest.py is in python-cream 0.5.3-1.

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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# Copyright: 2007-2013, Sebastian Billaudelle <sbillaudelle@googlemail.com>
#            2010-2013, Kristoffer Kleine <kris.kleine@yahoo.de>

# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import os
import itertools
from lxml.etree import parse as parse_xml_file

import cream.util


MANIFEST_FILE = 'manifest.xml'

class ManifestException(BaseException):
    pass

class NoNamespaceDefinedException(BaseException):
    pass

class Manifest(dict):

    def __init__(self, path, expand_paths=True):

        dict.__init__(self)

        self._path = path
        self._tree = parse_xml_file(self._path)

        self['path'] = os.path.dirname(os.path.abspath(path))

        root = self._tree.getroot()
        if root.tag != 'manifest':
            raise ManifestException("Manifest root tag has to 'manifest'")

        namespaces = []

        def append_ns(e):
            if e.get('namespace'):
                namespaces.append(e.get('namespace'))

        def remove_ns(e):
            if e.get('namespace'):
                namespaces.remove(e.get('namespace'))

        def expand_ns(s):
            if s.startswith('.'):
                if len(namespaces):
                    return namespaces[-1] + s
                else:
                    raise NoNamespaceDefinedException
            else:
                return s

        def expand_path(p):
            if expand_paths:
                if p:
                    return os.path.join(os.path.dirname(self._path), p)
            else:
                return p

        # TODO: Use a bottom-down iteration here and lookup node handlers
        # from a dict or so. Much faster!

        append_ns(root)

        component = root.find('component')
        append_ns(component)

        # General meta information:
        self['id'] = expand_ns(component.get('id'))
        self['type'] = expand_ns(component.get('type'))
        self['name'] = component.get('name')
        self['version'] = component.get('version')
        self['exec'] = component.get('exec')

        # Licenses:
        self['licenses'] = []

        licenses = component.findall('license')
        for license in licenses:
            append_ns(license)
            self['licenses'].append({
                'title'   : license.get('title'),
                'version' : license.get('version')
            })
            remove_ns(license)

        # Icon:
        icon = component.find('icon')
        if icon is not None:
            append_ns(icon)
            self['icon'] = expand_path(icon.get('path'))
            remove_ns(icon)

        # Category
        self['categories'] = []

        categories = component.findall('category')
        for category in categories:
            append_ns(category)
            self['categories'].append({
                'id'  : expand_ns(category.get('id'))
            })
            remove_ns(category)

        # Descriptions:
        self['descriptions'] = {}

        descriptions = component.findall('description')
        for descr in descriptions:
            append_ns(descr)
            self['descriptions'][descr.get('lang')] = descr.get('content')
            remove_ns(descr)

        self['description'] = self['descriptions'].get('en') or ''

        # Authors:
        self['authors'] = []

        authors = component.findall('author')
        for author in authors:
            append_ns(author)
            self['authors'].append({
                'name': author.get('name'),
                'type': author.get('type'),
                'mail': author.get('mail')
                })
            remove_ns(author)

        # Features:
        self['features'] = []

        features = component.findall('use-feature')
        for feature in features:
            append_ns(feature)
            feature_args = {}

            for k, v in feature.attrib.iteritems():
                if not k in ['id']:
                    feature_args[k] = v
            self['features'].append(
                (expand_ns(feature.attrib.pop('id')), feature_args)
            )
            remove_ns(feature)

        # Dependencies:
        self['dependencies'] = []

        dependencies = component.findall('dependency')
        for dependency in dependencies:
            append_ns(dependency)
            self['dependencies'].append({
                'id'        : expand_ns(dependency.get('id')),
                'type'      : expand_ns(dependency.get('type')),
                'required'  : dependency.get('required')
                })
            remove_ns(dependency)

        # Provided component types:
        self['provided-components'] = []

        provided_components = component.findall('provide-component')
        for component in provided_components:
            append_ns(component)
            self['provided-components'].append(expand_ns(component.get('type')))
            remove_ns(component)


        # Package information:
        package = root.find('package')
        if package is None:
            return

        self['package'] = {}

        self['package']['auto'] = package.get('auto') == 'true'

        self['package']['rules'] = {
            'ignore': [],
            'application': [],
            'desktop': [],
            'icon': [],
            'library': [],
        }

        rules = package.findall('rule')
        for rule in rules:
            type  = rule.get('type')
            files = rule.get('files')
            self['package']['rules'][type].append(files)


    def __str__(self):
        return "<Manifest '{0}'>".format(self._path)


class ManifestDB(object):

    def __init__(self, paths, type=None):

        if isinstance(paths, basestring):
            self.paths = [paths]
        else:
            self.paths = paths

        self.type = type

        self.manifests = {}

        self._manifest_scanner = self.scan()

    def scan(self):

        for path in self.paths:
            for file_ in cream.util.walkfiles(os.path.abspath(path)):
                filename = os.path.split(file_)[1]
                if filename == MANIFEST_FILE:
                    manifest = Manifest(file_)
                    if not self.type or manifest['type'] == self.type:
                        self.manifests[manifest['id']] = manifest
                        yield manifest


    def get(self, **kwargs):

        if 'id' in kwargs and kwargs['id'] in self.manifests:
            return self.manifests[kwargs['id']]

        for manifest in self.manifests.itervalues():
            for key, value in kwargs.iteritems():
                if manifest.get(key, None) == value:
                    return manifest

        for manifest in self._manifest_scanner:
            for key, value in kwargs.iteritems():
                if manifest.get(key, None) == value:
                    return manifest

    def get_all(self):

        # load all manifests
        for manifest in self._manifest_scanner:
            pass

        return self.manifests.values()