-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spread, tests: use prebuilt gojq, add simple tool for fetching files #14738
Open
bboozzoo
wants to merge
7
commits into
canonical:master
Choose a base branch
from
bboozzoo:bboozzoo/gojq-from-release-tarballs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
50b9ecb
tests/lib/tools/simpleget: simple fetcher, wget/curl replacement
bboozzoo 5920877
tests/lib/prepare-restore: do not build gojq
bboozzoo f49c0a7
spread: fetch and set up gojq
bboozzoo a656a55
spread: add URL to prebuilt armhf binaries
bboozzoo 7db1c0f
fixup! tests/lib/tools/simpleget: simple fetcher, wget/curl replacement
bboozzoo c01b1a6
fixup! tests/lib/tools/simpleget: simple fetcher, wget/curl replacement
bboozzoo f10ef73
fixup! tests/lib/tools/simpleget: simple fetcher, wget/curl replacement
bboozzoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,15 +608,6 @@ prepare_project() { | |
disable_journald_rate_limiting | ||
disable_journald_start_limiting | ||
fi | ||
|
||
# native jq replacement, but still with some incompatibilies, see | ||
# https://github.com/itchyny/gojq | ||
# major differences: | ||
# - map keys are sorted by default | ||
# - with --yaml-input, can parse YAML | ||
GOBIN=$PROJECT_PATH/tests/bin \ | ||
CGO_ENABLED=0 \ | ||
go install github.com/itchyny/gojq/cmd/[email protected] | ||
} | ||
|
||
prepare_project_each() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# note this script needs to run on Python as old as 3.6 | ||
import os.path | ||
import argparse | ||
import logging | ||
import datetime | ||
import tempfile | ||
from urllib import request | ||
from urllib.parse import urlparse | ||
|
||
|
||
def parse_arguments() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="simple file getter") | ||
parser.add_argument("-o", "--output", help="output file name") | ||
parser.add_argument("URL", help="download URL") | ||
return parser.parse_args() | ||
|
||
|
||
def main() -> None: | ||
logging.basicConfig( | ||
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.DEBUG | ||
) | ||
opts = parse_arguments() | ||
|
||
fromurl = urlparse(opts.URL).path | ||
output = os.path.basename(fromurl) | ||
if opts.output: | ||
output = opts.output | ||
|
||
if os.path.exists(output): | ||
raise RuntimeError("output path {} already exists".format(output)) | ||
|
||
total = 0 | ||
|
||
def _report(blocks: int, bsize: int, tot: int): | ||
nonlocal total | ||
total = tot | ||
logging.debug("got %d/%d kB", blocks * bsize / 1024.0, total / 1024.0) | ||
|
||
# create a temp in the same directory as output | ||
outdir = os.path.dirname(output) | ||
|
||
with tempfile.NamedTemporaryFile(mode="wb", dir=outdir, delete=False) as outf: | ||
name = outf.name | ||
outf.close() | ||
try: | ||
now = datetime.datetime.now() | ||
fn, _ = request.urlretrieve( | ||
opts.URL, filename=outf.name, reporthook=_report | ||
) | ||
after = datetime.datetime.now() | ||
|
||
os.rename(fn, output) | ||
except: | ||
os.unlink(name) | ||
raise | ||
|
||
speed = float(total) / (after - now).total_seconds() / 1024.0 | ||
logging.info("wrote %d bytes to %s, speed %.02f kB/s", total, output, speed) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're using urllib, is there a reason why not to use
urllib.request.urlretrieve
? Then the code would just be:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use urlretrieve, since it's handling a bit more errors.