Skip to content

Some fixes and enhancements for the make file #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
if len(sys.argv) >= 4:
addon = sys.argv[3]


def system(scmd, **kwargs):
"""
Replace and call system with scmd.
Expand Down Expand Up @@ -250,6 +251,7 @@ def build_addon(addon):
if files:
do_tar(files)


def check_gramps_path(command):
try:
sys.path.insert(0, GRAMPSPATH)
Expand All @@ -264,6 +266,7 @@ def check_gramps_path(command):
)
exit()


def strip_header(po_file):
"""
Strip the header off a `po` file and return its contents.
Expand All @@ -272,7 +275,7 @@ def strip_header(po_file):
out_file = ""
if not os.path.isfile(po_file):
return out_file
with open(po_file, "r") as in_file:
with open(po_file, "r", encoding="utf-8") as in_file:
for line in in_file:
if not header:
out_file += line
Expand All @@ -286,8 +289,8 @@ def aggregate_pot():
Aggregate the template files for all addons into a single file without
strings that are already present in core Gramps.
"""
args = ["touch", "po/template.pot"]
call(args)
f = open("po/template.pot", "w")
f.close()

args = ["xgettext", "-j", "-o", "po/template.pot"]
args.extend(glob.glob("*/po/template.pot"))
Expand Down Expand Up @@ -317,7 +320,7 @@ def extract_po(addon):
if not os.path.exists(pot):
return
for lang in get_all_languages():
#print (lang)
# print (lang)
po = os.path.join(po_dir, f"{lang}-local.po")
if os.path.exists(f"po/{lang}.po"):
old_file = strip_header(po)
Expand All @@ -337,6 +340,7 @@ def extract_po(addon):
args = ["git", "restore", po]
call(args)


if command == "clean":
if len(sys.argv) == 3:
for addon in [
Expand Down Expand Up @@ -396,18 +400,18 @@ def register(ptype, **kwargs):
continue # skip this one if not listed

mkdir(f"{addon}/po")
fnames = ' '.join(glob.glob(f"{addon}/*.py"))
fnames = " ".join(glob.glob(f"{addon}/*.py"))
system(
f"xgettext --language=Python --keyword=_ --keyword=N_"
f" --from-code=UTF-8"
f' -o "{addon}/po/template.pot" {fnames} '
)
fnames = ' '.join(glob.glob("%s/*.glade" % addon))
fnames = " ".join(glob.glob("%s/*.glade" % addon))
if fnames:
system(
"xgettext -j --add-comments -L Glade "
f'--from-code=UTF-8 -o "{addon}/po/template.pot" '
f'{fnames}'
f"{fnames}"
)

# scan for xml files and get translation text where the tag
Expand Down Expand Up @@ -510,9 +514,9 @@ def register(ptype, **kwargs):
f'"{addon}/po/{locale}-local.po" '
)
# Get all of the addon strings out of the catalog:
system(
f"touch {addon}/po/{locale}-temp.po"
)
f = open(f"{addon}/po/{locale}-temp.po", "w")
f.close()

system(
f"msggrep --location={addon}/* "
f'"{addon}/po/{locale}-global.po" '
Expand Down Expand Up @@ -572,9 +576,14 @@ def register(ptype, **kwargs):

languages = get_all_languages()
listings = {lang: [] for lang in languages}
dirs = [
file for file in glob.glob("*") if os.path.isdir(file) and file != "__pycache__"
]
if len(sys.argv) == 3 or addon == "all":
dirs = [
file
for file in glob.glob("*")
if os.path.isdir(file) and file != "__pycache__"
]
else:
dirs = [addon]
for addon in sorted(dirs):
todo = False
for po in glob.glob(f"{addon}/po/*-local.po"):
Expand Down Expand Up @@ -721,18 +730,18 @@ def register(ptype, **kwargs):
cleanup(addon)
if todo: # make an updated pot file
mkdir("%(addon)s/po")
fnames = ' '.join(glob.glob(f"{addon}/*.py"))
fnames = " ".join(glob.glob(f"{addon}/*.py"))
system(
"xgettext --language=Python --keyword=_ --keyword=N_"
" --from-code=UTF-8"
f' -o "{addon}/po/temp.pot" {fnames} '
)
fnames = ' '.join(glob.glob(f"{addon}/*.glade"))
fnames = " ".join(glob.glob(f"{addon}/*.glade"))
if fnames:
system(
"xgettext -j --add-comments -L Glade "
f'--from-code=UTF-8 -o "{addon}/po/temp.pot" '
f'{fnames}'
f"{fnames}"
)

# scan for xml files and get translation text where the tag
Expand Down Expand Up @@ -1023,10 +1032,10 @@ def register(ptype, **kwargs):
aggregate_pot()

elif command == "extract-po":
for addon in [file for file in glob.glob("*")
if os.path.isdir(file)
and file != "po"]:
print (addon)
for addon in [
file for file in glob.glob("*") if os.path.isdir(file) and file != "po"
]:
print(addon)
extract_po(addon)

else:
Expand Down