Add flag to tailor minimal zip package to different OSes

This commit is contained in:
Veronica K. B. Olsen
2021-02-05 16:52:23 +01:00
parent e4e8b939e2
commit f8ef3e6754
3 changed files with 55 additions and 42 deletions
+6 -5
View File
@@ -1,11 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
novelWriter Terminal Start Script novelWriter Start Script
=================================== ==========================
The main start script for the terminal
""" """
import os
import sys import sys
try: try:
@@ -13,9 +12,11 @@ try:
import PyQt5.QtGui # noqa: F401 import PyQt5.QtGui # noqa: F401
import PyQt5.QtCore # noqa: F401 import PyQt5.QtCore # noqa: F401
except Exception: except Exception:
print("ERROR: Failed to load dependency python3-pyqt5") print("ERROR: Failed to load dependency PyQt5")
sys.exit(1) sys.exit(1)
os.curdir = os.path.abspath(os.path.dirname(__file__))
if __name__ == "__main__": if __name__ == "__main__":
import nw import nw
nw.main(sys.argv[1:]) nw.main(sys.argv[1:])
-15
View File
@@ -1,15 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
novelWriter Windows Start Script
==================================
The main start script for Windows GUI
"""
import os
os.curdir = os.path.abspath(os.path.dirname(__file__))
if __name__ == "__main__":
import nw
nw.main()
+49 -22
View File
@@ -234,7 +234,7 @@ def buildSampleZip():
# Make Minimal Package (minimal-zip) # Make Minimal Package (minimal-zip)
## ##
def makeMinimalPackage(): def makeMinimalPackage(targetOS):
"""Pack the core source file in a single zip file. """Pack the core source file in a single zip file.
""" """
from nw import __version__ from nw import __version__
@@ -256,41 +256,53 @@ def makeMinimalPackage():
if not os.path.isdir("dist"): if not os.path.isdir("dist"):
os.mkdir("dist") os.mkdir("dist")
outFile = os.path.join("dist", "novelWriter-%s-minimal.zip" % __version__) if targetOS == OS_LINUX:
targName = "-linux"
elif targetOS == OS_DARWIN:
targName = "-darwin"
elif targetOS == OS_WIN:
targName = "-win"
else:
targName = ""
outFile = os.path.join("dist", f"novelWriter-{__version__}-minimal{targName}.zip")
if os.path.isfile(outFile): if os.path.isfile(outFile):
os.unlink(outFile) os.unlink(outFile)
rootFiles = [ rootFiles = ["LICENSE.md", "README.md", "CHANGELOG.md", "requirements.txt", "setup.py"]
"LICENSE.md",
"README.md",
"CHANGELOG.md",
"novelWriter.pyw",
"requirements.txt",
"setup.py",
"setup_windows.bat",
]
with ZipFile(outFile, "w", compression=ZIP_DEFLATED, compresslevel=9) as zipObj: with ZipFile(outFile, "w", compression=ZIP_DEFLATED, compresslevel=9) as zipObj:
for nRoot, _, nFiles in os.walk("setup"):
print("Compressing: %s [%d files]" % (nRoot, len(nFiles))) if targetOS != OS_WIN:
for aFile in nFiles: for nRoot, _, nFiles in os.walk("setup"):
zipObj.write(os.path.join(nRoot, aFile)) print("Adding Folder: %s [%d files]" % (nRoot, len(nFiles)))
for aFile in nFiles:
zipObj.write(os.path.join(nRoot, aFile))
for nRoot, _, nFiles in os.walk("nw"): for nRoot, _, nFiles in os.walk("nw"):
if nRoot.endswith("__pycache__"): if nRoot.endswith("__pycache__"):
print("Skipping: %s" % nRoot) print("Skipping Folder: %s" % nRoot)
continue continue
print("Compressing: %s [%d files]" % (nRoot, len(nFiles))) print("Adding Folder: %s [%d files]" % (nRoot, len(nFiles)))
for aFile in nFiles: for aFile in nFiles:
if aFile.endswith(".pyc"): if aFile.endswith(".pyc"):
print("Skipping: %s" % aFile) print("Skipping File: %s" % aFile)
continue continue
zipObj.write(os.path.join(nRoot, aFile)) zipObj.write(os.path.join(nRoot, aFile))
if targetOS == OS_WIN:
zipObj.write("novelWriter.py", "novelWriter.pyw")
print("Adding File: novelWriter.pyw")
zipObj.write("setup_windows.bat")
print("Adding File: setup_windows.bat")
else:
zipObj.write("novelWriter.py")
print("Adding File: novelWriter.py")
for aFile in rootFiles: for aFile in rootFiles:
assert os.path.isfile(aFile) assert os.path.isfile(aFile)
print("Compressing: %s" % aFile) print("Adding File: %s" % aFile)
zipObj.write(aFile) zipObj.write(aFile)
print("") print("")
@@ -913,7 +925,6 @@ def innoSetup(setupType):
if __name__ == "__main__": if __name__ == "__main__":
"""Parse command line options and run the commands. """Parse command line options and run the commands.
""" """
# Detect OS # Detect OS
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
hostOS = OS_LINUX hostOS = OS_LINUX
@@ -926,6 +937,19 @@ if __name__ == "__main__":
else: else:
hostOS = OS_NONE hostOS = OS_NONE
# Set Target OS
if "--linux" in sys.argv:
sys.argv.remove("--linux")
targetOS = OS_LINUX
elif "--darwin" in sys.argv:
sys.argv.remove("--darwin")
targetOS = OS_DARWIN
elif "--win" in sys.argv:
sys.argv.remove("--win")
targetOS = OS_WIN
else:
targetOS = hostOS
helpMsg = ( helpMsg = (
"\n" "\n"
"novelWriter Setup Tool\n" "novelWriter Setup Tool\n"
@@ -934,6 +958,9 @@ if __name__ == "__main__":
"This tool provides setup and build commands for installing or distibuting novelWriter\n" "This tool provides setup and build commands for installing or distibuting novelWriter\n"
"as a package on Linux, Mac and Windows. The available options are as follows:\n" "as a package on Linux, Mac and Windows. The available options are as follows:\n"
"\n" "\n"
"Some of the commands can be targeted towards a different OS than the host OS. To target\n"
"the command, add one of '--linux', '--darwin' or '--win'.\n"
"\n"
"General:\n" "General:\n"
"\n" "\n"
" help Print the help message.\n" " help Print the help message.\n"
@@ -950,7 +977,7 @@ if __name__ == "__main__":
"Python Packaging:\n" "Python Packaging:\n"
"\n" "\n"
" minimal-zip Creates a minimal zip file of the core application without all the\n" " minimal-zip Creates a minimal zip file of the core application without all the\n"
" other source files.\n" " other source files. Accepts a target OS flag.\n"
" pack-pyz Creates a pyz package in a folder with all dependencies using the\n" " pack-pyz Creates a pyz package in a folder with all dependencies using the\n"
" zipapp tool. On Windows, python embeddable is added to the folder.\n" " zipapp tool. On Windows, python embeddable is added to the folder.\n"
" freeze Freeze the package and produces a folder with all dependencies using\n" " freeze Freeze the package and produces a folder with all dependencies using\n"
@@ -1015,7 +1042,7 @@ if __name__ == "__main__":
if "minimal-zip" in sys.argv: if "minimal-zip" in sys.argv:
sys.argv.remove("minimal-zip") sys.argv.remove("minimal-zip")
makeMinimalPackage() makeMinimalPackage(targetOS)
if "pack-pyz" in sys.argv: if "pack-pyz" in sys.argv:
sys.argv.remove("pack-pyz") sys.argv.remove("pack-pyz")