Move common functions
This commit is contained in:
+7
-74
@@ -6,6 +6,7 @@ novelWriter – Packaging Utils
|
|||||||
File History:
|
File History:
|
||||||
Created: 2019-05-16 [0.5.1]
|
Created: 2019-05-16 [0.5.1]
|
||||||
Renamed: 2023-07-26 [2.1b1]
|
Renamed: 2023-07-26 [2.1b1]
|
||||||
|
Split: 2025-01-16 [2.7b1]
|
||||||
|
|
||||||
This file is a part of novelWriter
|
This file is a part of novelWriter
|
||||||
Copyright (C) 2019 Veronica Berglyd Olsen and novelWriter contributors
|
Copyright (C) 2019 Veronica Berglyd Olsen and novelWriter contributors
|
||||||
@@ -39,7 +40,10 @@ import utils.binary_dist
|
|||||||
import utils.icon_themes
|
import utils.icon_themes
|
||||||
import utils.windows_build
|
import utils.windows_build
|
||||||
|
|
||||||
from utils.common import ROOT_DIR, SETUP_DIR, copySourceCode, extractVersion, readFile, writeFile
|
from utils.common import (
|
||||||
|
ROOT_DIR, SETUP_DIR, checkAssetsExist, copySourceCode, extractVersion,
|
||||||
|
makeCheckSum, readFile, stripVersion, toUpload, writeFile
|
||||||
|
)
|
||||||
|
|
||||||
SIGN_KEY = "D6A9F6B8F227CF7C6F6D1EE84DBBE4B734B0BD08"
|
SIGN_KEY = "D6A9F6B8F227CF7C6F6D1EE84DBBE4B734B0BD08"
|
||||||
|
|
||||||
@@ -48,79 +52,6 @@ OS_DARWIN = sys.platform.startswith("darwin")
|
|||||||
OS_WIN = sys.platform.startswith("win32")
|
OS_WIN = sys.platform.startswith("win32")
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================================== #
|
|
||||||
# Utilities
|
|
||||||
# =============================================================================================== #
|
|
||||||
|
|
||||||
def stripVersion(version: str) -> str:
|
|
||||||
"""Strip the pre-release part from a version number."""
|
|
||||||
if "a" in version:
|
|
||||||
return version.partition("a")[0]
|
|
||||||
elif "b" in version:
|
|
||||||
return version.partition("b")[0]
|
|
||||||
elif "rc" in version:
|
|
||||||
return version.partition("rc")[0]
|
|
||||||
else:
|
|
||||||
return version
|
|
||||||
|
|
||||||
|
|
||||||
def toUpload(srcPath: str | Path, dstName: str | None = None) -> None:
|
|
||||||
"""Copy a file produced by one of the build functions to the upload
|
|
||||||
directory. The file can optionally be given a new name.
|
|
||||||
"""
|
|
||||||
uplDir = Path("dist_upload")
|
|
||||||
uplDir.mkdir(exist_ok=True)
|
|
||||||
srcPath = Path(srcPath)
|
|
||||||
shutil.copyfile(srcPath, uplDir / (dstName or srcPath.name))
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def makeCheckSum(sumFile: str, cwd: Path | None = None) -> str:
|
|
||||||
"""Create a SHA256 checksum file."""
|
|
||||||
try:
|
|
||||||
if cwd is None:
|
|
||||||
shaFile = f"{sumFile}.sha256"
|
|
||||||
else:
|
|
||||||
shaFile = cwd / f"{sumFile}.sha256"
|
|
||||||
with open(shaFile, mode="w") as fOut:
|
|
||||||
subprocess.call(["shasum", "-a", "256", sumFile], stdout=fOut, cwd=cwd)
|
|
||||||
print(f"SHA256 Sum: {shaFile}")
|
|
||||||
except Exception as exc:
|
|
||||||
print("Could not generate sha256 file")
|
|
||||||
print(str(exc))
|
|
||||||
return ""
|
|
||||||
|
|
||||||
return str(shaFile)
|
|
||||||
|
|
||||||
|
|
||||||
def checkAssetsExist() -> bool:
|
|
||||||
"""Check that the necessary assets exist ahead of a build."""
|
|
||||||
hasSample = False
|
|
||||||
hasManual = False
|
|
||||||
hasQmData = False
|
|
||||||
|
|
||||||
sampleZip = ROOT_DIR / "novelwriter" / "assets" / "sample.zip"
|
|
||||||
if sampleZip.is_file():
|
|
||||||
print(f"Found: {sampleZip}")
|
|
||||||
hasSample = True
|
|
||||||
|
|
||||||
pdfManual = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf"
|
|
||||||
if pdfManual.is_file():
|
|
||||||
print(f"Found: {pdfManual}")
|
|
||||||
hasManual = True
|
|
||||||
|
|
||||||
i18nAssets = ROOT_DIR / "novelwriter" / "assets" / "i18n"
|
|
||||||
if len(list(i18nAssets.glob("*.qm"))) > 0:
|
|
||||||
print(f"Found: {i18nAssets}/*.qm")
|
|
||||||
hasQmData = True
|
|
||||||
|
|
||||||
return hasSample and hasManual and hasQmData
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================================== #
|
|
||||||
# General
|
|
||||||
# =============================================================================================== #
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Print Version
|
# Print Version
|
||||||
##
|
##
|
||||||
@@ -176,7 +107,9 @@ def cleanBuildDirs(args: argparse.Namespace) -> None:
|
|||||||
|
|
||||||
folders = [
|
folders = [
|
||||||
ROOT_DIR / "build",
|
ROOT_DIR / "build",
|
||||||
|
ROOT_DIR / "build_bin",
|
||||||
ROOT_DIR / "dist",
|
ROOT_DIR / "dist",
|
||||||
|
ROOT_DIR / "dist_bin",
|
||||||
ROOT_DIR / "dist_deb",
|
ROOT_DIR / "dist_deb",
|
||||||
ROOT_DIR / "dist_minimal",
|
ROOT_DIR / "dist_minimal",
|
||||||
ROOT_DIR / "dist_appimage",
|
ROOT_DIR / "dist_appimage",
|
||||||
|
|||||||
+67
-1
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ def extractVersion(beQuiet: bool = False) -> tuple[str, str, str]:
|
|||||||
numVers = "0"
|
numVers = "0"
|
||||||
hexVers = "0x0"
|
hexVers = "0x0"
|
||||||
relDate = "Unknown"
|
relDate = "Unknown"
|
||||||
initFile = Path("novelwriter") / "__init__.py"
|
initFile = ROOT_DIR / "novelwriter" / "__init__.py"
|
||||||
try:
|
try:
|
||||||
for aLine in initFile.read_text(encoding="utf-8").splitlines():
|
for aLine in initFile.read_text(encoding="utf-8").splitlines():
|
||||||
if aLine.startswith("__version__"):
|
if aLine.startswith("__version__"):
|
||||||
@@ -58,6 +59,18 @@ def extractVersion(beQuiet: bool = False) -> tuple[str, str, str]:
|
|||||||
return numVers, hexVers, relDate
|
return numVers, hexVers, relDate
|
||||||
|
|
||||||
|
|
||||||
|
def stripVersion(version: str) -> str:
|
||||||
|
"""Strip the pre-release part from a version number."""
|
||||||
|
if "a" in version:
|
||||||
|
return version.partition("a")[0]
|
||||||
|
elif "b" in version:
|
||||||
|
return version.partition("b")[0]
|
||||||
|
elif "rc" in version:
|
||||||
|
return version.partition("rc")[0]
|
||||||
|
else:
|
||||||
|
return version
|
||||||
|
|
||||||
|
|
||||||
def copySourceCode(dst: Path) -> None:
|
def copySourceCode(dst: Path) -> None:
|
||||||
"""Copy the novelwriter source tree to path."""
|
"""Copy the novelwriter source tree to path."""
|
||||||
src = ROOT_DIR / "novelwriter"
|
src = ROOT_DIR / "novelwriter"
|
||||||
@@ -77,6 +90,59 @@ def copySourceCode(dst: Path) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def toUpload(srcPath: str | Path, dstName: str | None = None) -> None:
|
||||||
|
"""Copy a file produced by one of the build functions to the upload
|
||||||
|
directory. The file can optionally be given a new name.
|
||||||
|
"""
|
||||||
|
uplDir = Path("dist_upload")
|
||||||
|
uplDir.mkdir(exist_ok=True)
|
||||||
|
srcPath = Path(srcPath)
|
||||||
|
shutil.copyfile(srcPath, uplDir / (dstName or srcPath.name))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def makeCheckSum(sumFile: str, cwd: Path | None = None) -> str:
|
||||||
|
"""Create a SHA256 checksum file."""
|
||||||
|
try:
|
||||||
|
if cwd is None:
|
||||||
|
shaFile = f"{sumFile}.sha256"
|
||||||
|
else:
|
||||||
|
shaFile = cwd / f"{sumFile}.sha256"
|
||||||
|
with open(shaFile, mode="w") as fOut:
|
||||||
|
subprocess.call(["shasum", "-a", "256", sumFile], stdout=fOut, cwd=cwd)
|
||||||
|
print(f"SHA256 Sum: {shaFile}")
|
||||||
|
except Exception as exc:
|
||||||
|
print("Could not generate sha256 file")
|
||||||
|
print(str(exc))
|
||||||
|
return ""
|
||||||
|
|
||||||
|
return str(shaFile)
|
||||||
|
|
||||||
|
|
||||||
|
def checkAssetsExist() -> bool:
|
||||||
|
"""Check that the necessary assets exist ahead of a build."""
|
||||||
|
hasSample = False
|
||||||
|
hasManual = False
|
||||||
|
hasQmData = False
|
||||||
|
|
||||||
|
sampleZip = ROOT_DIR / "novelwriter" / "assets" / "sample.zip"
|
||||||
|
if sampleZip.is_file():
|
||||||
|
print(f"Found: {sampleZip}")
|
||||||
|
hasSample = True
|
||||||
|
|
||||||
|
pdfManual = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf"
|
||||||
|
if pdfManual.is_file():
|
||||||
|
print(f"Found: {pdfManual}")
|
||||||
|
hasManual = True
|
||||||
|
|
||||||
|
i18nAssets = ROOT_DIR / "novelwriter" / "assets" / "i18n"
|
||||||
|
if len(list(i18nAssets.glob("*.qm"))) > 0:
|
||||||
|
print(f"Found: {i18nAssets}/*.qm")
|
||||||
|
hasQmData = True
|
||||||
|
|
||||||
|
return hasSample and hasManual and hasQmData
|
||||||
|
|
||||||
|
|
||||||
def readFile(file: Path) -> str:
|
def readFile(file: Path) -> str:
|
||||||
"""Read an entire file and return as a string."""
|
"""Read an entire file and return as a string."""
|
||||||
return file.read_text(encoding="utf-8")
|
return file.read_text(encoding="utf-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user