This file is indexed.

/usr/share/pyshared/lpltk/bug.py is in python-launchpadlib-toolkit 0.5.

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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#!/usr/bin/python

import re
import sys
from utils                      import o2str
from datetime                   import datetime
from tags                       import BugTags
from attachments                import Attachments
from person                     import Person
from messages                   import Messages
from nominations                import Nominations
from bug_activity               import Activity

# Bug
#
# A class that provides a convenient interface to a Launchpad bug.
#
class Bug(object):
    # __init__
    #
    # Initialize the Bug instance from a Launchpad bug.
    #
    def __init__(self, service, bug_number, commit_changes=True):
        self.service        = service
        launchpad           = service.launchpad
        self.lpbug          = launchpad.bugs[bug_number]
        self.id             = self.lpbug.id
        self.commit_changes = commit_changes

        # Cached copies so we don't go back to launchpad as often
        #
        self.__activity                   = None
        self.__attachments                = None
        self.__date_created               = None
        self.__date_last_message          = None
        self.__date_last_updated          = None
        self.__date_latest_patch_uploaded = None
        self.__description                = None
        self.__duplicate_of               = None
        self.__gravity                    = None
        self.__heat                       = None
        self.__nominations                = None
        self.__owner                      = None
        self.__private                    = None
        self.__properties                 = None
        self.__releases                   = None
        self.__security_related           = None
        self.__tags                       = None
        self.__title                      = None
        self.__users_affected_count       = None
        self.__users_unaffected_count     = None

    #--------------------------------------------------------------------------
    # date_created / age
    #
    # (read-only)
    #
    @property
    def date_created(self):
        if self.__date_created is None:
            self.__date_created = self.lpbug.date_created
        return self.__date_created

    def age(self):
        ''' Age of bug in days '''
        dlm = self.date_created
        now = dlm.now(dlm.tzinfo)
        return (now - dlm).days

    #--------------------------------------------------------------------------
    # date_last_updated / age_last_updated
    #
    # (read-only)
    #
    @property
    def date_last_updated(self):
        if self.__date_last_updated is None:
            self.__date_last_updated = self.lpbug.date_last_updated
        return self.__date_last_updated

    def age_last_updated(self):
        ''' Age of last update to bug in days '''
        dlm = self.date_last_updated
        now = dlm.now(dlm.tzinfo)
        return (now - dlm).days

    #--------------------------------------------------------------------------
    # date_last_message / age_last_message
    #
    # (read-only)
    #
    @property
    def date_last_message(self):
        if self.__date_last_message is None:
            self.__date_last_message = self.lpbug.date_last_message
        return self.__date_last_message

    def age_last_message(self):
        ''' Age of last comment to bug in days '''
        dlm = self.date_last_message
        now = dlm.now(dlm.tzinfo)
        return (now - dlm).days

    #--------------------------------------------------------------------------
    # private
    #
    # (read-only)
    #
    @property
    def private(self):
        if self.__private is None:
            self.__private = self.lpbug.private
        return self.__private

    # private
    #
    # (read-only)
    #
    @private.setter
    def private(self, value):
        self.lpbug.private = value
        if self.commit_changes:
            self.lpbug.lp_save()
        self.__private = value
        return

    #--------------------------------------------------------------------------
    # security_related
    #
    # (read-only)
    #
    @property
    def security_related(self):
        if self.__security_related is None:
            self.__security_related = self.lpbug.security_related
        return self.__security_related

    # security_related
    #
    # (read-only)
    #
    @security_related.setter
    def security_related(self, value):
        self.lpbug.security_related = value
        if self.commit_changes:
            self.lpbug.lp_save()
        self.__security_related = value
        return

    #--------------------------------------------------------------------------
    # title
    #
    @property
    def title(self):
        '''A one-line summary of the problem being described by the bug.'''
        if self.__title is None:
            self.__title = o2str(self.lpbug.title)
        return self.__title

    @title.setter
    def title(self, value):
        if not isinstance(value, str):
            raise TypeError("Must be a string")
        self.lpbug.title = value
        if self.commit_changes:
            self.lpbug.lp_save()
        self.__title = value

    #--------------------------------------------------------------------------
    # description
    #
    @property
    def description(self):
        '''As complete as possible description of the bug/issue being reported as a bug.'''
        if self.__description is None:
            self.__description = o2str(self.lpbug.description)
        return self.__description

    @description.setter
    def description(self, value):
        if not isinstance(value, str):
            raise TypeError("Must be a string")
        self.lpbug.description = value
        if self.commit_changes:
            self.lpbug.lp_save()
        self.__description = value

    #--------------------------------------------------------------------------
    # tags
    #
    @property
    def tags(self):
        return BugTags(self)

    #--------------------------------------------------------------------------
    # releases - List of Ubuntu releases tagged as being affected
    #
    @property
    def releases(self):
        if self.__releases is None:
            self.__releases = []

            ubuntu_releases = []
            d = self.service.launchpad.distributions['ubuntu']
            for s in d.series:
                ubuntu_releases.append("%s" %(s.name))

            for bug_tag in self.tags:
                tag = o2str(bug_tag)
                if tag in ubuntu_releases:
                    self.__releases.append(tag)
        return self.__releases

    #--------------------------------------------------------------------------
    # owner
    #
    @property
    def owner(self):
        if self.__owner is None:
            self.__owner = Person(self, self.lpbug.owner)
        return self.__owner

    @property
    def owner_name(self):
        if self.owner is not None:
            return o2str(self.owner.username)
        else:
            return None

    #--------------------------------------------------------------------------
    # attachments
    #
    @property
    def attachments(self):
        return Attachments(self)

    #--------------------------------------------------------------------------
    # properties
    #
    @property
    def properties(self):
        '''Returns dict of key: value pairs found in the bug description

        This parses the bug report description into a more
        programmatically digestable dictionary form.
        '''
        if self.__properties is None:
            re_kvp            = re.compile("^(\s*)([\.\-\w]+):\s*(.*)$")
            re_error          = re.compile("^Error:\s*(.*)$")
            self.__properties = {}
            last_key = {'': 'bar'}
            for line in self.description.split("\n"):
                m = re_kvp.match(line)
                if not m:
                    continue

                level = m.group(1)
                item = m.group(2)
                value = m.group(3)
                key = item

                if len(level) > 0:
                    key = "%s.%s" %(last_key[''], item)
                last_key[level] = item

                m = re_error.match(value)
                if not m:
                    self.__properties[key] = value

        return self.__properties

    #--------------------------------------------------------------------------
    # messages
    #
    @property
    def messages(self):
        return Messages(self)

    @property
    def messages_count(self):
        return len(self.messages)

    #--------------------------------------------------------------------------
    # tasks
    #
    @property
    def tasks(self):
        # The following import is done here to work around a circular import
        # issue. bug_tasks imports bug.
        #
        from bug_tasks import BugTasks

        return BugTasks(self.service, self.lpbug.bug_tasks_collection)

    #--------------------------------------------------------------------------
    # add_comment
    #
    def add_comment(self, content, subject=None, avoid_dupes=False):
        '''Add a new comment to an existing bug.

        This is the equivalent of newMessage.  If no subject is provided,
        it will craft one using the bug title.  If avoid_dupes is set, the
        routine will check to see if this comment has already been posted,
        to avoid accidentally spamming; the routine will return False in
        this case.
        '''
        if avoid_dupes:
            # TODO: Actually only need to consider the last ~40 messages
            for m in self.lpbug.messages:
                if m.content == content:
                    return False
        self.lpbug.newMessage(content=content, subject=subject)
        return True

    #--------------------------------------------------------------------------
    # nominations
    #
    @property
    def nominations(self):
        return Nominations(self.service, self)

    # add a nomination
    #
    def add_nomination(self, series):
        self.lpbug.addNomination(target=series)

    #--------------------------------------------------------------------------
    # activity
    #
    @property
    def activity(self):
        return Activity(self.service, self)

    # duplicate_of
    #
    @property
    def duplicate_of(self):
        if self.__duplicate_of is None:
            self.__duplicate_of = self.lpbug.duplicate_of
        return self.__duplicate_of

    # duplicates_count
    @property
    def duplicates_count(self):
        return len(self.lpbug.duplicates)

    # subscriptions_count
    @property
    def subscriptions_count(self):
        return len(self.lpbug.subscriptions)

    # heat
    #
    @property
    def heat(self):
        if self.__heat is None:
            self.__heat = self.lpbug.heat
        return self.__heat

    # date_latest_patch_uploaded
    #
    @property
    def date_latest_patch_uploaded(self):
        if self.__date_latest_patch_uploaded is None:
            self.__date_latest_patch_uploaded = self.lpbug.latest_patch_uploaded
        return self.__date_latest_patch_uploaded

    # has_patch
    #
    def has_patch(self):
        if self.date_latest_patch_uploaded is None:
            return False
        return True

    # is_expirable
    #
    def is_expirable(self, days_old=None):
        return self.lpbug.isExpirable(days_old=days_old)

    #--------------------------------------------------------------------------
    # users (un)affected
    #
    @property
    def users_affected_count(self):
        if self.__users_affected_count is None:
            self.__users_affected_count = self.lpbug.users_affected_count
        return self.__users_affected_count

    @property
    def users_unaffected_count(self):
        if self.__users_unaffected_count is None:
            self.__users_unaffected_count = self.lpbug.users_unaffected_count
        return self.__users_unaffected_count

    #--------------------------------------------------------------------------
    # gravity
    #
    def gravity(self):
        if self.__gravity is None:
            self.__gravity = (6 * self.duplicates_count +
                              4 * self.subscriptions_count +
                              2 * self.users_affected_count)
            if self.private:
                self.__gravity += 151
            if self.has_patch:
                self.__gravity += 100
            tag_weights = { 'apport-bug':50, 'apport-package':100,
                            'apport-crash':100, 'apport-kerneloops':150,
                            'regression-release':200, 'regression-proposed':250,
                            'regression-updates':300
                            }
            for tag in tag_weights:
                if tag in self.tags:
                    self.__gravity += tag_weights[tag]

        return self.__gravity

# vi:set ts=4 sw=4 expandtab: