2023-01-26 08:13:07 +08:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# This file is part of npbackup
|
|
|
|
|
|
|
|
__intname__ = "npbackup.compile-and-package-for-windows"
|
|
|
|
__author__ = "Orsiris de Jong"
|
|
|
|
__copyright__ = "Copyright (C) 2023 NetInvent"
|
|
|
|
__license__ = "GPL-3.0-only"
|
2023-01-29 01:07:32 +08:00
|
|
|
__build__ = "2023012801"
|
|
|
|
__version__ = "1.4.0"
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from command_runner import command_runner
|
2023-01-29 01:07:32 +08:00
|
|
|
|
|
|
|
# Insert parent dir as path se we get to use npbackup as package
|
|
|
|
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
|
2023-01-27 18:40:46 +08:00
|
|
|
from npbackup import __version__ as npbackup_version
|
2023-01-29 01:07:32 +08:00
|
|
|
from bin.NPBackupInstaller import __version__ as installer_version
|
2023-01-27 18:30:06 +08:00
|
|
|
from npbackup.customization import (
|
2023-01-26 08:26:08 +08:00
|
|
|
COMPANY_NAME,
|
|
|
|
TRADEMARKS,
|
|
|
|
PRODUCT_NAME,
|
|
|
|
FILE_DESCRIPTION,
|
|
|
|
COPYRIGHT,
|
|
|
|
LICENSE_FILE,
|
|
|
|
)
|
2023-01-27 18:34:05 +08:00
|
|
|
from npbackup.core.restic_source_binary import get_restic_internal_binary
|
|
|
|
from npbackup.path_helper import BASEDIR
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
del sys.path[0]
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
def check_private_build():
|
|
|
|
private = False
|
|
|
|
try:
|
2023-01-29 01:07:32 +08:00
|
|
|
import npbackup._private_secret_keys
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
print("WARNING: Building with private secret key")
|
|
|
|
private = True
|
|
|
|
except ImportError:
|
|
|
|
try:
|
2023-01-29 01:07:32 +08:00
|
|
|
import npbackup.secret_keys
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
print("Building with default secret key")
|
|
|
|
except ImportError:
|
|
|
|
print("Cannot find secret keys")
|
|
|
|
sys.exit()
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
dist_conf_file_path = get_private_conf_dist_file()
|
2023-01-26 08:26:08 +08:00
|
|
|
if "_private" in dist_conf_file_path:
|
|
|
|
print("WARNING: Building with a private conf.dist file")
|
2023-01-26 08:13:07 +08:00
|
|
|
private = True
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
return private
|
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
def get_private_conf_dist_file():
|
2023-01-26 08:26:08 +08:00
|
|
|
private_dist_conf_file = "_private_npbackup.conf.dist"
|
|
|
|
dist_conf_file = "npbackup.conf.dist"
|
2023-01-29 01:40:16 +08:00
|
|
|
dist_conf_file_path = os.path.join(BASEDIR, os.pardir, "examples", private_dist_conf_file)
|
2023-01-29 01:07:32 +08:00
|
|
|
if os.path.isfile(dist_conf_file_path):
|
|
|
|
print("Building with private dist config file")
|
|
|
|
else:
|
|
|
|
print("Building with default dist config file")
|
2023-01-29 01:40:16 +08:00
|
|
|
dist_conf_file_path = os.path.join(BASEDIR, os.pardir, "examples", dist_conf_file)
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
return dist_conf_file_path
|
|
|
|
|
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
def have_nuitka_commercial():
|
|
|
|
try:
|
|
|
|
import nuitka.plugins.commercial
|
|
|
|
print("Running with nuitka commercial")
|
|
|
|
return True
|
|
|
|
except ImportError:
|
|
|
|
print("Running with nuitka open source")
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
def compile(arch="64"):
|
2023-01-29 01:07:32 +08:00
|
|
|
if os.name == "nt":
|
|
|
|
program_executable = "npbackup.exe"
|
|
|
|
restic_executable = "restic.exe"
|
|
|
|
else:
|
|
|
|
program_executable = "npbackup"
|
|
|
|
restic_executable = "restic"
|
|
|
|
|
|
|
|
PACKAGE_DIR = 'npbackup'
|
|
|
|
|
2023-01-27 18:30:06 +08:00
|
|
|
is_private = check_private_build()
|
2023-01-29 01:07:32 +08:00
|
|
|
OUTPUT_DIR = os.path.abspath(os.path.join(BASEDIR, os.pardir, "BUILD" + "-PRIVATE" if is_private else ""))
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
if not os.path.isdir(OUTPUT_DIR):
|
|
|
|
os.makedirs(OUTPUT_DIR)
|
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
PYTHON_EXECUTABLE = sys.executable
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
# npbackup compilation
|
|
|
|
# Strip possible version suffixes '-dev'
|
2023-01-26 08:26:08 +08:00
|
|
|
_npbackup_version = npbackup_version.split("-")[0]
|
|
|
|
PRODUCT_VERSION = _npbackup_version + ".0"
|
|
|
|
FILE_VERSION = _npbackup_version + ".0"
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-27 18:42:05 +08:00
|
|
|
file_description = "{} P{}-{}{}".format(
|
|
|
|
FILE_DESCRIPTION, sys.version_info[1], arch, "priv" if is_private else ""
|
|
|
|
)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
restic_source_file = get_restic_internal_binary(arch)
|
|
|
|
if not restic_source_file:
|
2023-01-26 08:26:08 +08:00
|
|
|
print("Cannot find restic source file.")
|
2023-01-26 08:13:07 +08:00
|
|
|
return
|
2023-01-29 01:07:32 +08:00
|
|
|
restic_dest_file = os.path.join(PACKAGE_DIR, restic_executable)
|
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
output_arch_dir = os.path.join(
|
|
|
|
OUTPUT_DIR,
|
|
|
|
"win-p{}{}-{}".format(sys.version_info[0], sys.version_info[1], arch),
|
|
|
|
)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
program_executable_path = os.path.join(output_arch_dir, program_executable)
|
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
translations_dir = "translations"
|
2023-01-29 01:07:32 +08:00
|
|
|
translations_dir_source = os.path.join(BASEDIR, translations_dir)
|
|
|
|
translations_dir_dest = os.path.join(PACKAGE_DIR, translations_dir)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
license_dest_file = os.path.join(PACKAGE_DIR, os.path.basename(LICENSE_FILE))
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
icon_file = os.path.join(PACKAGE_DIR, 'npbackup_icon.ico')
|
|
|
|
|
|
|
|
# Installer specific files, no need for a npbackup package directory here
|
|
|
|
dist_conf_file_source = get_private_conf_dist_file()
|
|
|
|
dist_conf_file_dest = os.path.basename(dist_conf_file_source)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
excludes_dir = "excludes"
|
2023-01-29 01:40:16 +08:00
|
|
|
excludes_dir_source = os.path.join(BASEDIR, os.pardir, excludes_dir)
|
2023-01-29 01:07:32 +08:00
|
|
|
excludes_dir_dest = excludes_dir
|
|
|
|
r"""
|
|
|
|
C:\GIT\npbackup>C:\GIT\NPBACKUP\venv\scripts\python.exe -m nuitka --python-flag=no_docstrings --python-flag=-O --onefile --plugin-enable=tk-inter --include-data-dir="C:\GIT\npbackup\npbackup\translations"="npbackup\translations" --include-data-file="C:\GIT\npbackup\npbackup\LICENSE.md"="npbackup\LICENSE.md" --include-data-file=npbackup\RESTIC_SOURCE_FILES\restic_0.15.0_windows_amd64.exe="restic.exe" --windows-icon-from-ico=npbackup\npbackup_icon.ico --company-name="NetInvent" --product-name="NPBackup Network Backup Client" --file-version="2.1.0.0" --product-version="2.1.0.0" --copyright="NetInvent 2022-2023" --file-description="Network Backup Client P10-x64priv" --trademarks="NetInvent (C)" --output-dir="C:\GIT\npbackup\npbackup\BUILD-PRIVATE\win-p310-x64" bin\npbackup
|
|
|
|
"""
|
2023-01-26 08:26:08 +08:00
|
|
|
EXE_OPTIONS = '--company-name="{}" --product-name="{}" --file-version="{}" --product-version="{}" --copyright="{}" --file-description="{}" --trademarks="{}"'.format(
|
|
|
|
COMPANY_NAME,
|
|
|
|
PRODUCT_NAME,
|
|
|
|
FILE_VERSION,
|
|
|
|
PRODUCT_VERSION,
|
|
|
|
COPYRIGHT,
|
|
|
|
file_description,
|
|
|
|
TRADEMARKS,
|
|
|
|
)
|
2023-01-29 01:07:32 +08:00
|
|
|
NUITKA_OPTIONS = '--enable-plugin=data-hiding' if have_nuitka_commercial() else ''
|
|
|
|
|
|
|
|
CMD = '{} -m nuitka --python-flag=no_docstrings --python-flag=-O {} {} --onefile --plugin-enable=tk-inter --include-data-dir="{}"="{}" --include-data-file="{}"="{}" --include-data-file="{}"="{}" --windows-icon-from-ico="{}" --output-dir="{}" bin/npbackup'.format(
|
2023-01-26 08:26:08 +08:00
|
|
|
PYTHON_EXECUTABLE,
|
2023-01-29 01:07:32 +08:00
|
|
|
NUITKA_OPTIONS,
|
|
|
|
EXE_OPTIONS,
|
|
|
|
translations_dir_source,
|
|
|
|
translations_dir_dest,
|
2023-01-26 08:26:08 +08:00
|
|
|
LICENSE_FILE,
|
2023-01-29 01:07:32 +08:00
|
|
|
license_dest_file,
|
2023-01-26 08:26:08 +08:00
|
|
|
restic_source_file,
|
2023-01-29 01:07:32 +08:00
|
|
|
restic_dest_file,
|
|
|
|
icon_file,
|
2023-01-26 08:26:08 +08:00
|
|
|
output_arch_dir,
|
|
|
|
)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
print(CMD)
|
|
|
|
errors = False
|
|
|
|
exit_code, output = command_runner(CMD, timeout=0, live_output=True)
|
|
|
|
if exit_code != 0:
|
|
|
|
errors = True
|
|
|
|
|
|
|
|
# installer compilation
|
2023-01-26 08:26:08 +08:00
|
|
|
_installer_version = installer_version.split("-")[0]
|
|
|
|
PRODUCT_VERSION = _installer_version + ".0"
|
|
|
|
FILE_VERSION = _installer_version + ".0"
|
|
|
|
EXE_OPTIONS = '--company-name="{}" --product-name="{}" --file-version="{}" --product-version="{}" --copyright="{}" --file-description="{}" --trademarks="{}"'.format(
|
|
|
|
COMPANY_NAME,
|
|
|
|
PRODUCT_NAME,
|
|
|
|
FILE_VERSION,
|
|
|
|
PRODUCT_VERSION,
|
|
|
|
COPYRIGHT,
|
|
|
|
file_description,
|
|
|
|
TRADEMARKS,
|
|
|
|
)
|
2023-01-29 01:07:32 +08:00
|
|
|
CMD = '{} -m nuitka --python-flag=no_docstrings --python-flag=-O {} {} --onefile --plugin-enable=tk-inter --include-data-file="{}"="{}" --include-data-file="{}"="{}" --include-data-dir="{}"="{}" --windows-icon-from-ico="{}" --windows-uac-admin --output-dir="{}" bin/NPBackupInstaller.py'.format(
|
2023-01-26 08:26:08 +08:00
|
|
|
PYTHON_EXECUTABLE,
|
2023-01-29 01:07:32 +08:00
|
|
|
NUITKA_OPTIONS,
|
|
|
|
EXE_OPTIONS,
|
2023-01-26 08:26:08 +08:00
|
|
|
program_executable_path,
|
|
|
|
program_executable,
|
2023-01-29 01:07:32 +08:00
|
|
|
dist_conf_file_source,
|
|
|
|
dist_conf_file_dest,
|
|
|
|
excludes_dir_source,
|
|
|
|
excludes_dir_dest,
|
|
|
|
icon_file,
|
2023-01-26 08:26:08 +08:00
|
|
|
output_arch_dir,
|
|
|
|
)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
|
|
|
print(CMD)
|
|
|
|
exit_code, output = command_runner(CMD, timeout=0, live_output=True)
|
|
|
|
if exit_code != 0:
|
|
|
|
errors = True
|
|
|
|
|
2023-01-29 01:07:32 +08:00
|
|
|
print("COMPILE ERRORS", errors)
|
2023-01-26 08:13:07 +08:00
|
|
|
|
2023-01-26 08:26:08 +08:00
|
|
|
|
2023-01-26 08:13:07 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# I know, I could improve UX here
|
|
|
|
compile(arch=sys.argv[1])
|
2023-01-26 08:26:08 +08:00
|
|
|
check_private_build()
|