Example #1
0
def get_srcrev_bzr(pkgname, srcname):
    """
    builpy.bzr.get_srcrev_bzr()
    function that returns the current revision number of the source branch
    """
    goto_srcdir(pkgname, srcname)
    rev = subprocess.check_output(["bzr", "revno"]).decode().rstrip('\n\r')
    goto_basedir()

    dbg(pkgname + " repo is at revno: " + rev)
    return rev
Example #2
0
def get_srcrev_git(pkgname, srcname):
    """
    builpy.git.get_srcrev_git()
    function that returns the current commit id of the repository
    """
    goto_srcdir(pkgname, srcname)
    rev = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode()
    rev = rev.rstrip('\r\n')[0:8]
    goto_basedir()

    dbg(pkgname + " repo is at commit: " + rev)
    return rev
Example #3
0
def get_srcrev(pkgname):
    """
    builpy.vcs.get_srcrev()
    generic function that returns the current revision number / commit id
    """
    dbg("Checking revision number / commit id.")
    srcname = get_srcname(pkgname)
    srctype = get_srctype(pkgname)

    if srctype == "bzr":
        return get_srcrev_bzr(pkgname, srcname)
    elif srctype == "git":
        return get_srcrev_git(pkgname, srcname)
    else:
        return None
Example #4
0
def format_version(pkgname, ver, rev):
    """
    builpy.vcs.format_version()
    generic function that returns the package version in a standard format
    """
    srctype = get_srctype(pkgname)

    if srctype == "bzr":
        return format_version_bzr(ver, rev)
    elif srctype == "git":
        return format_version_git(ver, rev)
    elif srctype == "url":
        return format_version_url(ver)
    else:
        dbg("Source type is not supported.")
Example #5
0
def get_confval(pkgname, section, key):
    """
    builpy.conf.get_confval
    generic function that reads a value from a package config file
    """
    dbg("Getting value from config file: [" + section + "]: " + key)
    assert isinstance(section, str)
    assert isinstance(key, str)

    goto_pkgdir(pkgname)
    pkgconfig = configparser.ConfigParser()
    pkgconfig.read(pkgname + ".conf")
    value = pkgconfig[section][key]
    goto_basedir()

    dbg("Got value from config file: [" + section + "]: " + key + ": " + value)
    return value
Example #6
0
def get_source(pkgname):
    """
    builpy.vcs.get_source()
    generic function that downloads the specified sources from vcs
    """
    srctype = get_srctype(pkgname)
    srcorig = get_srcorig(pkgname)
    srcdest = get_srcname(pkgname)

    if srctype == "bzr":
        return get_source_bzr(pkgname, srcorig, srcdest)
    elif srctype == "git":
        return get_source_git(pkgname, srcorig, srcdest)
    elif srctype == "url":
        return get_source_url(pkgname, srcorig, srcdest)
    else:
        dbg("Source type is not supported.")
Example #7
0
def src_export(pkgname):
    """
    builpy.vcs.src_export()
    function that exports the specified vcs repository to a tar.gz archive
    """
    pkgvers = get_pkgvers(pkgname)
    srcname = get_srcname(pkgname)
    srctype = get_srctype(pkgname)

    dbg("Exporting " + pkgname + "VCS sources to tarball for use in packaging.")

    if srctype == "bzr":
        src_export_bzr(pkgname, srcname, pkgvers)
    elif srctype == "git":
        src_export_git(pkgname, srcname, pkgvers)
    elif srctype == "url":
        pass
    else:
        dbg("Source type is not supported.")
Example #8
0
def src_update(pkgname):
    """
    builpy.vcs.src_update()
    generic function that updates the specified vcs repository
    """
    srcname = get_srcname(pkgname)
    srctype = get_srctype(pkgname)

    dbg("Checking " + srcname + " " + srctype + " repo for updates.")

    if srctype == "bzr":
        return src_update_bzr(pkgname, srcname)
    elif srctype == "git":
        return src_update_git(pkgname, srcname)
    elif srctype == "url":
        return 0
    else:
        dbg("Source type is not supported.")
        return 0
Example #9
0
def get_source_url(pkgname, orig, dest=None):
    """
    builpy.url.get_source_url()
    function that downloads a file via the specified url (wget)
    curl could also be supported in the future
    """
    quietstr = "--quiet"
    if DEBUG:
        quietstr = "--verbose"

    goto_pkgdir(pkgname)
    if dest != None:
        dbg("Downloading source tarball " + orig + " to " + dest + ".")
        subprocess.call(["wget", quietstr, orig, "-O", dest])
    else:
        dbg("Downloading source tarball " + orig + ".")
        subprocess.call(["wget", quietstr, orig])
    goto_basedir()
    return None
Example #10
0
def src_export_bzr(pkgname, srcname, pkgvers, keep=True):
    """
    builpy.bzr.src_export_bzr()
    function that exports the specified bzr branch or lightweight checkout
    to a .tar.gz archive
    """
    rev = get_srcrev_bzr(pkgname, srcname)

    strvers = format_version_bzr(pkgvers, rev)
    strpkgv = pkgname + "-" + strvers

    filename = "../" + strpkgv + ".tar.gz"

    goto_srcdir(pkgname, srcname)
    subprocess.call(["bzr", "export", filename])
    if not keep:
        subprocess.call(["rm", "-r", srcname])
    goto_basedir()

    dbg("Export to ../" + strpkgv + ".tar.gz successful.")
Example #11
0
def src_export_git(pkgname, srcname, pkgvers, keep=True):
    """
    builpy.git.src_export_git()
    function that exports the specified git repository
    """
    rev = get_srcrev_git(pkgname, srcname)

    version_str = format_version_git(pkgvers, rev)
    pkgpver_str = pkgname + "-" + version_str

    prefix_str = "--prefix=" + pkgpver_str + "/"
    target_str = "../" + pkgpver_str + ".tar.gz"

    goto_srcdir(pkgname, srcname)
    ret_code = subprocess.call(["git", "archive", prefix_str, "HEAD", "--output", target_str])
    if not keep:
        subprocess.call(["rm", "-r", srcname])
    goto_basedir()

    if ret_code:
        print("ERROR: Export to " + target_str + ".tar.gz not successful.")
    else:
        dbg("Export to " + target_str + ".tar.gz successful.")
Example #12
0
def get_source_git(pkgname, orig, dest):
    """
    builpy.git.get_source_git()
    function that downloads the specified git repository (whole or shallow)
    """
    srcname = get_srcname(pkgname)
    dbg("Checking out git repository " + orig + " to directory " + dest + ".")

    quietstr = "--quiet"
    if DEBUG:
        quietstr = "--verbose"

    goto_pkgdir(pkgname)
    subprocess.call(["git", "clone", quietstr, orig, dest])
    goto_basedir()

    dbg("Checkout to " + dest + " successful.")
    rev = get_srcrev_git(pkgname, srcname)
    dbg("Revision of checkout: " + rev)

    return rev
Example #13
0
def get_source_bzr(pkgname, orig, dest):
    """
    builpy.bzr.get_source_bzr()
    function that downloads the specified bzr branch or lightweight checkout
    """
    srcname = get_srcname(pkgname)
    dbg("Checking out bzr repository " + orig + " to directory " + dest + ".")

    quietstr = "--quiet"
    if DEBUG:
        quietstr = "--verbose"

    goto_pkgdir(pkgname)
    subprocess.call(["bzr", "branch", quietstr, orig, "./" + dest])
    goto_basedir()

    dbg("Checkout to " + dest + " successful.")
    rev = get_srcrev_bzr(pkgname, srcname)
    dbg("Revision number of checkout: " + rev)

    return rev