Exemple #1
0
def publish():
    for key, value in publishVersions.items():
        if not helper.getUserConfirm(f"publish for {key}"):
            continue
        config = os.path.join(constants.ARTIFACTFOLDER, key)
        if not os.path.exists(config):
            print("can not find publish config. create new")
            with open(
                    os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                 "config_template")) as f:
                stringData = f.read()
            t = Template(stringData)
            # retrieve password from keyvault
            pw = get_secret("functionlinuxpublish")
            print("trying to construct a config file")
            with open(config, "w") as f:
                f.write(t.safe_substitute(PW=pw, REPO=value))
        helper.printReturnOutput([
            "repoapi_client", "-config",
            os.path.join(constants.ARTIFACTFOLDER, key), "-addfile",
            os.path.join(
                constants.ARTIFACTFOLDER,
                f"{constants.PACKAGENAME}_{returnDebVersion(constants.VERSION)}.deb"
            )
        ],
                                 confirm=True)
def preparePackage():
    os.chdir(constants.DRIVERROOTDIR)

    debianVersion = returnDebVersion(constants.VERSION)
    packageFolder = f"{constants.PACKAGENAME}_{debianVersion}"
    buildFolder = os.path.join(os.getcwd(), constants.BUILDFOLDER, packageFolder)
    helper.linuxOutput(buildFolder)

    os.chdir(buildFolder)
    document = os.path.join("usr", "share", "doc", constants.PACKAGENAME)
    os.makedirs(document)
    # write copywrite
    print("include MIT copyright")
    scriptDir = os.path.abspath(os.path.dirname(__file__))
    shutil.copyfile(os.path.join(scriptDir, "copyright"), os.path.join(document, "copyright"))
    # write changelog
    with open(os.path.join(scriptDir, "changelog_template")) as f:
        stringData = f.read()  # read until EOF
    t = Template(stringData)
    # datetime example: Tue, 06 April 2018 16:32:31
    time = datetime.datetime.utcnow().strftime("%a, %d %b %Y %X")
    with open(os.path.join(document, "changelog.Debian"), "w") as f:
        print(f"writing changelog with date utc: {time}")
        f.write(t.safe_substitute(DEBIANVERSION=debianVersion, DATETIME=time, VERSION=constants.VERSION, PACKAGENAME=constants.PACKAGENAME))
    # by default gzip compress file in place
    output = helper.printReturnOutput(["gzip", "-9", "-n", os.path.join(document, "changelog.Debian")])
    helper.chmodFolderAndFiles(os.path.join("usr", "share"))

    debian = "DEBIAN"
    os.makedirs(debian)
    # get all files under usr/ and produce a md5 hash
    print("trying to produce md5 hashes")
    with open('DEBIAN/md5sums', 'w') as md5file:
        # iterate over all files under usr/
        # get their md5sum
        for dirpath, _, filenames in os.walk('usr'):
            for f in filenames:
                filepath = os.path.join(dirpath, f)
                if not os.path.islink(filepath):
                    h = helper.produceHashForfile(filepath, 'md5', Upper=False)
                    md5file.write(f"{h}  {filepath}\n")

    # produce the control file from template
    deps = []
    for key, value in constants.LINUXDEPS.items():
        entry = f"{key} ({value})"
        deps.append(entry)
    deps = ','.join(deps)
    with open(os.path.join(scriptDir, "control_template")) as f:
        stringData = f.read()
    t = Template(stringData)
    with open(os.path.join(debian, "control"), "w") as f:
        print("trying to write control file")
        f.write(t.safe_substitute(DEBIANVERSION=debianVersion, PACKAGENAME=constants.PACKAGENAME, DEPENDENCY=deps))
    helper.chmodFolderAndFiles(debian)

    os.chdir(constants.DRIVERROOTDIR) 
    output = helper.printReturnOutput(["fakeroot", "dpkg-deb", "--build",
                   os.path.join(constants.BUILDFOLDER, packageFolder), os.path.join(constants.ARTIFACTFOLDER, packageFolder+".deb")])
    assert(f"building package '{constants.PACKAGENAME}'" in output)
Exemple #3
0
def preparePackage():
    os.chdir(constants.DRIVERROOTDIR)

    rpmVersion = returnRpmVersion(constants.VERSION)
    packageFolder = f"{constants.PACKAGENAME}-{rpmVersion}"
    buildFolder = os.path.join(os.getcwd(), constants.BUILDFOLDER,
                               packageFolder)
    helper.linuxOutput(buildFolder)

    # massage files then put them into ~/rpmbuild/SOURCES
    # setting up rpm packaging work space at ~/rpmbuild
    helper.printReturnOutput(["rpmdev-setuptree"])
    RpmBuildAbs = os.path.join(os.environ['HOME'], "rpmbuild")

    os.chdir(buildFolder)
    # tar the build/ and put it in rpmbuild/SOURCE
    helper.printReturnOutput([
        "tar", "-czvf",
        os.path.join(RpmBuildAbs, "SOURCES", f"{packageFolder}.tar.gz"), "../"
    ])

    print("produce .spec under ~/rpmbuild/SPECS/")
    scriptDir = os.path.abspath(os.path.dirname(__file__))
    with open(os.path.join(scriptDir, "spec_template")) as f:
        stringData = f.read()
    t = Template(stringData)
    time = datetime.datetime.utcnow().strftime("%a %b %d %Y")
    deps = []
    for key, value in constants.LINUXDEPS.items():
        entry = f"{key} {value}"
        deps.append(entry)
    deps = ",".join(deps)
    with open(
            os.path.join(RpmBuildAbs, "SPECS",
                         f"{constants.PACKAGENAME}.spec"), 'w') as f:
        f.write(
            t.safe_substitute(PACKAGENAME=constants.PACKAGENAME,
                              RPMVERSION=rpmVersion,
                              DEPENDENCY=deps,
                              DATE=time))

    os.chdir(os.path.join(RpmBuildAbs, "SPECS"))
    output = helper.printReturnOutput(
        ["rpmbuild", "-bb", f"{constants.PACKAGENAME}.spec"])

    # get package name from output
    # Wrote: /home/shun/rpmbuild/RPMS/x86_64/azure-functions-core-tools-2.0.1~beta.33-1.fc27.x86_64.rpm
    suffix = ".rpm"
    prefix = "RPMS/x86_64"
    end = output.find(suffix) + len(suffix)
    start = output.rfind(prefix, 0, end) + len(prefix) + 1
    rpmName = output[start:end]

    # ~/rpmbuild/RPMS is where we find output RPMS, we are going to copy it to constants.ARTIFACT
    print(f"copy result to {os.path.join(constants.ARTIFACTFOLDER, rpmName)}")
    shutil.copyfile(
        os.path.join(RpmBuildAbs, prefix, rpmName),
        os.path.join(constants.DRIVERROOTDIR, constants.ARTIFACTFOLDER,
                     rpmName))
Exemple #4
0
def installPackage():
    chocoVersion = getChocoVersion(constants.VERSION)
    nupkg = os.path.join(constants.ARTIFACTFOLDER,
                         f"{constants.PACKAGENAME}.{chocoVersion}.nupkg")
    output = printReturnOutput(["choco", "install", nupkg, '-y'])
    firstTime = f"{constants.PACKAGENAME} package files install completed" in output
    deja = f"{constants.PACKAGENAME} v{chocoVersion} already installed" in output
    assert (firstTime or deja)
def installPackage():
    debVersion = returnDebVersion(constants.VERSION)
    deb = os.path.join(constants.ARTIFACTFOLDER,f"{constants.PACKAGENAME}_{debVersion}.deb")
    # -f fix broken dependency
    output = helper.printReturnOutput(["sudo", "apt", "install", "-f", "./"+deb, "-y"])
    coreTools = f"Setting up {constants.PACKAGENAME} ({debVersion})" in output
    coreDeps = True
    # if dotnet core sdk is installed, dependency will not be installed again
    # for key in constants.LINUXDEPS.keys():
    #     coreDeps = (f"Setting up {key}" in output) and coreDeps
    deja = f"{constants.PACKAGENAME} is already the newest version ({debVersion})" in output
    assert((coreTools and coreDeps) or deja)
Exemple #6
0
def uninstallPackage():
    debVersion = returnDebVersion(constants.VERSION)
    output = helper.printReturnOutput(
        ["sudo", "dpkg", "--remove", constants.PACKAGENAME])
    assert (f"Removing {constants.PACKAGENAME} ({debVersion})" in output)
    output = helper.printReturnOutput(["sudo", "apt-get", "autoremove", "-y"])
Exemple #7
0
def preparePackage():
    fileName_x86 = f"Azure.Functions.Cli.win-x86.{constants.VERSION}.zip"
    fileName_x64 = f"Azure.Functions.Cli.win-x64.{constants.VERSION}.zip"
    url_x86 = f'https://functionscdn.azureedge.net/public/{constants.VERSION}/{fileName_x86}'
    url_x64 = f'https://functionscdn.azureedge.net/public/{constants.VERSION}/{fileName_x64}'

    # version used in url is provided from user input
    # version used for packaging nuget packages needs a slight modification
    chocoVersion = getChocoVersion(constants.VERSION)

    # download the zip
    # output to local folder
    #  -- For 32 bit
    if not os.path.exists(fileName_x86):
        print(f"downloading from {url_x86}")
        wget.download(url_x86)
    #  -- For 64 bit
    if not os.path.exists(fileName_x64):
        print(f"downloading from {url_x64}")
        wget.download(url_x64)

    # get the checksums
    fileHash_x86 = produceHashForfile(fileName_x86, HASH)
    fileHash_x64 = produceHashForfile(fileName_x64, HASH)

    tools = os.path.join(constants.BUILDFOLDER, "tools")
    os.makedirs(tools)

    # write install powershell script
    scriptDir = os.path.abspath(os.path.dirname(__file__))
    with open(os.path.join(scriptDir, "installps_template")) as f:
        # TODO stream replace instead of reading the entire string into memory
        stringData = f.read()
    t = Template(stringData)
    with open(os.path.join(tools, "chocolateyinstall.ps1"), "w") as f:
        print("writing install powershell script")
        f.write(
            t.safe_substitute(ZIPURL_X86=url_x86,
                              ZIPURL_X64=url_x64,
                              PACKAGENAME=constants.PACKAGENAME,
                              CHECKSUM_X86=fileHash_x86,
                              CHECKSUM_X64=fileHash_x64,
                              HASHALG=HASH))

    # write nuspec package metadata
    with open(os.path.join(scriptDir, "nuspec_template")) as f:
        stringData = f.read()
    t = Template(stringData)
    nuspecFile = os.path.join(constants.BUILDFOLDER,
                              constants.PACKAGENAME + ".nuspec")
    with open(nuspecFile, 'w') as f:
        print("writing nuspec")
        f.write(
            t.safe_substitute(PACKAGENAME=constants.PACKAGENAME,
                              CHOCOVERSION=chocoVersion))

    # run choco pack, stdout is merged into python interpreter stdout
    output = printReturnOutput([
        "choco", "pack", nuspecFile, "--outputdirectory",
        constants.ARTIFACTFOLDER
    ])
    assert ("Successfully created package" in output)
Exemple #8
0
def uninstallPackage():
    output = printReturnOutput(["choco", "uninstall", constants.PACKAGENAME])
    assert (f"{constants.PACKAGENAME} has been successfully uninstalled"
            in output)