GithubHelp home page GithubHelp logo

Don't fail on "local variable 'fullpath' referenced before assignment" it there are rpms to check about koji-containerbuild HOT 2 CLOSED

containerbuildsystem avatar containerbuildsystem commented on September 25, 2024
Don't fail on "local variable 'fullpath' referenced before assignment" it there are rpms to check

from koji-containerbuild.

Comments (2)

maxamillion avatar maxamillion commented on September 25, 2024

For what it's worth, this originates from the koji hub code.

def importImageInternal(task_id, build_id, imgdata):
    """
    Import image info and the listing into the database, and move an image
    to the final resting place. The filesize may be reported as a string if it
    exceeds the 32-bit signed integer limit. This function will convert it if
    need be. This is the completeBuild for images; it should not be called for
    scratch images.

    imgdata is:
    arch - the arch if the image
    files - files associated with the image (appliances have multiple files)
    rpmlist - the list of RPM NVRs installed into the image
    """
    host = Host()
    host.verify()
    task = Task(task_id)
    task.assertHost(host.id)

    koji.plugin.run_callbacks('preImport', type='image', image=imgdata)

    # import the build output
    build_info = get_build(build_id, strict=True)
    workpath = koji.pathinfo.task(imgdata['task_id'])
    imgdata['relpath'] = koji.pathinfo.taskrelpath(imgdata['task_id'])
    archives = []
    for imgfile in imgdata['files']:
        fullpath = os.path.join(workpath, imgfile)
        archivetype = get_archive_type(imgfile)
        logger.debug('image type we are importing is: %s' % archivetype)
        if not archivetype:
            raise koji.BuildError, 'Unsupported image type'
        archives.append(import_archive(fullpath, build_info, 'image', imgdata))

    # upload logs
    logs = [f for f in os.listdir(workpath) if f.endswith('.log')]
    for logfile in logs:
        logsrc = os.path.join(workpath, logfile)
        logdir = os.path.join(koji.pathinfo.build(build_info),
                              'data/logs/image')
        koji.ensuredir(logdir)
        final_path = os.path.join(logdir, os.path.basename(logfile))
        if os.path.exists(final_path):
            raise koji.GenericError("Error importing build log. %s already exists." % final_path)
        if os.path.islink(logsrc) or not os.path.isfile(logsrc):
            raise koji.GenericError("Error importing build log. %s is not a regular file." % logsrc)
        os.rename(logsrc, final_path)
        os.symlink(final_path, logsrc)

    # record all of the RPMs installed in the image(s)
    # verify they were built in Koji or in an external repo
    rpm_ids = []
    for an_rpm in imgdata['rpmlist']:
        location = an_rpm.get('location')
        if location:
            data = add_external_rpm(an_rpm, location, strict=False)
        else:
            data = get_rpm(an_rpm, strict=True)
        rpm_ids.append(data['id'])

    # associate those RPMs with the image
    q = """INSERT INTO image_listing (image_id,rpm_id)
           VALUES (%(image_id)i,%(rpm_id)i)"""
    for archive in archives:
        sys.stderr.write('working on archive %s' % archive)
        if archive['filename'].endswith('xml'):
            continue
        sys.stderr.write('associating installed rpms with %s' % archive['id'])
        for rpm_id in rpm_ids:
            _dml(q, {'image_id': archive['id'], 'rpm_id': rpm_id})

    koji.plugin.run_callbacks('postImport', type='image', image=imgdata,
                              fullpath=fullpath)

https://pagure.io/koji/blob/master/f/hub/kojihub.py#_7759

Which might be a bug in kojihub itself since it's setting a value inside a loop that may or may not execute based on the iterator being non-zero in length but then the variable is referenced blindly such that is is assumed to always be populated or assigned.

from koji-containerbuild.

lcarva avatar lcarva commented on September 25, 2024

This issue has not been since likely because we've moved to content generator API and have consolidated tasks into single buildContainer.

from koji-containerbuild.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.