def init(section): print color.success_blue('# ') + 'Fetching stories from Backlog and Queue...' progress.update(0, 2) backlog_stories = filter_not_accepted(section.backlog.fetch_stories()) backlog_stories_sorted = effort_sorted(backlog_stories) progress.update(1, 2) queue_backlog = filter_backlog(section.queue.fetch_stories()) progress.finish() print color.success_blue('# ') + 'Writing original story order to config file...' section.order = map(lambda story: (story.id, story.current_state), backlog_stories) section.write_order() progress.finish() def move_to_estimator(story, origin): story.description = getattr(story, 'description', '') + '\n' + origin_key + origin story.sync_to_project(section.estimator, safe=True) for story in backlog_stories_sorted: if story.story_type == 'release' and story.current_state == 'unscheduled': story.current_state = 'unstarted' continue if story.story_type != 'release' and story.current_state in ['unscheduled', 'unstarted']: story.current_state = 'started' if not hasattr(story, 'estimate') and story.is_estimatable(): print color.warn('Warning: ') + 'Story %s has no estimate. Adding an estimate of one; this is needed to start the story in Estimator.' % story.name story.estimate = 1 print color.success_blue('# ') + 'Moving stories from Backlog to Estimator...' progress.iter(backlog_stories_sorted, move_to_estimator, 'backlog') for story in queue_backlog: story.current_state = 'unscheduled' print color.success_blue('# ') + 'Moving stories from Queue to Estimator...' progress.iter(queue_backlog[::-1], move_to_estimator, 'queue')
def run_session(section): if section.has_estimator_id(): print color.success_blue('# ') + 'Loaded existing Estimator session' else: print color.success_blue('# ') + 'No existing Estimator session found, starting new session...' print color.success_blue('# ') + 'Making backup of Queue and Backlog...' backup.backup_project(section.queue) progress.update(1, 2) backup.backup_project(section.backlog) progress.finish() try: section.estimator = create_estimator(section) section.write_estimator_id() try: print color.success_blue('# ') + 'Sharing Estimator with all members in account...' share_estimator_with_account(section) except Exception: pass except RuntimeError: est_id = raw_input(color.err('ERROR: ') + 'Estimator project already exists, but was not found in the config file. Please enter id of the Estimator project: ') section.estimator = piv.Project.load(int(est_id)) section.write_estimator_id() section.imported = False section.write_imported() if not section.has_imported(): stories = section.estimator.fetch_stories() if len(stories) != 0: print color.success_blue('# ') + 'Estimator project has not imported all the stories from Queue and Backlog; continuing imports...' init(section) section.imported = True section.write_imported() print color.success_blue('# ') + 'Estimator project at: https://www.pivotaltracker.com/n/projects/' + str(section.estimator.id) query_user_input(section) print color.success_blue('# ') + 'Making backup of Estimator...' backup.backup_project(section.estimator) progress.finish() finalize(section)
def finalize(section): print color.success_blue('# ') + 'Fetching stories from Estimator...' estimator_stories = section.estimator.fetch_stories() estimator_backlog = filter_backlog(estimator_stories) estimator_icebox = filter_icebox(estimator_stories) # stories that originally came from the backlog from_backlog = filter(lambda story: parse_tag(story, origin_key) == 'backlog', estimator_backlog) # stories that originally came from the queue from_queue = filter(lambda story: parse_tag(story, origin_key) == 'queue', estimator_backlog) # newly created stories no_from = filter(lambda story: story not in (from_backlog+from_queue), estimator_backlog) progress.finish() for story in estimator_icebox: if parse_tag(story, effort_key) == 'backlog': print color.warn('Warning: ') + 'Story \"%s\" is from the backlog, but was placed in Estimator icebox. It will be moved to backlog of Queue.' % story.name print color.success_blue('# ') + 'Filtering out nonexistant stories...' existing_backlog = get_existing(from_backlog, section.estimator) print color.success_blue('# ') + 'Restoring states and moving stories from Backlog...' restore_states(existing_backlog, section.order) progress.iter(existing_backlog, lambda story: story.sync_to_project(section.backlog,safe=True)) print color.success_blue('# ') + 'Ordering stories originally from Backlog...' order_backlog(existing_backlog, section.order) print color.success_blue('# ') + 'Moving new stories from Queue into icebox of Backlog...' progress.iter(list(reversed(from_queue)), move_to_icebox, section.backlog) print color.success_blue('# ') + 'Moving stories created in Estimator to icebox of Backlog...' progress.iter(no_from, move_to_icebox, section.backlog) print color.success_blue('# ') + 'Moving stories from icebox of Estimator to backlog of Queue...' progress.iter(estimator_icebox, move_to_backlog, section.queue) print color.success_blue('# ') + 'Formatting tags...' progress.iter(estimator_stories, finalize_tags) print color.success_blue('# ') + 'Deleting Estimator...' section.estimator.delete() progress.finish() abandon_session_config(section)