2017-03-12 15:00:57 -04:00
|
|
|
# Copyright 2017 Virgil Dupras
|
2014-10-05 16:31:16 -04:00
|
|
|
#
|
2015-01-03 16:33:16 -05:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-05 16:31:16 -04:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 16:33:16 -05:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2021-08-26 03:29:24 -05:00
|
|
|
from pathlib import Path
|
2021-08-20 23:49:20 -05:00
|
|
|
import sys
|
2011-01-21 14:39:33 +01:00
|
|
|
from optparse import OptionParser
|
2010-01-01 21:42:52 +01:00
|
|
|
import shutil
|
2021-08-28 17:07:18 -05:00
|
|
|
from multiprocessing import Pool
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2021-08-26 03:29:24 -05:00
|
|
|
from setuptools import sandbox
|
2011-01-12 17:30:57 +01:00
|
|
|
from hscommon import sphinxgen
|
2014-10-13 15:08:59 -04:00
|
|
|
from hscommon.build import (
|
2019-12-31 20:16:27 -06:00
|
|
|
add_to_pythonpath,
|
|
|
|
print_and_do,
|
|
|
|
fix_qt_resource_file,
|
2014-10-13 15:08:59 -04:00
|
|
|
)
|
2011-11-01 15:44:18 -04:00
|
|
|
from hscommon import loc
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2011-01-21 14:39:33 +01:00
|
|
|
def parse_args():
|
|
|
|
usage = "usage: %prog [options]"
|
|
|
|
parser = OptionParser(usage=usage)
|
2014-10-13 15:08:59 -04:00
|
|
|
parser.add_option(
|
2019-12-31 20:16:27 -06:00
|
|
|
"--clean",
|
|
|
|
action="store_true",
|
|
|
|
dest="clean",
|
|
|
|
help="Clean build folder before building",
|
2014-10-13 15:08:59 -04:00
|
|
|
)
|
2021-08-28 17:07:18 -05:00
|
|
|
parser.add_option("--doc", action="store_true", dest="doc", help="Build only the help file (en)")
|
|
|
|
parser.add_option("--alldoc", action="store_true", dest="all_doc", help="Build only the help file in all languages")
|
2021-08-15 04:10:18 -05:00
|
|
|
parser.add_option("--loc", action="store_true", dest="loc", help="Build only localization")
|
2014-10-13 15:08:59 -04:00
|
|
|
parser.add_option(
|
2019-12-31 20:16:27 -06:00
|
|
|
"--updatepot",
|
|
|
|
action="store_true",
|
|
|
|
dest="updatepot",
|
|
|
|
help="Generate .pot files from source code.",
|
2014-10-13 15:08:59 -04:00
|
|
|
)
|
|
|
|
parser.add_option(
|
2019-12-31 20:16:27 -06:00
|
|
|
"--mergepot",
|
|
|
|
action="store_true",
|
|
|
|
dest="mergepot",
|
|
|
|
help="Update all .po files based on .pot files.",
|
2014-10-13 15:08:59 -04:00
|
|
|
)
|
|
|
|
parser.add_option(
|
2019-12-31 20:16:27 -06:00
|
|
|
"--normpo",
|
|
|
|
action="store_true",
|
|
|
|
dest="normpo",
|
|
|
|
help="Normalize all PO files (do this before commit).",
|
2014-10-13 15:08:59 -04:00
|
|
|
)
|
2020-12-28 20:59:01 -06:00
|
|
|
parser.add_option(
|
|
|
|
"--modules",
|
|
|
|
action="store_true",
|
|
|
|
dest="modules",
|
|
|
|
help="Build the python modules.",
|
|
|
|
)
|
2011-01-21 14:39:33 +01:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
return options
|
|
|
|
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2021-08-28 17:07:18 -05:00
|
|
|
def build_one_help(language):
|
2022-04-27 20:53:12 -05:00
|
|
|
print(f"Generating Help in {language}")
|
2021-08-26 03:29:24 -05:00
|
|
|
current_path = Path(".").absolute()
|
|
|
|
changelog_path = current_path.joinpath("help", "changelog")
|
2021-01-30 22:17:43 +01:00
|
|
|
tixurl = "https://github.com/arsenetar/dupeguru/issues/{}"
|
2021-08-26 03:29:24 -05:00
|
|
|
changelogtmpl = current_path.joinpath("help", "changelog.tmpl")
|
|
|
|
conftmpl = current_path.joinpath("help", "conf.tmpl")
|
2021-08-28 17:07:18 -05:00
|
|
|
help_basepath = current_path.joinpath("help", language)
|
|
|
|
help_destpath = current_path.joinpath("build", "help", language)
|
|
|
|
confrepl = {"language": language}
|
2019-12-31 20:16:27 -06:00
|
|
|
sphinxgen.gen(
|
|
|
|
help_basepath,
|
|
|
|
help_destpath,
|
|
|
|
changelog_path,
|
|
|
|
tixurl,
|
|
|
|
confrepl,
|
|
|
|
conftmpl,
|
|
|
|
changelogtmpl,
|
|
|
|
)
|
|
|
|
|
2011-01-11 17:58:28 +01:00
|
|
|
|
2021-08-28 17:07:18 -05:00
|
|
|
def build_help():
|
|
|
|
languages = ["en", "de", "fr", "hy", "ru", "uk"]
|
|
|
|
# Running with Pools as for some reason sphinx seems to cross contaminate the output otherwise
|
|
|
|
with Pool(len(languages)) as p:
|
|
|
|
p.map(build_one_help, languages)
|
|
|
|
|
|
|
|
|
2012-08-02 12:49:49 -04:00
|
|
|
def build_qt_localizations():
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.compile_all_po(Path("qtlib", "locale"))
|
|
|
|
loc.merge_locale_dir(Path("qtlib", "locale"), "locale")
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2012-08-02 12:49:49 -04:00
|
|
|
|
2017-03-12 15:00:57 -04:00
|
|
|
def build_localizations():
|
2019-12-31 20:16:27 -06:00
|
|
|
loc.compile_all_po("locale")
|
2017-03-12 15:00:57 -04:00
|
|
|
build_qt_localizations()
|
2021-08-26 03:29:24 -05:00
|
|
|
locale_dest = Path("build", "locale")
|
|
|
|
if locale_dest.exists():
|
2012-08-02 12:49:49 -04:00
|
|
|
shutil.rmtree(locale_dest)
|
2021-08-15 04:10:18 -05:00
|
|
|
shutil.copytree("locale", locale_dest, ignore=shutil.ignore_patterns("*.po", "*.pot"))
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2011-11-01 15:44:18 -04:00
|
|
|
|
2011-11-02 15:55:20 -04:00
|
|
|
def build_updatepot():
|
2011-11-01 15:44:18 -04:00
|
|
|
print("Building .pot files from source files")
|
|
|
|
print("Building core.pot")
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.generate_pot(["core"], Path("locale", "core.pot"), ["tr"])
|
2011-11-01 15:44:18 -04:00
|
|
|
print("Building columns.pot")
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.generate_pot(["core"], Path("locale", "columns.pot"), ["coltr"])
|
2011-11-01 15:44:18 -04:00
|
|
|
print("Building ui.pot")
|
2022-03-28 00:47:46 -05:00
|
|
|
loc.generate_pot(["qt"], Path("locale", "ui.pot"), ["tr"], merge=True)
|
2011-11-01 15:44:18 -04:00
|
|
|
print("Building qtlib.pot")
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.generate_pot(["qtlib"], Path("qtlib", "locale", "qtlib.pot"), ["tr"])
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2011-11-02 15:55:20 -04:00
|
|
|
|
|
|
|
def build_mergepot():
|
|
|
|
print("Updating .po files using .pot files")
|
2019-12-31 20:16:27 -06:00
|
|
|
loc.merge_pots_into_pos("locale")
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.merge_pots_into_pos(Path("qtlib", "locale"))
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2011-06-14 13:43:29 -04:00
|
|
|
|
2013-08-03 17:13:24 -04:00
|
|
|
def build_normpo():
|
2019-12-31 20:16:27 -06:00
|
|
|
loc.normalize_all_pos("locale")
|
2021-08-26 03:29:24 -05:00
|
|
|
loc.normalize_all_pos(Path("qtlib", "locale"))
|
2021-03-17 19:55:00 -05:00
|
|
|
|
|
|
|
|
2017-03-12 15:00:57 -04:00
|
|
|
def build_pe_modules():
|
2010-08-17 09:30:25 +02:00
|
|
|
print("Building PE Modules")
|
2021-08-26 03:29:24 -05:00
|
|
|
# Leverage setup.py to build modules
|
|
|
|
sandbox.run_setup("setup.py", ["build_ext", "--inplace"])
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2010-02-09 15:32:52 +01:00
|
|
|
|
2017-03-12 15:00:57 -04:00
|
|
|
def build_normal():
|
|
|
|
print("Building dupeGuru with UI qt")
|
2019-12-31 20:16:27 -06:00
|
|
|
add_to_pythonpath(".")
|
2010-08-11 16:39:06 +02:00
|
|
|
print("Building dupeGuru")
|
2017-03-12 15:00:57 -04:00
|
|
|
build_pe_modules()
|
|
|
|
print("Building localizations")
|
|
|
|
build_localizations()
|
|
|
|
print("Building Qt stuff")
|
2022-04-27 20:53:12 -05:00
|
|
|
print_and_do("pyrcc5 {} > {}".format(Path("qt", "dg.qrc"), Path("qt", "dg_rc.py")))
|
2021-08-26 03:29:24 -05:00
|
|
|
fix_qt_resource_file(Path("qt", "dg_rc.py"))
|
2017-03-12 15:00:57 -04:00
|
|
|
build_help()
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2019-12-31 20:16:27 -06:00
|
|
|
|
2011-01-21 14:39:33 +01:00
|
|
|
def main():
|
2022-03-15 05:09:58 -05:00
|
|
|
if sys.version_info < (3, 7):
|
|
|
|
sys.exit("Python < 3.7 is unsupported.")
|
2011-01-21 14:39:33 +01:00
|
|
|
options = parse_args()
|
2021-08-26 03:29:24 -05:00
|
|
|
if options.clean and Path("build").exists():
|
2021-08-20 23:49:20 -05:00
|
|
|
shutil.rmtree("build")
|
2021-08-26 03:29:24 -05:00
|
|
|
if not Path("build").exists():
|
|
|
|
Path("build").mkdir()
|
2011-06-14 13:43:29 -04:00
|
|
|
if options.doc:
|
2021-08-28 17:07:18 -05:00
|
|
|
build_one_help("en")
|
|
|
|
elif options.all_doc:
|
2016-05-31 20:21:07 -04:00
|
|
|
build_help()
|
2011-06-14 13:43:29 -04:00
|
|
|
elif options.loc:
|
2017-03-12 15:00:57 -04:00
|
|
|
build_localizations()
|
2011-11-02 15:55:20 -04:00
|
|
|
elif options.updatepot:
|
|
|
|
build_updatepot()
|
|
|
|
elif options.mergepot:
|
|
|
|
build_mergepot()
|
2013-08-03 17:13:24 -04:00
|
|
|
elif options.normpo:
|
|
|
|
build_normpo()
|
2020-12-28 20:59:01 -06:00
|
|
|
elif options.modules:
|
|
|
|
build_pe_modules()
|
2011-01-21 14:39:33 +01:00
|
|
|
else:
|
2017-03-12 15:00:57 -04:00
|
|
|
build_normal()
|
2011-01-21 14:39:33 +01:00
|
|
|
|
2019-12-31 20:16:27 -06:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2009-12-30 16:34:41 +00:00
|
|
|
main()
|