Expand glob in update-pot on Windows only
This commit is contained in:
parent
62c87a1fe5
commit
327254d091
|
|
@ -7,9 +7,7 @@ import regex
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import lib.charset as cs
|
import lib.charset as cs
|
||||||
from pathlib import Path, PurePosixPath
|
from pathlib import Path
|
||||||
|
|
||||||
FILE_LIST: list[Path] = []
|
|
||||||
|
|
||||||
# Absolute path
|
# Absolute path
|
||||||
BASE_DIR: Path = Path.absolute(Path(__file__).parent)
|
BASE_DIR: Path = Path.absolute(Path(__file__).parent)
|
||||||
|
|
@ -274,25 +272,13 @@ def main():
|
||||||
ap.add_argument('file', nargs='+', help='Input files')
|
ap.add_argument('file', nargs='+', help='Input files')
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
for path in args.file:
|
|
||||||
if not Path(path).exists():
|
|
||||||
# assume its regex, search for files that match pattern
|
|
||||||
for file in sorted(PO_DIR.glob(path)):
|
|
||||||
FILE_LIST.append(file)
|
|
||||||
else:
|
|
||||||
FILE_LIST.append(Path(path))
|
|
||||||
|
|
||||||
# Convert the path to relative and use Posix format
|
|
||||||
for index, absolute_path in enumerate(FILE_LIST[:]):
|
|
||||||
FILE_LIST[index] = PurePosixPath(absolute_path).relative_to(PO_DIR)
|
|
||||||
|
|
||||||
# extract strings
|
# extract strings
|
||||||
catalog = {}
|
catalog = {}
|
||||||
for path in FILE_LIST:
|
for path in args.file:
|
||||||
extract_file(path, catalog, warn_skipped=args.warn_skipped)
|
extract_file(path, catalog, warn_skipped=args.warn_skipped)
|
||||||
|
|
||||||
# process backreferences in a 2nd pass
|
# process backreferences in a 2nd pass
|
||||||
for path in FILE_LIST:
|
for path in args.file:
|
||||||
extract_refs(path, catalog)
|
extract_refs(path, catalog)
|
||||||
|
|
||||||
# check the catalog entries
|
# check the catalog entries
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,21 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
|
# Constants
|
||||||
BASE_DIR: Path = Path.absolute(Path(__file__).parent)
|
BASE_DIR: Path = Path.absolute(Path(__file__).parent)
|
||||||
PROJECT_DIR: Path = BASE_DIR.parent
|
PROJECT_DIR: Path = BASE_DIR.parent
|
||||||
PO_DIR: Path = BASE_DIR / "po"
|
PO_DIR: Path = BASE_DIR / "po"
|
||||||
|
|
||||||
|
# Regex pattern to search for source files
|
||||||
SEARCH_REGEX: str = "[a-zA-Z]*.[ch]*"
|
SEARCH_REGEX: str = "[a-zA-Z]*.[ch]*"
|
||||||
|
|
||||||
|
# Folders to search for messages
|
||||||
SEARCH_PATHS: list[str] = ["./Firmware", "./Firmware/mmu2"]
|
SEARCH_PATHS: list[str] = ["./Firmware", "./Firmware/mmu2"]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# List of source files to extract messages from
|
||||||
|
FILE_LIST: list[Path] = []
|
||||||
|
|
||||||
# Start by creating a back-up of the current Firmware.pot
|
# Start by creating a back-up of the current Firmware.pot
|
||||||
shutil.copy(PO_DIR / "Firmware.pot", PO_DIR / "Firmware.pot.bak")
|
shutil.copy(PO_DIR / "Firmware.pot", PO_DIR / "Firmware.pot.bak")
|
||||||
|
|
@ -34,16 +41,33 @@ def main():
|
||||||
|
|
||||||
# We want to search for the C/C++ files relative to the .po/ directory
|
# We want to search for the C/C++ files relative to the .po/ directory
|
||||||
# Lets append to the search path an absolute path.
|
# Lets append to the search path an absolute path.
|
||||||
for index, search_path in enumerate(SEARCH_PATHS[:]):
|
for index, search_path in enumerate(SEARCH_PATHS.copy()):
|
||||||
try:
|
try:
|
||||||
# Example: Converts ./Firmware to ../../Firmware
|
# Example: Converts ./Firmware to ../../Firmware
|
||||||
SEARCH_PATHS[index] = PurePath(rel_path).joinpath(search_path)
|
SEARCH_PATHS[index] = PurePath(rel_path).joinpath(search_path)
|
||||||
|
|
||||||
# Example: Convert ../../Firmware to ../../Firmware/[a-zA-Z]*.[ch]*
|
# Example: Convert ../../Firmware to ../../Firmware/[a-zA-Z]*.[ch]*
|
||||||
SEARCH_PATHS[index] = PurePosixPath(SEARCH_PATHS[index]).joinpath(SEARCH_REGEX)
|
SEARCH_PATHS[index] = PurePosixPath(SEARCH_PATHS[index]).joinpath(
|
||||||
|
SEARCH_REGEX
|
||||||
|
)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
print(error)
|
print(error)
|
||||||
|
|
||||||
|
# If operating system is Windows, then the script must expand
|
||||||
|
# the regex expression with glob. On Linux and Mac, the operating
|
||||||
|
# system takes care of expanding the glob for you. We only need to
|
||||||
|
# do this manually on Windows.
|
||||||
|
if sys.platform == "win32":
|
||||||
|
for pattern in SEARCH_PATHS:
|
||||||
|
for file in sorted(PO_DIR.glob(str(pattern))):
|
||||||
|
FILE_LIST.append(file)
|
||||||
|
|
||||||
|
# Convert the path to relative and use Posix format
|
||||||
|
for index, absolute_path in enumerate(FILE_LIST.copy()):
|
||||||
|
FILE_LIST[index] = PurePosixPath(absolute_path).relative_to(PO_DIR)
|
||||||
|
else:
|
||||||
|
FILE_LIST = SEARCH_PATHS
|
||||||
|
|
||||||
# Run the lang-extract.py script
|
# Run the lang-extract.py script
|
||||||
SCRIPT_PATH = BASE_DIR.joinpath("lang-extract.py")
|
SCRIPT_PATH = BASE_DIR.joinpath("lang-extract.py")
|
||||||
try:
|
try:
|
||||||
|
|
@ -55,8 +79,7 @@ def main():
|
||||||
"-s",
|
"-s",
|
||||||
"-o",
|
"-o",
|
||||||
"./Firmware.pot",
|
"./Firmware.pot",
|
||||||
SEARCH_PATHS[0],
|
*FILE_LIST,
|
||||||
SEARCH_PATHS[1],
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
except CalledProcessError as error:
|
except CalledProcessError as error:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue