Ejemplo n.º 1
0
def main():
  parser = argparse.ArgumentParser(description="Update version and hash digest of LTeX LS")
  parser.add_argument("--allow-prerelease", action="store_true",
      help="Allow prerelease versions")
  args = parser.parse_args()

  print("Retrieving list of releases of LTeX LS...")
  releases = common.requestFromGitHub("https://api.github.com/repos/valentjn/ltex-ls/releases")
  ltexLsVersion = getLatestLtexLsVersion([x["tag_name"] for x in releases],
      allowPrerelease=args.allow_prerelease)
  ltexLsVersion = str(ltexLsVersion)

  print(f"Downloading LTeX LS {ltexLsVersion}...")
  ltexLsUrl = ("https://github.com/valentjn/ltex-ls/releases/download/"
      f"{urllib.parse.quote_plus(ltexLsVersion)}/"
      f"ltex-ls-{urllib.parse.quote_plus(ltexLsVersion)}.tar.gz")
  response = common.requestFromGitHub(ltexLsUrl, decodeAsJson=False)

  print("Computing hash digest...")
  ltexLsHashDigest = hashlib.sha256(response).hexdigest()
  print(f"Hash digest is '{ltexLsHashDigest}'.")

  print("Writing version and hash digest to 'src/DependencyManager.ts'...")
  dependencyManagerFilePath = os.path.join(common.repoDirPath, "src", "DependencyManager.ts")
  with open(dependencyManagerFilePath, "r") as f: dependencyManagerTypescript = f.read()
  dependencyManagerTypescript = re.sub(r"(_toBeDownloadedLtexLsVersion: string = ').*?(';\n)",
      rf"\g<1>{ltexLsVersion}\g<2>", dependencyManagerTypescript)
  dependencyManagerTypescript = re.sub(
      r"(_toBeDownloadedLtexLsHashDigest: string =\n *').*?(';\n)",
      fr"\g<1>{ltexLsHashDigest}\g<2>", dependencyManagerTypescript)
  with open(dependencyManagerFilePath, "w") as f: f.write(dependencyManagerTypescript)
Ejemplo n.º 2
0
def getDownloadUrlsOfGitHubReleases(organizationName, repositoryName, tagName):
    apiUrl = (
        f"https://api.github.com/repos/{urllib.parse.quote_plus(organizationName)}/"
        f"{urllib.parse.quote_plus(repositoryName)}/releases/tags/{urllib.parse.quote_plus(tagName)}"
    )
    response = common.requestFromGitHub(apiUrl)
    return {x["name"]: x["browser_download_url"] for x in response["assets"]}
Ejemplo n.º 3
0
def downloadLtexLs():
  releasesUrl = "https://api.github.com/repos/valentjn/ltex-ls/releases"
  print(f"Fetching list of ltex-ls releases from '{releasesUrl}'...")
  releases = common.requestFromGitHub(releasesUrl)

  ltexLsVersion = getLatestCompatibleLtexLsVersion([x["tag_name"] for x in releases])
  print(f"Latest compatible release is 'ltex-ls-{ltexLsVersion}'.")

  ltexLsUrl = ("https://github.com/valentjn/ltex-ls/releases/download/"
      f"{ltexLsVersion}/ltex-ls-{ltexLsVersion}.tar.gz")
  ltexLsArchivePath = os.path.join(libDirPath, f"ltex-ls-{ltexLsVersion}.tar.gz")
  print(f"Downloading ltex-ls from '{ltexLsUrl}' to '{ltexLsArchivePath}'...")
  urllib.request.urlretrieve(ltexLsUrl, ltexLsArchivePath)

  extractLtexLs(ltexLsArchivePath)

  print("Removing ltex-ls archive...")
  os.remove(ltexLsArchivePath)
Ejemplo n.º 4
0
def main():
    print(
        f"Retrieving list of assets for tag 'jdk-{common.toBeDownloadedJavaVersion}'..."
    )
    downloadUrls = getDownloadUrlsOfGitHubReleases(
        "AdoptOpenJDK", "openjdk11-binaries",
        f"jdk-{common.toBeDownloadedJavaVersion}")
    assetFileNames = [
        x for x in downloadUrls
        if ("-jre_" in x) and (x.endswith(".zip") or x.endswith(".tar.gz"))
    ]
    assetFileNames.sort()
    hashDigests = []

    for assetFileName in assetFileNames:
        print(f"Retrieving hash digest for '{assetFileName}'...")
        response = common.requestFromGitHub(
            f"{downloadUrls[assetFileName]}.sha256.txt",
            decodeAsJson=False).decode().strip()
        match = re.match(r"^([A-Fa-f0-9]{64}) +(.*)$", response)
        hashDigest = match.group(1)
        assert match.group(2) == assetFileName
        print(f"Hash digest is '{hashDigest}'.")
        hashDigests.append(hashDigest)

    hashDigestsTypescript = "".join(
        f"    '{x}':\n      '{y}',\n"
        for x, y in zip(assetFileNames, hashDigests))

    print("Writing hash digests to 'src/DependencyManager.ts'...")
    dependencyManagerFilePath = os.path.join(common.repoDirPath, "src",
                                             "DependencyManager.ts")
    with open(dependencyManagerFilePath, "r") as f:
        dependencyManagerTypescript = f.read()
    dependencyManagerTypescript = re.sub(
        r"(_toBeDownloadedJavaHashDigests: \{\[fileName: string\]: string\} = \{\n).*?(  \};\n)",
        fr"\g<1>{hashDigestsTypescript}\g<2>",
        dependencyManagerTypescript,
        flags=re.DOTALL)
    with open(dependencyManagerFilePath, "w") as f:
        f.write(dependencyManagerTypescript)