2017-03-12 19:00:57 +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
|
|
|
|
2021-08-26 08:29:24 +00:00
|
|
|
from pathlib import Path
|
2021-08-21 04:49:20 +00:00
|
|
|
import sys
|
2011-01-21 13:39:33 +00:00
|
|
|
from optparse import OptionParser
|
2010-01-01 20:42:52 +00:00
|
|
|
import shutil
|
2021-08-28 22:07:18 +00:00
|
|
|
from multiprocessing import Pool
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2021-08-26 08:29:24 +00:00
|
|
|
from setuptools import sandbox
|
2011-01-12 16:30:57 +00:00
|
|
|
from hscommon import sphinxgen
|
2014-10-13 19:08:59 +00:00
|
|
|
from hscommon.build import (
|
2020-01-01 02:16:27 +00:00
|
|
|
add_to_pythonpath,
|
|
|
|
print_and_do,
|
|
|
|
fix_qt_resource_file,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon import loc
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def parse_args():
|
|
|
|
usage = "usage: %prog [options]"
|
|
|
|
parser = OptionParser(usage=usage)
|
2014-10-13 19:08:59 +00:00
|
|
|
parser.add_option(
|
2020-01-01 02:16:27 +00:00
|
|
|
"--clean",
|
|
|
|
action="store_true",
|
|
|
|
dest="clean",
|
|
|
|
help="Clean build folder before building",
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2021-08-28 22:07:18 +00: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 09:10:18 +00:00
|
|
|
parser.add_option("--loc", action="store_true", dest="loc", help="Build only localization")
|
2014-10-13 19:08:59 +00:00
|
|
|
parser.add_option(
|
2020-01-01 02:16:27 +00:00
|
|
|
"--updatepot",
|
|
|
|
action="store_true",
|
|
|
|
dest="updatepot",
|
|
|
|
help="Generate .pot files from source code.",
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
|
|
|
parser.add_option(
|
2020-01-01 02:16:27 +00:00
|
|
|
"--mergepot",
|
|
|
|
action="store_true",
|
|
|
|
dest="mergepot",
|
|
|
|
help="Update all .po files based on .pot files.",
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
|
|
|
parser.add_option(
|
2020-01-01 02:16:27 +00:00
|
|
|
"--normpo",
|
|
|
|
action="store_true",
|
|
|
|
dest="normpo",
|
|
|
|
help="Normalize all PO files (do this before commit).",
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2020-12-29 02:59:01 +00:00
|
|
|
parser.add_option(
|
|
|
|
"--modules",
|
|
|
|
action="store_true",
|
|
|
|
dest="modules",
|
|
|
|
help="Build the python modules.",
|
|
|
|
)
|
2011-01-21 13:39:33 +00:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
return options
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2021-08-28 22:07:18 +00:00
|
|
|
def build_one_help(language):
|
2022-04-28 01:53:12 +00:00
|
|
|
print(f"Generating Help in {language}")
|
2021-08-26 08:29:24 +00:00
|
|
|
current_path = Path(".").absolute()
|
|
|
|
changelog_path = current_path.joinpath("help", "changelog")
|
2021-01-30 21:17:43 +00:00
|
|
|
tixurl = "https://github.com/arsenetar/dupeguru/issues/{}"
|
2021-08-26 08:29:24 +00:00
|
|
|
changelogtmpl = current_path.joinpath("help", "changelog.tmpl")
|
|
|
|
conftmpl = current_path.joinpath("help", "conf.tmpl")
|
2021-08-28 22:07:18 +00:00
|
|
|
help_basepath = current_path.joinpath("help", language)
|
|
|
|
help_destpath = current_path.joinpath("build", "help", language)
|
|
|
|
confrepl = {"language": language}
|
2020-01-01 02:16:27 +00:00
|
|
|
sphinxgen.gen(
|
|
|
|
help_basepath,
|
|
|
|
help_destpath,
|
|
|
|
changelog_path,
|
|
|
|
tixurl,
|
|
|
|
confrepl,
|
|
|
|
conftmpl,
|
|
|
|
changelogtmpl,
|
|
|
|
)
|
|
|
|
|
2011-01-11 16:58:28 +00:00
|
|
|
|
2021-08-28 22:07:18 +00: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)
|
|
|
|
|
|
|
|
|
2017-03-12 19:00:57 +00:00
|
|
|
def build_localizations():
|
2020-01-01 02:16:27 +00:00
|
|
|
loc.compile_all_po("locale")
|
2021-08-26 08:29:24 +00:00
|
|
|
locale_dest = Path("build", "locale")
|
|
|
|
if locale_dest.exists():
|
2012-08-02 16:49:49 +00:00
|
|
|
shutil.rmtree(locale_dest)
|
2021-08-15 09:10:18 +00:00
|
|
|
shutil.copytree("locale", locale_dest, ignore=shutil.ignore_patterns("*.po", "*.pot"))
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
|
2011-11-02 19:55:20 +00:00
|
|
|
def build_updatepot():
|
2011-11-01 19:44:18 +00:00
|
|
|
print("Building .pot files from source files")
|
|
|
|
print("Building core.pot")
|
2021-08-26 08:29:24 +00:00
|
|
|
loc.generate_pot(["core"], Path("locale", "core.pot"), ["tr"])
|
2011-11-01 19:44:18 +00:00
|
|
|
print("Building columns.pot")
|
2021-08-26 08:29:24 +00:00
|
|
|
loc.generate_pot(["core"], Path("locale", "columns.pot"), ["coltr"])
|
2011-11-01 19:44:18 +00:00
|
|
|
print("Building ui.pot")
|
2022-03-28 05:47:46 +00:00
|
|
|
loc.generate_pot(["qt"], Path("locale", "ui.pot"), ["tr"], merge=True)
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-11-02 19:55:20 +00:00
|
|
|
|
|
|
|
def build_mergepot():
|
|
|
|
print("Updating .po files using .pot files")
|
2020-01-01 02:16:27 +00:00
|
|
|
loc.merge_pots_into_pos("locale")
|
|
|
|
|
2011-06-14 17:43:29 +00:00
|
|
|
|
2013-08-03 21:13:24 +00:00
|
|
|
def build_normpo():
|
2020-01-01 02:16:27 +00:00
|
|
|
loc.normalize_all_pos("locale")
|
2021-03-18 00:55:00 +00:00
|
|
|
|
|
|
|
|
2017-03-12 19:00:57 +00:00
|
|
|
def build_pe_modules():
|
2010-08-17 07:30:25 +00:00
|
|
|
print("Building PE Modules")
|
2021-08-26 08:29:24 +00:00
|
|
|
# Leverage setup.py to build modules
|
|
|
|
sandbox.run_setup("setup.py", ["build_ext", "--inplace"])
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2010-02-09 14:32:52 +00:00
|
|
|
|
2017-03-12 19:00:57 +00:00
|
|
|
def build_normal():
|
|
|
|
print("Building dupeGuru with UI qt")
|
2020-01-01 02:16:27 +00:00
|
|
|
add_to_pythonpath(".")
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Building dupeGuru")
|
2017-03-12 19:00:57 +00:00
|
|
|
build_pe_modules()
|
|
|
|
print("Building localizations")
|
|
|
|
build_localizations()
|
|
|
|
print("Building Qt stuff")
|
2023-04-27 06:36:32 +00:00
|
|
|
Path("qt", "dg_rc.py").unlink(missing_ok=True)
|
2022-04-28 01:53:12 +00:00
|
|
|
print_and_do("pyrcc5 {} > {}".format(Path("qt", "dg.qrc"), Path("qt", "dg_rc.py")))
|
2021-08-26 08:29:24 +00:00
|
|
|
fix_qt_resource_file(Path("qt", "dg_rc.py"))
|
2017-03-12 19:00:57 +00:00
|
|
|
build_help()
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def main():
|
2022-03-15 10:09:58 +00:00
|
|
|
if sys.version_info < (3, 7):
|
|
|
|
sys.exit("Python < 3.7 is unsupported.")
|
2011-01-21 13:39:33 +00:00
|
|
|
options = parse_args()
|
2021-08-26 08:29:24 +00:00
|
|
|
if options.clean and Path("build").exists():
|
2021-08-21 04:49:20 +00:00
|
|
|
shutil.rmtree("build")
|
2021-08-26 08:29:24 +00:00
|
|
|
if not Path("build").exists():
|
|
|
|
Path("build").mkdir()
|
2011-06-14 17:43:29 +00:00
|
|
|
if options.doc:
|
2021-08-28 22:07:18 +00:00
|
|
|
build_one_help("en")
|
|
|
|
elif options.all_doc:
|
2016-06-01 00:21:07 +00:00
|
|
|
build_help()
|
2011-06-14 17:43:29 +00:00
|
|
|
elif options.loc:
|
2017-03-12 19:00:57 +00:00
|
|
|
build_localizations()
|
2011-11-02 19:55:20 +00:00
|
|
|
elif options.updatepot:
|
|
|
|
build_updatepot()
|
|
|
|
elif options.mergepot:
|
|
|
|
build_mergepot()
|
2013-08-03 21:13:24 +00:00
|
|
|
elif options.normpo:
|
|
|
|
build_normpo()
|
2020-12-29 02:59:01 +00:00
|
|
|
elif options.modules:
|
|
|
|
build_pe_modules()
|
2011-01-21 13:39:33 +00:00
|
|
|
else:
|
2017-03-12 19:00:57 +00:00
|
|
|
build_normal()
|
2011-01-21 13:39:33 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2009-12-30 16:34:41 +00:00
|
|
|
main()
|