/usr/share/pyshared/lpltk/bug_task.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 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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | #!/usr/bin/python
import datetime
from person import Person
from bug import Bug
from milestone import Milestone
from utils import (o2str, typecheck_Entry)
# BugTask
#
class BugTask(object):
# __init__
#
def __init__(self, service, lp_bug_task):
self.__service = service
self.lp_bug_task = typecheck_Entry(lp_bug_task)
self.__assignee = None
self.__bug_target_display_name = None
self.__bug_target_name = None
self.__bug_watch = None
self.__date_assigned = None
self.__date_closed = None
self.__date_confirmed = None
self.__date_created = None
self.__date_fix_committed = None
self.__date_fix_released = None
self.__date_importance_set = None
self.__date_in_progress = None
self.__date_incomplete = None
self.__date_left_closed = None
self.__date_left_new = None
self.__date_triaged = None
self.__importance = None
self.__is_complete = None
self.__milestone = None
self.__owner = None
self.__similar_bugs = None
self.__status = None
self.__status_age = None
self.__target = None
self.__title = None
self.__upstream_bug_tracker = None
self.__upstream_product = None
self.__web_link = None
# __str__
#
def __str__(self):
return self.display_name
# owner
#
@property
def owner(self):
if self.__owner is None:
lp_owner = self.lp_bug_task.owner
if lp_owner is not None:
self.__owner = Person(None, lp_owner)
return self.__owner
@property
def owner_name(self):
if self.owner is not None:
return o2str(self.owner.username)
else:
return None
# bug_target_display_name
#
@property
def bug_target_display_name(self):
if self.__bug_target_display_name is None:
self.__bug_target_display_name = self.lp_bug_task.bug_target_display_name
return self.__bug_target_display_name
# bug_target_name
#
@property
def bug_target_name(self):
if self.__bug_target_name is None:
self.__bug_target_name = self.lp_bug_task.bug_target_name
return self.__bug_target_name
# bug
#
@property
def bug(self):
return Bug(self.__service, self.lp_bug_task.bug.id)
# status
#
@property
def status(self):
return self.lp_bug_task.status
@status.setter
def status(self, value):
if value == 'Incomplete' and self.lp_bug_task.status == 'Incomplete':
self.lp_bug_task.status = 'New'
self.lp_bug_task.lp_save()
self.lp_bug_task.status = value
self.lp_bug_task.lp_save()
return
# title
#
@property
def title(self):
if self.__title is None:
self.__title = self.lp_bug_task.title
return self.__title
# is_complete
#
@property
def is_complete(self):
if self.__is_complete is None:
self.__is_complete = self.lp_bug_task.is_complete
return self.__is_complete
# is_complete_upstream
#
@property
def is_complete_upstream(self):
"""Returns true if bug has been fixed in the official upstream bug tracker
for this package's upstream product, false if it's still open, and None
if the status is indeterminate."""
bug_tracker_url = None
try:
up = bug.target.upstream_product
bug_tracker_url = up.bug_tracker.base_url
except:
return None
for sibling_task in self.lp_bug_task.related_tasks:
if sibling_task.bug_watch is None:
continue
bt = sibling_task.bug_watch.bug_tracker
if bt is not None:
if bt.base_url == bug_tracker_url:
if sibling_task.is_complete:
return True
else:
return False
return None
# importance
#
@property
def importance(self):
if self.__importance is None:
self.__importance = self.lp_bug_task.importance
return self.__importance
@importance.setter
def importance(self, value):
self.lp_bug_task.importance = value
self.lp_bug_task.lp_save()
return
# assignee
#
@property
def assignee(self):
if self.__assignee is None:
lp_assignee = self.lp_bug_task.assignee
if lp_assignee is not None:
self.__assignee = Person(None, lp_assignee)
return self.__assignee
@assignee.setter
def assignee(self, value):
self.lp_bug_task.assignee = value
self.lp_bug_task.lp_save()
return
@property
def assignee_name(self):
if self.assignee is not None:
return o2str(self.assignee.username)
else:
return None
# date_assigned
#
@property
def date_assigned(self):
if self.__date_assigned is None:
self.__date_assigned = self.lp_bug_task.date_assigned
return self.__date_assigned
# date_closed
#
@property
def date_closed(self):
if self.__date_closed is None:
self.__date_closed = self.lp_bug_task.date_closed
return self.__date_closed
# date_confirmed
#
@property
def date_confirmed(self):
if self.__date_confirmed is None:
self.__date_confirmed = self.lp_bug_task.date_confirmed
return self.__date_confirmed
# date_created
#
@property
def date_created(self):
if self.__date_created is None:
self.__date_created = self.lp_bug_task.date_created
return self.__date_created
# date_fix_committed
#
@property
def date_fix_committed(self):
if self.__date_fix_committed is None:
self.__date_fix_committed = self.lp_bug_task.date_fix_committed
return self.__date_fix_committed
# date_fix_released
#
@property
def date_fix_released(self):
if self.__date_fix_released is None:
self.__date_fix_released = self.lp_bug_task.date_fix_released
return self.__date_fix_released
# date_in_progress
#
@property
def date_in_progress(self):
if self.__date_in_progress is None:
self.__date_in_progress = self.lp_bug_task.date_in_progress
return self.__date_in_progress
# date_incomplete
#
@property
def date_incomplete(self):
if self.__date_incomplete is None:
self.__date_incomplete = self.lp_bug_task.date_incomplete
return self.__date_incomplete
# date_left_closed
#
@property
def date_left_closed(self):
if self.__date_left_closed is None:
self.__date_left_closed = self.lp_bug_task.date_left_closed
return self.__date_left_closed
# date_left_new
#
@property
def date_left_new(self):
if self.__date_left_new is None:
self.__date_left_new = self.lp_bug_task.date_left_new
return self.__date_left_new
# date_triaged
#
@property
def date_triaged(self):
if self.__date_triaged is None:
self.__date_triaged = self.lp_bug_task.date_triaged
return self.__date_triaged
# determine the date the importance was set using bug activity
#
@property
def date_importance_set(self):
if (self.__date_importance_set is None and
self.importance not in ['Undecided', 'Unknown']):
target = self.bug_target_name
# continue checking the activity log in case the task went
# High -> Medium -> High
for activity in self.bug.activity:
if (activity.new_value == self.importance and
activity.what_changed.split(':')[0] in target):
self.__date_importance_set = activity.date_changed
return self.__date_importance_set
# milestone
#
@property
def milestone(self):
if self.__milestone is None:
milestone = self.lp_bug_task.milestone
if milestone is not None:
self.__milestone = Milestone(self.__service, milestone)
return self.__milestone
# product
#
@property
def upstream_product(self):
if self.__upstream_product is None:
target = self.lp_bug_task.target
if target is not None:
self.__upstream_product = target.upstream_product
return self.__upstream_product
# bugtracker
#
@property
def upstream_bug_tracker(self):
if self.__upstream_bug_tracker is None:
if self.upstream_product is None:
return None
self.__upstream_bug_tracker = self.upstream_product.bug_tracker
if self.__upstream_bug_tracker is None:
# If project is in a project group, the group may have bt info
project_group = self.upstream_product.project_group
if project_group:
self.__upstream_bug_tracker = project_group.bug_tracker
return self.__upstream_bug_tracker
# related_tasks
#
@property
def related_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.lp_bug_task.related_tasks_collection)
# target
#
@property
def target(self):
if self.__target is None:
self.__target = self.lp_bug_task.target
return self.__target
@target.setter
def target(self, value):
self.lp_bug_task.target = value
self.lp_bug_task.lp_save()
# bug_watch
#
@property
def bug_watch(self):
if self.__bug_watch is None:
self.__bug_watch = self.lp_bug_task.bug_watch
return self.__bug_watch
# similar_bugs
#
@property
def similar_bugs(self):
if self.__similar_bugs is None:
self.__similar_bugs = self.lp_bug_task.findSimilarBugs()
return Bugs(self.__service, self.__similar_bugs)
# web_link
#
@property
def web_link(self):
if self.__web_link is None:
self.__web_link = self.lp_bug_task.web_link
return self.__web_link
# return a datetime.timedelta of the length a time the task has been in
# this status
#
def status_age(self):
now = datetime.datetime.now()
status = self.status
if status in ['Invalid', 'Expired', "Won't Fix"]:
try:
self.__status_age = now - self.date_closed.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
# if the task has been reopened use date_left_closed and ignore other
# date_states
elif self.date_left_closed:
try:
self.__status_age = now - self.date_left_closed.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
# only if it has not left the new state should we use date_created
elif status == 'New' and self.date_left_new is None:
try:
self.__status_age = now - self.date_created.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'Incomplete':
try:
self.__status_age = now - self.date_incomplete.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'Confirmed':
try:
self.__status_age = now - self.date_confirmed.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'Triaged':
try:
self.__status_age = now - self.date_triaged.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'In Progress':
try:
self.__status_age = now - self.date_in_progress.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'Fix Committed':
try:
self.__status_age = now - self.date_fix_committed.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
elif status == 'Fix Released':
try:
self.__status_age = now - self.date_fix_released.replace(tzinfo=None)
except AttributeError as error:
if 'NoneType' in error.message:
return None
return self.__status_age
# to_dict
#
def to_dict(self):
package = self.bug_target_display_name
source_pkg = package.replace(" (Ubuntu)", "")
return {
'date_created' : o2str(self.date_created),
'date_closed' : o2str(self.date_closed),
'date_fix_released': o2str(self.date_fix_released),
'is_complete' : self.is_complete,
'assignee' : self.assignee_name,
'target' : source_pkg,
'status' : o2str(self.status),
'importance' : o2str(self.importance),
}
# vi:set ts=4 sw=4 expandtab:
|