def _BuildModDownloads () -> None: from Automation import Distribution, Mods with open(os.path.join(Paths.TemplatesPath, "DownloadInstaller.html")) as downloadTemplateFile: downloadInstallerTemplate = downloadTemplateFile.read() with open(os.path.join(Paths.TemplatesPath, "DownloadInstallerAge.html")) as downloadTemplateFile: downloadInstallerAgeTemplate = downloadTemplateFile.read() with open(os.path.join(Paths.TemplatesPath, "DownloadFiles.html")) as downloadTemplateFile: downloadFilesTemplate = downloadTemplateFile.read() with open(os.path.join(Paths.TemplatesPath, "DownloadFilesAge.html")) as downloadTemplateFile: downloadFilesAgeTemplate = downloadTemplateFile.read() with open(os.path.join(Paths.TemplatesPath, "DownloadSources.html")) as downloadTemplateFile: downloadSourcesTemplate = downloadTemplateFile.read() with open(os.path.join(Paths.TemplatesPath, "DownloadSourcesAge.html")) as downloadTemplateFile: downloadSourcesAgeTemplate = downloadTemplateFile.read() for modNamespace, modVersions in Distribution.Releases.items(): # type: str, typing.List[Distribution.ModVersion] modBuildPath = os.path.join(Paths.DownloadsBuildPath, "mods", modNamespace.lower()) # type: str licensePath = os.path.join(modBuildPath.replace(Paths.DownloadsBuildPath + os.path.sep, ""), _licenseName) # type: str licensePath = licensePath.replace("\\", "/") with open(os.path.join(Paths.DownloadsSourcesPath, "mods", modNamespace + ".json")) as modInformationFile: modInformation = decoder.JSONDecoder().decode(modInformationFile.read()) # type: dict if not modInformation["Mod"]["Age"]: modInstallerTemplate = downloadInstallerTemplate # type: str modFilesTemplate = downloadFilesTemplate # type: str else: modInstallerTemplate = downloadInstallerAgeTemplate # type: str modFilesTemplate = downloadFilesAgeTemplate # type: str if not modInformation["Sources"]["Age"]: sourcesTemplate = downloadSourcesTemplate # type: str else: sourcesTemplate = downloadSourcesAgeTemplate # type: str mod = Mods.GetMod(modNamespace) # type: Mods.Mod modLatestVersion = mod.ReleaseLatest # type: Distribution.ModVersion modName = mod.GetName() # type: typing.Optional[str] if modName is None: modName = modNamespace latestBasePath = os.path.relpath(Paths.DownloadsBuildPath, modBuildPath).replace("\\", "/") + "/.." # type: str latestInstallerPath = os.path.join(modBuildPath, "installer/index.html") # type: str latestInstallerURL = modLatestVersion.InstallerURL # type: str latestFilesPath = os.path.join(modBuildPath, "files/index.html") # type: str latestFilesRelativePath = os.path.relpath(latestFilesPath, Paths.DownloadsBuildPath) # type: str latestFilesURL = modLatestVersion.FilesURL # type: str latestSourcesPath = os.path.join(modBuildPath, "sources/index.html") # type: str latestSourcesURL = modLatestVersion.SourcesURL # type: str _WriteDownload(latestInstallerPath, modInstallerTemplate, latestBasePath, modName, str(modLatestVersion.Version), _typeInstaller, str(modLatestVersion.GameVersion), modLatestVersion.ReleaseDate, latestFilesRelativePath, licensePath, latestInstallerURL) _WriteDownload(latestFilesPath, modFilesTemplate, latestBasePath, modName, str(modLatestVersion.Version), _typeFiles, str(modLatestVersion.GameVersion), modLatestVersion.ReleaseDate, latestFilesRelativePath, licensePath, latestFilesURL) _WriteDownload(latestSourcesPath, sourcesTemplate, latestBasePath, modName, str(modLatestVersion.Version), _typeSources, str(modLatestVersion.GameVersion), modLatestVersion.ReleaseDate, latestFilesRelativePath, licensePath, latestSourcesURL) for modVersion in modVersions: # type: Distribution.ModVersion versionBuildPath = os.path.join(modBuildPath, str(modVersion.Version)) basePath = os.path.relpath(Paths.DownloadsBuildPath, versionBuildPath).replace("\\", "/") + "/.." # type: str installerPath = os.path.join(versionBuildPath, "installer/index.html") # type: str installerURL = modVersion.InstallerURL # type: str filesPath = os.path.join(versionBuildPath, "files/index.html") # type: str filesRelativePath = os.path.relpath(filesPath, Paths.DownloadsBuildPath) # type: str filesURL = modVersion.FilesURL # type: str sourcesPath = os.path.join(versionBuildPath, "sources/index.html") # type: str sourcesURL = modVersion.SourcesURL # type: str _WriteDownload(installerPath, modInstallerTemplate, basePath, modName, str(modVersion.Version), _typeInstaller, str(modLatestVersion.GameVersion), modLatestVersion.ReleaseDate, filesRelativePath, licensePath, installerURL) _WriteDownload(filesPath, modFilesTemplate, basePath, modName, str(modVersion.Version), _typeFiles, str(modVersion.GameVersion), modVersion.ReleaseDate, filesRelativePath, licensePath, filesURL) _WriteDownload(sourcesPath, sourcesTemplate, basePath, modName, str(modVersion.Version), _typeSources, str(modVersion.GameVersion), modVersion.ReleaseDate, filesRelativePath, licensePath, sourcesURL) for modNamespace, modVersions in Distribution.Previews.items(): # type: str, typing.List[Distribution.ModVersion] modBuildPath = os.path.join(Paths.DownloadsBuildPath, "Mods", modNamespace) # type: str licensePath = os.path.join(modBuildPath.replace(Paths.DownloadsBuildPath + os.path.sep, ""), _licenseName) # type: str licensePath = licensePath.replace("\\", "/") with open(os.path.join(Paths.DownloadsSourcesPath, "mods", modNamespace + ".json")) as modInformationFile: modInformation = decoder.JSONDecoder().decode(modInformationFile.read()) # type: dict if not modInformation["Mod"]["Age"]: modInstallerTemplate = downloadInstallerTemplate # type: str modFilesTemplate = downloadFilesTemplate # type: str else: modInstallerTemplate = downloadInstallerAgeTemplate # type: str modFilesTemplate = downloadFilesAgeTemplate # type: str if not modInformation["Sources"]["Age"]: sourcesTemplate = downloadSourcesTemplate # type: str else: sourcesTemplate = downloadSourcesAgeTemplate # type: str mod = Mods.GetMod(modNamespace) # type: Mods.Mod modName = mod.GetName() # type: typing.Optional[str] for modVersion in modVersions: # type: Distribution.ModVersion versionBuildPath = os.path.join(modBuildPath, str(modVersion.Version), modVersion.ConcealerFolderName) basePath = os.path.relpath(Paths.DownloadsBuildPath, versionBuildPath).replace("\\", "/") + "/.." # type: str installerPath = os.path.join(versionBuildPath, "installer/index.html") # type: str installerURL = modVersion.InstallerURL # type: str filesPath = os.path.join(versionBuildPath, "files/index.html") # type: str filesRelativePath = os.path.relpath(filesPath, Paths.DownloadsBuildPath) # type: str filesURL = modVersion.FilesURL # type: str sourcesPath = os.path.join(versionBuildPath, "sources/index.html") # type: str sourcesURL = modVersion.SourcesURL # type: str _WriteDownload(installerPath, modInstallerTemplate, basePath, modName, str(modVersion.Version), _typeFiles, str(modVersion.GameVersion), modVersion.ReleaseDate, filesRelativePath, licensePath, installerURL) _WriteDownload(filesPath, modFilesTemplate, basePath, modName, str(modVersion.Version), _typeFiles, str(modVersion.GameVersion), modVersion.ReleaseDate, filesRelativePath, licensePath, filesURL) _WriteDownload(sourcesPath, sourcesTemplate, basePath, modName, str(modVersion.Version), _typeSources, str(modVersion.GameVersion), modVersion.ReleaseDate, filesRelativePath, licensePath, sourcesURL)
def __init__(self, modFilePath: str): self.LoadModDictionary(modFilePath) from Automation import Mods self.Mod = Mods.GetMod(self.Namespace) # type: Mods.Mod
def PublishModRelease(modNamespace: str) -> None: print("Publishing mod '" + modNamespace + "' as a release.") if Paths.DistributionReleasesPath is None: raise Exception( "No distribution release path has been specified via automation settings." ) mod = Mods.GetMod(modNamespace) # type: Mods.Mod modDirectoryPath = Mods.GetModPath(modNamespace) # type: str version = mod.GetVersion() # type: typing.Optional[str] installerFilePath = mod.GetInstallerFilePath( ) # type: typing.Optional[str] filesFilePath = mod.GetFilesFilePath() # type: typing.Optional[str] sourcesFileName = mod.GetSourcesFileName() # type: typing.Optional[str] if version is None: raise Exception( "Couldn't get the current version number for this mod.") if installerFilePath is None: raise Exception( "Couldn't get the current installer file path for this mod.") if filesFilePath is None: raise Exception( "Couldn't get the current files file path for this mod.") if sourcesFileName is None: raise Exception( "Couldn't get the current sources file name for this mod.") distributionVersionDirectoryPath = os.path.join( Paths.DistributionReleasesPath, modNamespace.lower(), version) # type: str distributionInstallerDirectoryPath = os.path.join( distributionVersionDirectoryPath, "installer") # type: str distributionFilesDirectoryPath = os.path.join( distributionVersionDirectoryPath, "files") # type: str distributionSourcesDirectoryPath = os.path.join( distributionVersionDirectoryPath, "sources") # type: str if os.path.exists(distributionVersionDirectoryPath): dir_util.remove_tree(distributionVersionDirectoryPath, verbose=1) os.makedirs(distributionInstallerDirectoryPath) os.makedirs(distributionFilesDirectoryPath) os.makedirs(distributionSourcesDirectoryPath) file_util.copy_file(installerFilePath, distributionInstallerDirectoryPath, preserve_times=0) file_util.copy_file(filesFilePath, distributionFilesDirectoryPath, preserve_times=0) sourcesIncludedPaths = GetIncludedPaths( Paths.StrippingModsFilePath, Mods.GetModPath(modNamespace)) # type: typing.List[str] archiveFile = zipfile.ZipFile( os.path.join(distributionSourcesDirectoryPath, sourcesFileName), mode="w", compression=zipfile.ZIP_DEFLATED) # type: zipfile.ZipFile for sourcesIncludedPath in sourcesIncludedPaths: # type: str archiveFile.write(os.path.join(modDirectoryPath, sourcesIncludedPath), arcname=sourcesIncludedPath) archiveFile.close() with open( os.path.join(distributionVersionDirectoryPath, "information.json"), "w+") as versionInformationFile: versionInformationFile.write( encoder.JSONEncoder(indent="\t").encode({ "Game Version": S4.Version, "Release Date": datetime.datetime.now().date().isoformat() }))