def GetNebraskaSrcFile(source_dir): """Returns path to nebraska source file. nebraska is copied to source_dir, either from a local file or by downloading from googlesource.com. """ assert os.path.isdir(source_dir), ('%s must be a valid directory.' % source_dir) nebraska_path = os.path.join(source_dir, NEBRASKA_FILENAME) checkout = path_util.DetermineCheckout() if checkout.type == path_util.CHECKOUT_TYPE_REPO: # ChromeOS checkout. Copy existing file to destination. local_src = os.path.join(constants.SOURCE_ROOT, 'src', 'platform', 'dev', 'nebraska', NEBRASKA_FILENAME) assert os.path.isfile(local_src), "%s doesn't exist" % local_src shutil.copy2(local_src, source_dir) else: # Download from googlesource. nebraska_url_path = '%s/+/%s/%s?format=text' % ( 'chromiumos/platform/dev-util', 'refs/heads/master', 'nebraska/nebraska.py') contents_b64 = gob_util.FetchUrl(constants.EXTERNAL_GOB_HOST, nebraska_url_path) osutils.WriteFile(nebraska_path, base64.b64decode(contents_b64).decode('utf-8')) return nebraska_path
def _GetQemuBinPath(): """Get prebuilt QEMU binary path from google storage.""" contents_b64 = gob_util.FetchUrl( constants.EXTERNAL_GOB_HOST, '%s?format=TEXT' % SDKFetcher.PREBUILT_CONF_PATH) binhost, path = base64.b64decode(contents_b64.read()).strip().split('=') if binhost != 'FULL_BINHOST' or not path: return None return path.strip('"')
def testUtf8Response(self): """Handle gerrit responses w/UTF8 in them.""" utf8_data = 'That\xe2\x80\x99s an error. That\xe2\x80\x99s all we know.' with mock.patch.object(gob_util, 'CreateHttpConn', autospec=False) as m: m.return_value = FakeHTTPConnection(body=utf8_data) gob_util.FetchUrl('', '') m.return_value = FakeHTTPConnection(body=utf8_data, status=502) self.assertRaises(gob_util.InternalGOBError, gob_util.FetchUrl, '', '')
def Send(self, dryrun): """Posts a comment to a gerrit review.""" body = { 'message': self._ConstructPaladinMessage(), 'notify': 'OWNER', } path = 'changes/%s/revisions/%s/review' % ( self.patch.gerrit_number, self.patch.revision) if dryrun: logging.info('Would have sent %r to %s', body, path) return gob_util.FetchUrl(self.helper.host, path, reqtype='POST', body=body)
def testConnectionTimeout(self): """Exercise the timeout process.""" # To finish the test quickly, we need to shorten the timeout. self.PatchObject(gob_util, 'REQUEST_TIMEOUT_SECONDS', 1) # Setup a 'hanging' network connection. def simulateHang(*_args, **_kwargs): time.sleep(30) self.fail('Would hang forever.') self.conn.side_effect = simulateHang # Verify that we fail, with expected timeout error. with self.assertRaises(timeout_util.TimeoutError): gob_util.FetchUrl('', '')
def GetLatestRelease(git_url, branch=None): """Gets the latest release version from the release tags in the repository. Args: git_url: URL of git repository. branch: If set, gets the latest release for branch, otherwise latest release. Returns: Latest version string. """ # TODO(szager): This only works for public release buildspecs in the chromium # src repository. Internal buildspecs are tracked differently. At the time # of writing, I can't find any callers that use this method to scan for # internal buildspecs. But there may be something lurking... parsed_url = urlparse.urlparse(git_url) path = parsed_url[2].rstrip('/') + '/+refs/tags?format=JSON' j = gob_util.FetchUrlJson(parsed_url[1], path, ignore_404=False) if branch: chrome_version_re = re.compile(r'^%s\.\d+.*' % branch) else: chrome_version_re = re.compile(r'^[0-9]+\..*') matching_versions = [ key for key in j.keys() if chrome_version_re.match(key) ] matching_versions.sort(key=distutils.version.LooseVersion) for chrome_version in reversed(matching_versions): path = parsed_url[2].rstrip() + ('/+/refs/tags/%s/DEPS?format=text' % chrome_version) fh = gob_util.FetchUrl(parsed_url[1], path, ignore_404=False) content = fh.read() if fh else None if content: deps_content = base64.b64decode(content) if CheckIfChromeRightForOS(deps_content): return chrome_version return None
def testUtf8Response502(self): self.conn.return_value = FakeHTTPConnection(body=self.UTF8_DATA, status=502) with self.assertRaises(gob_util.InternalGOBError): gob_util.FetchUrl('', '')
def testUtf8Response(self): """Handle gerrit responses w/UTF8 in them.""" self.conn.return_value = FakeHTTPConnection(body=self.UTF8_DATA) gob_util.FetchUrl('', '')
def _fetch(): fh = gob_util.FetchUrl(host, path, ignore_404=True) return fh.read() if fh else None
def _fetch(): return gob_util.FetchUrl(host, path, ignore_404=True)