Exemplo n.º 1
0
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)
Exemplo n.º 2
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)