ubuntu-bugcontrol team mailing list archive
-
ubuntu-bugcontrol team
-
Mailing list archive
-
Message #04803
[Merge] ~octagalland/ubuntu-qa-tools:lpl_common_download into ubuntu-qa-tools:master
Octavio Galland has proposed merging ~octagalland/ubuntu-qa-tools:lpl_common_download into ubuntu-qa-tools:master.
Commit message:
Allow downloading using Launchpad's _browser
Requested reviews:
Paulo Flabiano Smorigo (pfsmorigo)
Ubuntu Security Team (ubuntu-security)
For more details, see:
https://code.launchpad.net/~octagalland/ubuntu-qa-tools/+git/ubuntu-qa-tools/+merge/484537
By downloading files from LP's `*_url` fields (e.g. changes_file_url, build_log_url) using Launchpad._browser. If the rest of the tooling was migrated to use this new functionality, this would eliminate the need to keep a cookies file in our UCT environment.
--
Your team Ubuntu Bug Control is subscribed to branch ubuntu-qa-tools:master.
diff --git a/common/lpl_common.py b/common/lpl_common.py
index 7387e2c..3c5f9a1 100644
--- a/common/lpl_common.py
+++ b/common/lpl_common.py
@@ -239,12 +239,12 @@ def chunked_read(response, chunk_size=8192, outfile=None, verbose=True):
bar.finish()
return bytes_so_far
-
-def download(opener, url, filename=None, verbose=True, dryrun=False):
+def download(opener_or_lp, url, filename=None, verbose=True, dryrun=False, rewrite_uri=False):
if verbose:
print(" %s ..." % (url))
+ if dryrun:
+ print("(dry run, skipping)")
if dryrun:
- print("(dry run, skipping)")
return
if not filename:
@@ -256,8 +256,18 @@ def download(opener, url, filename=None, verbose=True, dryrun=False):
tmp = tempfile.NamedTemporaryFile(delete=False)
- response = open_url(opener, url)
- chunked_read(response, outfile=tmp, verbose=verbose)
+ if type(opener_or_lp) == Launchpad:
+ lp = opener_or_lp
+ lp_api_root_uri = str(lp._root_uri)
+ lp_root_uri = 'https://launchpad.net/'
+ if rewrite_uri and url.startswith(lp_root_uri):
+ url = url.replace(lp_root_uri, lp_api_root_uri)
+ contents = lp._browser.get(url)
+ tmp.write(contents)
+ else:
+ opener = opener_or_lp
+ response = open_url(opener, url)
+ chunked_read(response, outfile=tmp, verbose=verbose)
tmp.close()
shutil.move(tmp.name,filename)