def prompt_project(arguments): """prompts the user for a project, if not passed in as a argument""" projects = Project.all() # Do not prompt -- and auto select the one project if a account only has one project if len(projects) == 1: return projects[0] if arguments['--project-index'] is not None: try: idx = int(arguments['--project-index']) - 1 project = projects[idx] return project except: print 'Yikes, that did not work -- try again?' exit() while True: print "Select a Project:" for idx, project in enumerate(projects): print "[{}] {}".format(idx + 1, project.name) s = raw_input('>> ') try: project = projects[int(s) - 1] except: print 'Hmmm, that did not work -- try again?' continue break return project
def load_project(cls, project_id): url = "https://www.pivotaltracker.com/services/v3/projects/%s" % project_id response = _perform_pivotal_get(url) project_node = ET.fromstring(response.text) name = _parse_text(project_node, 'name') return Project(project_id, name)
def prompt_project(arguments): """prompts the user for a project, if not passed in as a argument""" projects = Project.all() # Do not prompt -- and auto select the one project if a account only has one project if len(projects) == 1: return projects[0] if arguments['--project-index'] is not None: try: idx = int(arguments['--project-index']) - 1 project = projects[idx] return project except: print 'Yikes, that did not work -- try again?' exit() while True: print "Select a Project:" for idx, project in enumerate(projects): print "[{}] {}".format(idx+1, project.name) s = raw_input('>> ') try: project = projects[int(s) - 1] except: print 'Hmmm, that did not work -- try again?' continue break return project
def all(cls): """returns all projects for the given user""" projects_url = 'https://www.pivotaltracker.com/services/v3/projects' response = _perform_pivotal_get(projects_url) root = ET.fromstring(response.text) if root is not None: return [Project.from_node(project_node) for project_node in root]
def find(cls, story_id, project_index=None): project = None if project_index is None: project = find_project_for_story(story_id) else: project = Project.all()[project_index] if project is not None: return project.load_story(story_id) else: return None
def find_project_for_story(story_id): """If we have multiple projects, will loop through the projects to find the one with the given story. returns None if not found """ for project in Project.all(): story = project.load_story(story_id) if story is not None: return project #Not found print "No project found for story: #{}".format(story_id) return None
def from_node(cls, project_node): name = _parse_text(project_node, 'name') id = _parse_text(project_node, 'id') point_scale = _parse_array(project_node, 'point_scale') return Project(id, name, point_scale)
def get_project_by_index(index): return Project.all()[index]