Speed up blueprint checking with naming convention
If the blueprint file is named beginning with the name of a project,
look there for the blueprint first.
Change-Id: I49cf48ed001945670ab900fcc76cd4c2087ddbb7
Doug Hellmann
9 years ago
73 | 73 | |
74 | 74 | def blueprint_exists(self, project_name, bp_name): |
75 | 75 | """Return boolean indicating whether the blueprint exists.""" |
76 | self.app.info('Checking for %s in %s' % (bp_name, project_name)) | |
76 | 77 | url = self.BP_URL_TEMPLATE % (project_name, bp_name) |
77 | 78 | response = requests.get(url) |
78 | return response.status_code == 200 | |
79 | if response.status_code == 200: | |
80 | self.app.info('Found %s in %s' % (bp_name, project_name)) | |
81 | return True | |
82 | return False | |
79 | 83 | |
80 | 84 | def check(self, bp_name): |
81 | 85 | """Given one blueprint name, check to see if it is valid.""" |
83 | 87 | return True |
84 | 88 | self._load_project_settings() |
85 | 89 | self.app.info('') # emit newline |
90 | candidate_project, dash, bp_name_to_find = bp_name.partition('-') | |
91 | if candidate_project in self.project_names: | |
92 | # First check the shortened name of the blueprint in the project. | |
93 | if self.blueprint_exists(candidate_project, bp_name_to_find): | |
94 | return | |
95 | # Then check the full name of the blueprint in the project. | |
96 | if self.blueprint_exists(candidate_project, bp_name): | |
97 | return | |
98 | self.app.info( | |
99 | ('Blueprint name %r looks like it starts with a project ' | |
100 | 'name, but %r was not found in project %r') % | |
101 | (bp_name, bp_name_to_find, candidate_project) | |
102 | ) | |
103 | else: | |
104 | self.app.info( | |
105 | 'Blueprint checking is faster if the file names ' | |
106 | 'start with the launchpad project name.' | |
107 | ) | |
86 | 108 | for project_name in self.project_names: |
87 | self.app.info('Checking for %s in %s' % (bp_name, project_name)) | |
88 | 109 | if self.blueprint_exists(project_name, bp_name): |
89 | self.app.info('Found %s in %s' % (bp_name, project_name)) | |
90 | 110 | self._good_bps.add(bp_name) |
91 | 111 | break |
92 | 112 | else: |