def test_trackable1(self): "Assure basic tracking works properly." tracker = pyt.Tracker() obj = track1(tracker) self.assertEqual(len(tracker), 1) self.assertEqual(tracker.values()[0].allocated, 1) self.assertEqual(tracker.keys()[0], 'track1') obj = None gc.collect() self.assertEqual(tracker.values()[0].deallocated, 1)
def test_trackable2(self): "Assure both objects are tracked as allocated and deallocated." tracker = pyt.Tracker() obj1 = track1(tracker) obj2 = track2(tracker) self.assertEqual(len(tracker), 2) self.assertEqual(tracker['track1'].allocated, 1) self.assertEqual(tracker['track2'].allocated, 1) obj1 = obj2 = None gc.collect() self.assertEqual(tracker['track1'].allocated, 0) self.assertEqual(tracker['track2'].allocated, 0)
class foo1(pyt.Trackable): def __init__(self, msg): self._set_data_bundle(msg) class foo2(foo1): pass class foo3(foo1): _disable_global_tracker = True t = pyt.Tracker() pyt.set_global_tracker(t) x1 = foo1('first') x2 = foo2('second') x3 = foo1('third') x4 = foo2('fourth') x5 = foo3('not to be tracked') t.dump() x3 = x4 = x5 = None t.dump() t.set_object_tracking(foo1)
def main(opts): parser = ConfigParser.RawConfigParser() parser.read(opts.credentials) cal_auth = GetCredentials(parser, 'calendar') tracker_auth = GetCredentials(parser, 'tracker') c = Calendar(opts.calendar_id, cal_auth) if opts.tracker_base_api_url.find('.google.com') != -1: tracker_auth = pytrackergoogle.TrackerAtGoogleAuth(*tracker_auth) else: tracker_auth = pytracker.HostedTrackerAuth(*tracker_auth) t = pytracker.Tracker(opts.tracker_id, tracker_auth, base_api_url=opts.tracker_base_api_url) # For now, we care only about type:release stories. # We could extend this to also include stories with # specific tags. def FilterForReleases(event): return event.title.text.find('[release') != -1 c.Visit(FilterForReleases, c.DeleteEventVisitor) xml = t.GetReleaseStoriesXml() soup = BeautifulStoneSoup(xml) batch = c.GetEventFeedForBatch() releases = soup.stories.findAll('story') logging.info('found %d releases', len(releases)) for e in releases: url = e.url.contents[0] # can't use .name -- soup would return the tag name. title = e.find('name').contents[0] # The release date is computed by Tracker and is an estimate of story # completion. release_date = pytracker.TrackerDatetimeToYMD( e.iteration.finish.contents[0]) suffix = '[release, floating]' calendar_date = release_date body = ( url + '\n\n\n\n' '[This event was automatically created based on data from Tracker]' ) # Hard deadlines are special. if e.find('deadline'): scheduled_date = pytracker.TrackerDatetimeToYMD( e.deadline.contents[0]) suffix = '[release, hard]' # Prefix the event with "SLIPPING" if release > deadline scheduled_secs = YMDToSeconds(scheduled_date) release_secs = YMDToSeconds(release_date) delta = release_secs - scheduled_secs if release_secs > scheduled_secs: title = 'SLIPPING %.1f days: %s' % (delta / 86400, title) calendar_date = scheduled_date title = title + ' ' + suffix batch.AddInsert(entry=c.CreateForBatch(title, calendar_date, body)) logging.info('%s: %s / %s', url, title, calendar_date) c.RunBatch(batch)