def update_licenses(bb_dict, specfile):
    """Add the bitbake license if it is not included in the specfile."""
    if "LICENSE" in bb_dict:
        if bb_dict.get("LICENSE").lower() not in [
                l.lower() for l in specfile.licenses
        ]:
            specfile.licenses.append(bb_dict.get("LICENSE"))
            print_infile("License added: {}".format(bb_dict.get("LICENSE")))
def update_build_deps(bb_dict, specfile):
    """Add build dependencies to the buildreq set, if the bb_dict scraped build time dependencies."""
    if bb_dict.get('DEPENDS'):
        for dep in bb_dict.get('DEPENDS').split():
            dep = re.match(r"(\$\{PYTHON_PN\}\-)?([a-zA-Z0-9\-]+)", dep).group(2)
            if dep.endswith('-native'):
                dep = dep[:-7]

            specfile.buildreqs.add(dep)
            print_infile("Build dependency added: {}".format(dep))
def update_licenses(bb_dict, specfile):
    """
    The specfile contains a list of licenses for a package, if the bitbake
    license is not included in that list, add it.
    """
    if "LICENSE" in bb_dict:
        if bb_dict.get("LICENSE").lower() not in [
                l.lower() for l in specfile.licenses
        ]:
            specfile.licenses.append(bb_dict.get("LICENSE"))
            print_infile("License added: {}".format(bb_dict.get("LICENSE")))
def update_summary(bb_dict, specfile):
    """Update the default summary to the summary or description scraped from the bitbake file.

    The bitbake "SUMMARY" variable is first priority, then the "DESCRIPTION" variable. If neither
    exist, set set it back to the specfile value.
    """
    specfile.default_sum = bb_dict.get("SUMMARY") or \
        bb_dict.get("DESCRIPTION") or specfile.default_sum

    if specfile.default_sum == bb_dict.get("SUMMARY") or \
            specfile.default_sum == bb_dict.get("DESCRIPTION"):
        print_infile("Summary updated: {}".format(specfile.default_sum))
def write_cmd_files(bb_dict, dirname):
    """
    Append "do_" task commands that are scraped from the bitbake file(s). Some
    of these commands have append/prepend. These operations are performed
    prior to being added to the dict. This function appends all commands to
    as comments to their mapped file within the target directory.
    """
    for cmd_name, cmd in bb_dict.items():
        if cmd_name.startswith("do_"):
            filename = os.path.join(dirname, cmd_mappings.get(cmd_name))
            with open(filename, 'a') as cmdfp:
                cmdfp.write("# Infile parser added the following lines:\n")
                cmdfp.write("\n".join(cmd) + "\n")
            print_infile("Suggestions added to the {} file".format(
                cmd_mappings.get(cmd_name)))
Exemple #6
0
def main():
    """
    Main function for autospec
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("-g",
                        "--skip-git",
                        action="store_false",
                        dest="git",
                        default=True,
                        help="Don't commit result to git")
    parser.add_argument("-n",
                        "--name",
                        action="store",
                        dest="name",
                        default="",
                        help="Override the package name")
    parser.add_argument("-v",
                        "--version",
                        action="store",
                        dest="version",
                        default="",
                        help="Override the package version")
    parser.add_argument("url",
                        default="",
                        nargs="?",
                        help="tarball URL (e.g."
                        " http://example.com/downloads/mytar.tar.gz)")
    parser.add_argument('-a',
                        "--archives",
                        action="store",
                        dest="archives",
                        default=[],
                        nargs='*',
                        help="tarball URLs for additional source archives and"
                        " a location for the sources to be extacted to (e.g."
                        " http://example.com/downloads/dependency.tar.gz"
                        " /directory/relative/to/extract/root )")
    parser.add_argument("-l",
                        "--license-only",
                        action="store_true",
                        dest="license_only",
                        default=False,
                        help="Only scan for license files")
    parser.add_argument("-b",
                        "--skip-bump",
                        dest="bump",
                        action="store_false",
                        default=True,
                        help="Don't bump release number")
    parser.add_argument("-c",
                        "--config",
                        dest="config",
                        action="store",
                        default="/usr/share/defaults/autospec/autospec.conf",
                        help="Set configuration file to use")
    parser.add_argument("-t",
                        "--target",
                        dest="target",
                        action="store",
                        default=None,
                        help="Target location to create or reuse")
    parser.add_argument(
        "-i",
        "--integrity",
        action="store_true",
        default=False,
        help="Search for package signature from source URL and "
        "attempt to verify package")
    parser.add_argument("-p",
                        "--prep-only",
                        action="store_true",
                        default=False,
                        help="Only perform preparatory work on package")
    parser.add_argument(
        "--non_interactive",
        action="store_true",
        default=False,
        help="Disable interactive mode for package verification")
    parser.add_argument("-C",
                        "--cleanup",
                        dest="cleanup",
                        action="store_true",
                        default=False,
                        help="Clean up mock chroot after building the package")
    parser.add_argument("--infile",
                        action="store",
                        dest="infile",
                        default="",
                        help="type of input file for .specfile creation")
    parser.add_argument(
        "-m",
        "--mock-config",
        action="store",
        default="clear",
        help="Value to pass with Mock's -r option. Defaults to "
        "\"clear\", meaning that Mock will use "
        "/etc/mock/clear.cfg.")

    args = parser.parse_args()

    name, url, archives = read_old_metadata()
    name = args.name or name
    url = args.url or url
    archives = args.archives or archives
    infile_dict = {}

    if args.infile:
        infile_dict = infile_handler.infile_reader(args.infile, name)
        if not url:
            try:
                url = infile_dict.get('URL')
            except:
                pass
            else:
                print_infile("Source url found: {}".format(url))

        if infile_dict.get("LICENSE"):
            license.add_license(infile_dict.get("LICENSE"))
            print_infile("License added: {}".format(
                infile_dict.get("LICENSE")))

    if not url:
        parser.error(
            argparse.ArgumentTypeError(
                "the url argument or options.conf['package']['url'] is required"
            ))

    if len(archives) % 2 != 0:
        parser.error(
            argparse.ArgumentTypeError(
                "-a/--archives or options.conf['package']['archives'] requires an "
                "even number of arguments"))

    if args.prep_only:
        package(args, url, name, archives, "./workingdir", infile_dict)
    else:
        with tempfile.TemporaryDirectory() as workingdir:
            package(args, url, name, archives, workingdir, infile_dict)