/usr/share/pyshared/lpltk/messages.py is in python-launchpadlib-toolkit 2.3.
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 | #!/usr/bin/python
from message import Message
class Messages(object):
# __init__
#
# Initialize the instance from a Launchpad bug.
#
def __init__(self, tkbug):
self.__tkbug = tkbug
self.__commit_changes = tkbug.commit_changes
self.__messages = None
self.__filter_since_status_change = False
self.__filter_by_max_age = None
self.__filtered_messages = None
def filtered_messages(self):
if self.__filtered_messages is None:
self.__filtered_messages = list(self.__iter__())
return self.__filtered_messages
# __len__
#
def __len__(self):
return len(self.filtered_messages())
# __getitem__
#
def __getitem__(self, key):
messages = self.filtered_messages()
return messages[key]
# __iter__
#
def __iter__(self):
self.__fetch_if_needed()
for msg in self.__messages:
m = Message(self.__tkbug, msg)
if self.__filter_by_max_age:
if m.age > self.__filter_by_max_age:
continue
elif self.__filter_since_status_change:
if m.age > self.__tkbug.status_age:
continue
yield m
# __contains__
#
def __contains__(self, item):
return item in self.__iter__()
# __fetch_if_needed
#
def __fetch_if_needed(self):
if self.__messages == None:
self.__messages = self.__tkbug.lpbug.messages_collection
def set_filter_by_max_age(self, days):
'''Only include messages posted within the given number of days'''
self.__filter_by_max_age = days
self.__filtered_messages = None
def set_filter_since_status_change(self):
'''Only include messages created since the status was changed'''
self.__filter_since_status_change = True
self.__filtered_messages = None
# non_owner_count
#
def non_owner_count(self):
'''Number of messages by someone other than the original reporter'''
count = 0
for message in self.__iter__():
if message.owner != self.__tkbug.owner:
count += 1
return count
# owners
#
@property
def owner_usernames(self):
'''List of People who have posted one or more of these Messages'''
owners = {}
for message in self.__iter__():
owners[message.owner.username] = 1
return owners.keys()
# vi:set ts=4 sw=4 expandtab:
|