2017-03-12 01:41:47 +00:00
|
|
|
# Copyright 2017 Virgil Dupras
|
2014-10-05 20:31:16 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-05 20:31:16 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2017-08-28 23:27:17 +00:00
|
|
|
import sys
|
2009-12-30 16:34:41 +00:00
|
|
|
import os
|
|
|
|
import os.path as op
|
2010-04-07 10:56:43 +00:00
|
|
|
import compileall
|
2010-02-09 14:52:09 +00:00
|
|
|
import shutil
|
2011-01-11 15:21:36 +00:00
|
|
|
import json
|
2012-04-07 15:21:38 +00:00
|
|
|
from argparse import ArgumentParser
|
2013-03-24 16:02:41 +00:00
|
|
|
import platform
|
2020-06-24 23:39:06 +00:00
|
|
|
import distro
|
2017-08-28 23:27:17 +00:00
|
|
|
import re
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2014-10-13 19:08:59 +00:00
|
|
|
from hscommon.build import (
|
2020-01-01 02:16:27 +00:00
|
|
|
print_and_do,
|
|
|
|
copy_packages,
|
|
|
|
build_debian_changelog,
|
|
|
|
get_module_version,
|
|
|
|
filereplace,
|
|
|
|
copy,
|
|
|
|
setup_package_argparser,
|
|
|
|
copy_all,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2010-02-09 14:42:48 +00:00
|
|
|
|
2021-08-25 05:46:33 +00:00
|
|
|
ENTRY_SCRIPT = "run.py"
|
|
|
|
LOCALE_DIR = "build/locale"
|
|
|
|
HELP_DIR = "build/help"
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2012-04-07 15:21:38 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = ArgumentParser()
|
2012-06-20 17:09:42 +00:00
|
|
|
setup_package_argparser(parser)
|
|
|
|
return parser.parse_args()
|
2012-04-07 15:21:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2021-08-25 05:46:33 +00:00
|
|
|
def check_loc_doc():
|
|
|
|
if not op.exists(LOCALE_DIR):
|
|
|
|
print('Locale files are missing. Have you run "build.py --loc"?')
|
|
|
|
# include help files if they are built otherwise exit as they should be included?
|
|
|
|
if not op.exists(HELP_DIR):
|
|
|
|
print('Help files are missing. Have you run "build.py --doc"?')
|
|
|
|
return op.exists(LOCALE_DIR) and op.exists(HELP_DIR)
|
|
|
|
|
|
|
|
|
2013-09-22 13:38:52 +00:00
|
|
|
def copy_files_to_package(destpath, packages, with_so):
|
|
|
|
# when with_so is true, we keep .so files in the package, and otherwise, we don't. We need this
|
|
|
|
# flag because when building debian src pkg, we *don't* want .so files (they're compiled later)
|
|
|
|
# and when we're packaging under Arch, we're packaging a binary package, so we want them.
|
2013-04-14 21:21:08 +00:00
|
|
|
if op.exists(destpath):
|
|
|
|
shutil.rmtree(destpath)
|
|
|
|
os.makedirs(destpath)
|
2021-08-25 05:46:33 +00:00
|
|
|
shutil.copy(ENTRY_SCRIPT, op.join(destpath, ENTRY_SCRIPT))
|
2020-01-01 02:16:27 +00:00
|
|
|
extra_ignores = ["*.so"] if not with_so else None
|
2013-09-22 13:38:52 +00:00
|
|
|
copy_packages(packages, destpath, extra_ignores=extra_ignores)
|
2020-07-24 01:33:13 +00:00
|
|
|
# include locale files if they are built otherwise exit as it will break
|
|
|
|
# the localization
|
2021-08-25 05:46:33 +00:00
|
|
|
if not check_loc_doc():
|
|
|
|
print("Exiting...")
|
2020-07-24 01:33:13 +00:00
|
|
|
return
|
|
|
|
shutil.copytree(op.join("build", "help"), op.join(destpath, "help"))
|
|
|
|
shutil.copytree(op.join("build", "locale"), op.join(destpath, "locale"))
|
2013-04-14 21:21:08 +00:00
|
|
|
compileall.compile_dir(destpath)
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2016-06-01 00:21:07 +00:00
|
|
|
def package_debian_distribution(distribution):
|
2020-01-01 02:16:27 +00:00
|
|
|
app_version = get_module_version("core")
|
|
|
|
version = "{}~{}".format(app_version, distribution)
|
|
|
|
destpath = op.join("build", "dupeguru-{}".format(version))
|
|
|
|
srcpath = op.join(destpath, "src")
|
2022-05-09 00:40:37 +00:00
|
|
|
packages = ["hscommon", "core", "qt", "send2trash"]
|
2013-09-22 13:38:52 +00:00
|
|
|
copy_files_to_package(srcpath, packages, with_so=False)
|
2020-01-01 02:16:27 +00:00
|
|
|
os.mkdir(op.join(destpath, "modules"))
|
|
|
|
copy_all(op.join("core", "pe", "modules", "*.*"), op.join(destpath, "modules"))
|
|
|
|
copy(
|
|
|
|
op.join("qt", "pe", "modules", "block.c"),
|
|
|
|
op.join(destpath, "modules", "block_qt.c"),
|
|
|
|
)
|
|
|
|
copy(
|
|
|
|
op.join("pkg", "debian", "build_pe_modules.py"),
|
|
|
|
op.join(destpath, "build_pe_modules.py"),
|
|
|
|
)
|
|
|
|
debdest = op.join(destpath, "debian")
|
|
|
|
debskel = op.join("pkg", "debian")
|
2012-06-16 14:35:23 +00:00
|
|
|
os.makedirs(debdest)
|
2020-01-01 02:16:27 +00:00
|
|
|
debopts = json.load(open(op.join(debskel, "dupeguru.json")))
|
|
|
|
for fn in ["compat", "copyright", "dirs", "rules", "source"]:
|
2014-04-19 21:48:48 +00:00
|
|
|
copy(op.join(debskel, fn), op.join(debdest, fn))
|
2020-01-01 02:16:27 +00:00
|
|
|
filereplace(op.join(debskel, "control"), op.join(debdest, "control"), **debopts)
|
|
|
|
filereplace(op.join(debskel, "Makefile"), op.join(destpath, "Makefile"), **debopts)
|
2021-08-15 09:10:18 +00:00
|
|
|
filereplace(op.join(debskel, "dupeguru.desktop"), op.join(debdest, "dupeguru.desktop"), **debopts)
|
2020-01-01 02:16:27 +00:00
|
|
|
changelogpath = op.join("help", "changelog")
|
|
|
|
changelog_dest = op.join(debdest, "changelog")
|
|
|
|
project_name = debopts["pkgname"]
|
|
|
|
from_version = "2.9.2"
|
2014-10-13 19:08:59 +00:00
|
|
|
build_debian_changelog(
|
2020-01-01 02:16:27 +00:00
|
|
|
changelogpath,
|
|
|
|
changelog_dest,
|
|
|
|
project_name,
|
|
|
|
from_version=from_version,
|
|
|
|
distribution=distribution,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2020-01-01 02:16:27 +00:00
|
|
|
shutil.copy(op.join("images", "dgse_logo_128.png"), srcpath)
|
2010-04-07 10:56:43 +00:00
|
|
|
os.chdir(destpath)
|
2020-05-20 22:15:49 +00:00
|
|
|
cmd = "dpkg-buildpackage -F -us -uc"
|
2012-07-11 20:21:40 +00:00
|
|
|
os.system(cmd)
|
2020-01-01 02:16:27 +00:00
|
|
|
os.chdir("../..")
|
|
|
|
|
2012-10-26 14:23:50 +00:00
|
|
|
|
2016-06-01 00:21:07 +00:00
|
|
|
def package_debian():
|
2019-08-29 19:01:04 +00:00
|
|
|
print("Packaging for Debian/Ubuntu")
|
2020-01-01 02:16:27 +00:00
|
|
|
for distribution in ["unstable"]:
|
2016-06-01 00:21:07 +00:00
|
|
|
package_debian_distribution(distribution)
|
2010-04-07 10:56:43 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2016-06-01 00:21:07 +00:00
|
|
|
def package_arch():
|
2013-04-14 21:21:08 +00:00
|
|
|
# For now, package_arch() will only copy the source files into build/. It copies less packages
|
|
|
|
# than package_debian because there are more python packages available in Arch (so we don't
|
|
|
|
# need to include them).
|
|
|
|
print("Packaging for Arch")
|
2020-01-01 02:16:27 +00:00
|
|
|
srcpath = op.join("build", "dupeguru-arch")
|
2022-05-09 00:40:37 +00:00
|
|
|
packages = ["hscommon", "core", "qt", "send2trash"]
|
2013-09-22 13:38:52 +00:00
|
|
|
copy_files_to_package(srcpath, packages, with_so=True)
|
2020-01-01 02:16:27 +00:00
|
|
|
shutil.copy(op.join("images", "dgse_logo_128.png"), srcpath)
|
|
|
|
debopts = json.load(open(op.join("pkg", "arch", "dupeguru.json")))
|
2021-08-15 09:10:18 +00:00
|
|
|
filereplace(op.join("pkg", "arch", "dupeguru.desktop"), op.join(srcpath, "dupeguru.desktop"), **debopts)
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2013-04-14 21:21:08 +00:00
|
|
|
|
2019-08-29 19:01:04 +00:00
|
|
|
def package_source_txz():
|
2013-12-21 17:13:26 +00:00
|
|
|
print("Creating git archive")
|
2020-01-01 02:16:27 +00:00
|
|
|
app_version = get_module_version("core")
|
|
|
|
name = "dupeguru-src-{}.tar".format(app_version)
|
2016-08-14 00:30:24 +00:00
|
|
|
base_path = os.getcwd()
|
2020-01-01 02:16:27 +00:00
|
|
|
build_path = op.join(base_path, "build")
|
2016-08-14 00:30:24 +00:00
|
|
|
dest = op.join(build_path, name)
|
2020-01-01 02:16:27 +00:00
|
|
|
print_and_do("git archive -o {} HEAD".format(dest))
|
|
|
|
print_and_do("xz {}".format(dest))
|
|
|
|
|
2013-05-05 14:47:43 +00:00
|
|
|
|
2017-08-28 23:27:17 +00:00
|
|
|
def package_windows():
|
2020-01-01 02:16:27 +00:00
|
|
|
app_version = get_module_version("core")
|
2017-08-28 23:27:17 +00:00
|
|
|
arch = platform.architecture()[0]
|
2019-03-25 02:35:34 +00:00
|
|
|
# Information to pass to pyinstaller and NSIS
|
2020-01-01 02:16:27 +00:00
|
|
|
match = re.search("[0-9]+.[0-9]+.[0-9]+", app_version)
|
|
|
|
version_array = match.group(0).split(".")
|
|
|
|
match = re.search("[0-9]+", arch)
|
2019-03-25 02:35:34 +00:00
|
|
|
bits = match.group(0)
|
2020-01-01 02:28:35 +00:00
|
|
|
if bits == "64":
|
|
|
|
arch = "x64"
|
|
|
|
else:
|
|
|
|
arch = "x86"
|
2017-08-28 23:27:17 +00:00
|
|
|
# include locale files if they are built otherwise exit as it will break
|
|
|
|
# the localization
|
2021-08-25 05:46:33 +00:00
|
|
|
if not check_loc_doc():
|
|
|
|
print("Exiting...")
|
2017-08-28 23:27:17 +00:00
|
|
|
return
|
2019-03-25 02:35:34 +00:00
|
|
|
# create version information file from template
|
|
|
|
try:
|
|
|
|
version_template = open("win_version_info.temp", "r")
|
|
|
|
version_info = version_template.read()
|
2020-01-01 02:16:27 +00:00
|
|
|
version_template.close()
|
2019-03-25 02:35:34 +00:00
|
|
|
version_info_file = open("win_version_info.txt", "w")
|
2021-08-15 09:10:18 +00:00
|
|
|
version_info_file.write(version_info.format(version_array[0], version_array[1], version_array[2], bits))
|
2019-03-25 02:35:34 +00:00
|
|
|
version_info_file.close()
|
|
|
|
except Exception:
|
|
|
|
print("Error creating version info file, exiting...")
|
|
|
|
return
|
2020-01-01 02:28:35 +00:00
|
|
|
# run pyinstaller from here:
|
|
|
|
import PyInstaller.__main__
|
|
|
|
|
|
|
|
# UCRT dlls are included if the system has the windows kit installed
|
|
|
|
PyInstaller.__main__.run(
|
|
|
|
[
|
|
|
|
"--name=dupeguru-win{0}".format(bits),
|
|
|
|
"--windowed",
|
|
|
|
"--noconfirm",
|
|
|
|
"--icon=images/dgse_logo.ico",
|
2021-08-25 05:46:33 +00:00
|
|
|
"--add-data={0};locale".format(LOCALE_DIR),
|
|
|
|
"--add-data={0};help".format(HELP_DIR),
|
2020-01-01 02:28:35 +00:00
|
|
|
"--version-file=win_version_info.txt",
|
2021-08-15 09:10:18 +00:00
|
|
|
"--paths=C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\ucrt\\DLLs\\{0}".format(arch),
|
2021-08-25 05:46:33 +00:00
|
|
|
ENTRY_SCRIPT,
|
2020-01-01 02:28:35 +00:00
|
|
|
]
|
2020-01-01 02:16:27 +00:00
|
|
|
)
|
2019-03-25 02:35:34 +00:00
|
|
|
# remove version info file
|
2020-01-01 02:16:27 +00:00
|
|
|
os.remove("win_version_info.txt")
|
2017-08-28 23:27:17 +00:00
|
|
|
# Call NSIS (TODO update to not use hardcoded path)
|
2020-01-01 02:16:27 +00:00
|
|
|
cmd = (
|
|
|
|
'"C:\\Program Files (x86)\\NSIS\\Bin\\makensis.exe" '
|
|
|
|
"/DVERSIONMAJOR={0} /DVERSIONMINOR={1} /DVERSIONPATCH={2} /DBITS={3} setup.nsi"
|
|
|
|
)
|
2017-08-28 23:27:17 +00:00
|
|
|
print_and_do(cmd.format(version_array[0], version_array[1], version_array[2], bits))
|
|
|
|
|
2020-12-31 02:04:14 +00:00
|
|
|
|
2020-12-30 22:44:27 +00:00
|
|
|
def package_macos():
|
|
|
|
# include locale files if they are built otherwise exit as it will break
|
|
|
|
# the localization
|
2021-08-25 05:46:33 +00:00
|
|
|
if not check_loc_doc():
|
|
|
|
print("Exiting")
|
2020-12-30 22:44:27 +00:00
|
|
|
return
|
|
|
|
# run pyinstaller from here:
|
|
|
|
import PyInstaller.__main__
|
|
|
|
|
|
|
|
PyInstaller.__main__.run(
|
|
|
|
[
|
|
|
|
"--name=dupeguru",
|
|
|
|
"--windowed",
|
|
|
|
"--noconfirm",
|
|
|
|
"--icon=images/dupeguru.icns",
|
|
|
|
"--osx-bundle-identifier=com.hardcoded-software.dupeguru",
|
2021-08-25 05:46:33 +00:00
|
|
|
"--add-data={0}:locale".format(LOCALE_DIR),
|
|
|
|
"--add-data={0}:help".format(HELP_DIR),
|
2022-02-10 04:33:41 +00:00
|
|
|
"{0}".format(ENTRY_SCRIPT),
|
2020-12-30 22:44:27 +00:00
|
|
|
]
|
2020-12-31 02:04:14 +00:00
|
|
|
)
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-12-30 16:34:41 +00:00
|
|
|
def main():
|
2012-04-07 15:21:38 +00:00
|
|
|
args = parse_args()
|
2013-05-05 14:47:43 +00:00
|
|
|
if args.src_pkg:
|
2016-06-01 00:21:07 +00:00
|
|
|
print("Creating source package for dupeGuru")
|
2019-08-29 19:01:04 +00:00
|
|
|
package_source_txz()
|
2013-05-05 14:47:43 +00:00
|
|
|
return
|
2017-03-12 01:41:47 +00:00
|
|
|
print("Packaging dupeGuru with UI qt")
|
2020-01-01 02:16:27 +00:00
|
|
|
if sys.platform == "win32":
|
2021-08-28 22:07:18 +00:00
|
|
|
package_windows()
|
2020-12-30 22:44:27 +00:00
|
|
|
elif sys.platform == "darwin":
|
|
|
|
package_macos()
|
2017-03-12 01:41:47 +00:00
|
|
|
else:
|
2017-08-28 23:27:17 +00:00
|
|
|
if not args.arch_pkg:
|
2020-06-24 23:39:06 +00:00
|
|
|
distname = distro.id()
|
2017-08-28 23:27:17 +00:00
|
|
|
else:
|
2020-01-01 02:16:27 +00:00
|
|
|
distname = "arch"
|
|
|
|
if distname == "arch":
|
2017-08-28 23:27:17 +00:00
|
|
|
package_arch()
|
|
|
|
else:
|
|
|
|
package_debian()
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-04-07 10:56:43 +00:00
|
|
|
main()
|