Skip to content

Instantly share code, notes, and snippets.

@muratg
Last active November 5, 2018 22:42
Show Gist options
  • Save muratg/331ea258e969dba20f3981a69ff6fc1c to your computer and use it in GitHub Desktop.
Save muratg/331ea258e969dba20f3981a69ff6fc1c to your computer and use it in GitHub Desktop.
Download a given ProdConV1 build from a given origin
import urllib.request as UR
import xml.etree.ElementTree as ET
# ------------------------------------------------------------------------------------------------------------------------------------------------
def download_nupkgs(build_xml_url, origin_build_names):
### HELPER FUNCTIONS
def get_build_xml(build_xml_path):
UR.urlretrieve(build_xml_path, 'build.xml')
def parse_build_xml_orchestrated_endpoint():
tree = ET.parse('./build.xml')
root = tree.getroot()
endpoint = root.find('Endpoint')
assert endpoint.attrib['Id'] == 'Orchestrated'
return endpoint
def get_url_from_endpoint(endpoint):
url = endpoint.attrib['Url']
return url.replace('/index.json', '')
def get_pkglist_from_endpoint(endpoint):
packages = endpoint.findall('Package')
return packages
def filter_pkglist(pkgs, origin_build_names):
return [(pkg.attrib['Id'], pkg.attrib['Version']) for pkg in pkgs
if pkg.attrib['OriginBuildName'] in origin_build_names # originated from ASP.NET
and 'NonShipping' not in pkg.attrib] # remove non shipping packages
def map_pkgs_to_urls(pkgs, root_url):
## links are upper case, but files are actually lowercase in the blob storage
return [(f"{pkg[0]}.{pkg[1]}.nupkg", f"{root_url}/flatcontainer/{pkg[0].lower()}/{pkg[1]}/{pkg[0].lower()}.{pkg[1]}.nupkg") for pkg in pkgs]
def get_shipping_pkg_urls( build_xml_path, origin_build_names):
"""
args:
build_xml_path: path to build.xml file
origin_build_names: list of OriginBuildName values to be filtered in
output:
Tuple. (pkg_name, pkg_url)
notes:
This filters out "NonShipping = 'true'" packages as well
"""
print('Downloading: ', build_xml_path)
get_build_xml(build_xml_path)
endpoint = parse_build_xml_orchestrated_endpoint()
url = get_url_from_endpoint(endpoint)
print('URL: ', url)
pkgs = get_pkglist_from_endpoint(endpoint)
filtered_pkgs = filter_pkglist(pkgs, origin_build_names)
pkg_urls = map_pkgs_to_urls(filtered_pkgs, url)
return pkg_urls
def download_pkgs(pkg_urls):
"""
args:
pkgs_urls: Tuple. (pkg_name, pkg_url)
"""
for u in pkg_urls:
print('... downloading ', u[1], ' into ', u[0])
UR.urlretrieve(u[1], u[0])
## DO IT!
download_pkgs(get_shipping_pkg_urls(build_xml_url, origin_build_names))
# ------------------------------------------------------------------------------------------------------------------------------------------------
# example usage: Download 2.2 build from aspnet, aspnet_extensions and aspnet_entityframework
download_nupkgs('https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/product/cli/release/2.2/build.xml', ['aspnet', 'aspnet-extensions', 'aspnet-entityframework'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment