[master][PATCH] Add automatic fetching of RPMs for new Defines & Requires

Brian C. Lane bcl at redhat.com
Wed Jul 24 19:06:39 UTC 2013


On Wed, Jul 24, 2013 at 03:03:16PM +0200, Martin Kolman wrote:
> When the -f or --fetch flag is used, the Anaconda spec file
> diff will be checked for new packages specified with Defines and
> Requires and will then automatically download and include RPMs
> belonging to those packages in the updates image.

Nice idea!

> +RPM_FOLDER_NAME = "updates_rpm_cache"

This should probably go in ~/.updates_rpm_cache so that it doesn't get
clobbered by a git clean -xdf

> +KOJI_BASE_URL = "http://kojipkgs.fedoraproject.org//packages/%s/%s/%s/%s/%s"
>  
>  def getArchiveTag(configure, spec):
>      tag = ""
> @@ -82,6 +88,19 @@ def getArchiveTagOffset(configure, spec, offset):
>      except IndexError:
>          return tag
>  
> +def get_anaconda_version():
> +    """Get current anaconda version as string from the configure script"""
> +    f = open("configure.ac", "rc")
> +    match = re.search(r"AC_INIT\(\[.*\],\ \[(.*)\],\ \[.*\]\)", f.read())
> +    f.close()
> +    return match.groups()[0]
> +
> +def get_fedora_version():
> +    """Return integer representing current Fedora number,
> +    based on Anaconda version"""
> +    anaconda_version = get_anaconda_version()
> +    return int(anaconda_version.split(".")[0])
> +
>  def doGitDiff(tag, args=[]):
>      proc = subprocess.Popen(['git', 'diff', '--name-status', tag] + args,
>                              stdout=subprocess.PIPE,
> @@ -90,6 +109,44 @@ def doGitDiff(tag, args=[]):
>      lines = proc[0].split('\n')
>      return lines
>  
> +def doGitContentDiff(tag, args=[]):
> +    proc = subprocess.Popen(['git', 'diff', tag] + args,
> +                            stdout=subprocess.PIPE,
> +                            stderr=subprocess.PIPE).communicate()
> +    lines = proc[0].split('\n')
> +    return lines
> +
> +def download_with_progress(url, path):
> +    try:
> +        request = urllib2.urlopen(url)
> +        f = open(path, 'wb')

Using with open() as f: saves you the close and closes on errors.


> +        metadata = request.info()
> +        size = int(metadata.getheaders("Content-Length")[0])
> +        print("Downloading: {0} Bytes: {1}".format(url, size))
> +        download_size = 0
> +        block_size = 8192

8K is way too small a buffer. Really, using python to read and write
like this is really inefficient -- I'd just shell out to wget or curl
for the download, they can do progress reporting and are much more
efficient.

> +def check_for_new_packages(tag, arch):
> +    """Download any new packages added to Requires and Defines
> +    since the given tag, return list of RPM paths"""

Multiline docstrings should end with """ on a line by themselves.

> +        # leave only results that are ither noarch or are built

type: either


> +        # for the current architecture
> +        allowed = ("noarch.rpm", "%s.rpm" % arch)
> +        results = [x for x in results if x['name'].endswith(allowed)]
> +        if results:  # any packages left ?
> +            rpm_name = results[0]['name']
> +            print("RPM found: %s" % rpm_name)
> +            rpm_id = results[0]['id']
> +            # get info about the RPM to
> +            # get the arch and build_id
> +            result = kojiclient.getRPM(rpm_id)
> +            arch = result['arch']
> +            release = result['release']
> +            build_id = result['build_id']
> +            # so we can get the toplevel package name and version
> +            result = kojiclient.getBuild(build_id)
> +            toplevel_name = result['package_name']
> +            toplevel_version = result['version']
> +            # and use the information to build the URL
> +            url = KOJI_BASE_URL % (toplevel_name, toplevel_version,
> +                                   release, arch, rpm_name)

Does result have name in it as well? You could make KOJI_BASE_URL a
.format() style string and just pass the result dict to it.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 482 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/anaconda-patches/attachments/20130724/03b29263/attachment-0001.sig>


More information about the anaconda-patches mailing list