def GetArtifacts(self): if not self.CheckThrottle(): return (500, "Not retrieving due to throttle") result = urlfetch.fetch(ARTIFACTS_DIR, validate_certificate=True) if not result.status_code == 200: return (result.status_code, "Error fetching %s from github" % ARTIFACTS_DIR) dir_listing = json.loads(result.content) filenames = [x["name"] for x in dir_listing] graph = artifact.ArtifactGraph() for artifactfile in filenames: url = urlparse.urljoin(ARTIFACTS_DIR, artifactfile) result = urlfetch.fetch(url, validate_certificate=True) if not result.status_code == 200: return (result.status_code, "Error fetching %s from github" % url) yaml_content = base64.decodestring(json.loads(result.content)["content"]) artifact_obj = artifact.Artifact(parent=artifact.ARTIFACT_STORE_KEY, filename=artifactfile, content=yaml_content) artifact_obj.put() memcache.add("last_github_fetch_time", datetime.now()) return (200, "Retrieved artifact files: %s" % filenames)
def testLoadFromStore(self): test_parent_key = ndb.Key("ArtifactStore", "default") with mock.patch("artifact.ARTIFACT_STORE_KEY", test_parent_key) as mock_key: artifact_obj = artifact.Artifact(parent=test_parent_key, filename="all.yaml", content=self.yamlstring) artifact_obj.put() graph = artifact.ArtifactGraph() graph.LoadGraphFromDataStore() self._CheckGraph(graph)
def get(self): graph = memcache.get("artifact_graph") if not graph: # Try to get a fresh version github_fetch.GitHubFetch().GetArtifacts() # Load whatever we have from the datastore graph = artifact.ArtifactGraph(top_level="Artifacts") graph.LoadGraphFromDataStore() memcache.add("artifact_graph", graph) self.response.write(graph.GetJSONTree("Artifacts"))
def get(self): d3json = memcache.get("d3json") if not d3json: graph = memcache.get("d3artifact_graph") if not graph: # Try to get a fresh version github_fetch.GitHubFetch().GetArtifacts() # Load whatever we have from the datastore graph = artifact.ArtifactGraph() graph.LoadGraphFromDataStore() memcache.add("d3artifact_graph", graph) d3json = graph.GetD3JSON() memcache.add("d3json", d3json) self.response.write(d3json)
def testInitializeFromYAMLBuffers(self): graph = artifact.ArtifactGraph() graph.InitializeFromYAMLBuffers([self.windows, self.bootstrap, self.linux]) self._CheckGraph(graph)