mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
cleanup: Format using black
This commit is contained in:
parent
4b42016837
commit
af03c2ac0f
36 changed files with 928 additions and 616 deletions
|
@ -34,9 +34,11 @@ class CouldNotPort:
|
|||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
def change_suffix(f):
|
||||
return f.removesuffix(".ui") + ".blp"
|
||||
|
||||
|
||||
def decompile_file(in_file, out_file) -> T.Union[str, CouldNotPort]:
|
||||
if os.path.exists(out_file):
|
||||
return CouldNotPort("already exists")
|
||||
|
@ -61,12 +63,15 @@ def decompile_file(in_file, out_file) -> T.Union[str, CouldNotPort]:
|
|||
except PrintableError as e:
|
||||
e.pretty_print(out_file, decompiled)
|
||||
|
||||
print(f"{Colors.RED}{Colors.BOLD}error: the generated file does not compile{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.RED}{Colors.BOLD}error: the generated file does not compile{Colors.CLEAR}"
|
||||
)
|
||||
print(f"in {Colors.UNDERLINE}{out_file}{Colors.NO_UNDERLINE}")
|
||||
print(
|
||||
f"""{Colors.FAINT}Either the original XML file had an error, or there is a bug in the
|
||||
f"""{Colors.FAINT}Either the original XML file had an error, or there is a bug in the
|
||||
porting tool. If you think it's a bug (which is likely), please file an issue on GitLab:
|
||||
{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/new?issue{Colors.CLEAR}\n""")
|
||||
{Colors.BLUE}{Colors.UNDERLINE}https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/new?issue{Colors.CLEAR}\n"""
|
||||
)
|
||||
|
||||
return CouldNotPort("does not compile")
|
||||
|
||||
|
@ -106,7 +111,9 @@ def enter():
|
|||
|
||||
|
||||
def step1():
|
||||
print(f"{Colors.BOLD}STEP 1: Create subprojects/blueprint-compiler.wrap{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.BOLD}STEP 1: Create subprojects/blueprint-compiler.wrap{Colors.CLEAR}"
|
||||
)
|
||||
|
||||
if os.path.exists("subprojects/blueprint-compiler.wrap"):
|
||||
print("subprojects/blueprint-compiler.wrap already exists, skipping\n")
|
||||
|
@ -119,14 +126,16 @@ def step1():
|
|||
pass
|
||||
|
||||
with open("subprojects/blueprint-compiler.wrap", "w") as wrap:
|
||||
wrap.write("""[wrap-git]
|
||||
wrap.write(
|
||||
"""[wrap-git]
|
||||
directory = blueprint-compiler
|
||||
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
|
||||
revision = main
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
program_names = blueprint-compiler""")
|
||||
program_names = blueprint-compiler"""
|
||||
)
|
||||
|
||||
print()
|
||||
|
||||
|
@ -141,7 +150,9 @@ def step2():
|
|||
if yesno("Add '/subprojects/blueprint-compiler' to .gitignore?"):
|
||||
gitignore.write("\n/subprojects/blueprint-compiler\n")
|
||||
else:
|
||||
print("'/subprojects/blueprint-compiler' already in .gitignore, skipping")
|
||||
print(
|
||||
"'/subprojects/blueprint-compiler' already in .gitignore, skipping"
|
||||
)
|
||||
else:
|
||||
if yesno("Create .gitignore with '/subprojects/blueprint-compiler'?"):
|
||||
with open(".gitignore", "w") as gitignore:
|
||||
|
@ -164,9 +175,13 @@ def step3():
|
|||
if isinstance(result, CouldNotPort):
|
||||
if result.message == "already exists":
|
||||
print(Colors.FAINT, end="")
|
||||
print(f"{Colors.RED}will not port {Colors.UNDERLINE}{in_file}{Colors.NO_UNDERLINE} -> {Colors.UNDERLINE}{out_file}{Colors.NO_UNDERLINE} [{result.message}]{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.RED}will not port {Colors.UNDERLINE}{in_file}{Colors.NO_UNDERLINE} -> {Colors.UNDERLINE}{out_file}{Colors.NO_UNDERLINE} [{result.message}]{Colors.CLEAR}"
|
||||
)
|
||||
else:
|
||||
print(f"will port {Colors.UNDERLINE}{in_file}{Colors.CLEAR} -> {Colors.UNDERLINE}{out_file}{Colors.CLEAR}")
|
||||
print(
|
||||
f"will port {Colors.UNDERLINE}{in_file}{Colors.CLEAR} -> {Colors.UNDERLINE}{out_file}{Colors.CLEAR}"
|
||||
)
|
||||
success += 1
|
||||
|
||||
print()
|
||||
|
@ -175,7 +190,9 @@ def step3():
|
|||
elif success == len(files):
|
||||
print(f"{Colors.GREEN}All files were converted.{Colors.CLEAR}")
|
||||
elif success > 0:
|
||||
print(f"{Colors.RED}{success} file(s) were converted, {len(files) - success} were not.{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.RED}{success} file(s) were converted, {len(files) - success} were not.{Colors.CLEAR}"
|
||||
)
|
||||
else:
|
||||
print(f"{Colors.RED}None of the files could be converted.{Colors.CLEAR}")
|
||||
|
||||
|
@ -199,22 +216,33 @@ def step3():
|
|||
|
||||
def step4(ported):
|
||||
print(f"{Colors.BOLD}STEP 4: Set up meson.build{Colors.CLEAR}")
|
||||
print(f"{Colors.BOLD}{Colors.YELLOW}NOTE: Depending on your build system setup, you may need to make some adjustments to this step.{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.BOLD}{Colors.YELLOW}NOTE: Depending on your build system setup, you may need to make some adjustments to this step.{Colors.CLEAR}"
|
||||
)
|
||||
|
||||
meson_files = [file for file in listdir_recursive(".") if os.path.basename(file) == "meson.build"]
|
||||
meson_files = [
|
||||
file
|
||||
for file in listdir_recursive(".")
|
||||
if os.path.basename(file) == "meson.build"
|
||||
]
|
||||
for meson_file in meson_files:
|
||||
with open(meson_file, "r") as f:
|
||||
if "gnome.compile_resources" in f.read():
|
||||
parent = os.path.dirname(meson_file)
|
||||
file_list = "\n ".join([
|
||||
f"'{os.path.relpath(file, parent)}',"
|
||||
for file in ported
|
||||
if file.startswith(parent)
|
||||
])
|
||||
file_list = "\n ".join(
|
||||
[
|
||||
f"'{os.path.relpath(file, parent)}',"
|
||||
for file in ported
|
||||
if file.startswith(parent)
|
||||
]
|
||||
)
|
||||
|
||||
if len(file_list):
|
||||
print(f"{Colors.BOLD}Paste the following into {Colors.UNDERLINE}{meson_file}{Colors.NO_UNDERLINE}:{Colors.CLEAR}")
|
||||
print(f"""
|
||||
print(
|
||||
f"{Colors.BOLD}Paste the following into {Colors.UNDERLINE}{meson_file}{Colors.NO_UNDERLINE}:{Colors.CLEAR}"
|
||||
)
|
||||
print(
|
||||
f"""
|
||||
blueprints = custom_target('blueprints',
|
||||
input: files(
|
||||
{file_list}
|
||||
|
@ -222,14 +250,17 @@ blueprints = custom_target('blueprints',
|
|||
output: '.',
|
||||
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
enter()
|
||||
|
||||
print(f"""{Colors.BOLD}Paste the following into the 'gnome.compile_resources()'
|
||||
print(
|
||||
f"""{Colors.BOLD}Paste the following into the 'gnome.compile_resources()'
|
||||
arguments in {Colors.UNDERLINE}{meson_file}{Colors.NO_UNDERLINE}:{Colors.CLEAR}
|
||||
|
||||
dependencies: blueprints,
|
||||
""")
|
||||
"""
|
||||
)
|
||||
enter()
|
||||
|
||||
print()
|
||||
|
@ -239,7 +270,9 @@ def step5(in_files):
|
|||
print(f"{Colors.BOLD}STEP 5: Update POTFILES.in{Colors.CLEAR}")
|
||||
|
||||
if not os.path.exists("po/POTFILES.in"):
|
||||
print(f"{Colors.UNDERLINE}po/POTFILES.in{Colors.NO_UNDERLINE} does not exist, skipping\n")
|
||||
print(
|
||||
f"{Colors.UNDERLINE}po/POTFILES.in{Colors.NO_UNDERLINE} does not exist, skipping\n"
|
||||
)
|
||||
return
|
||||
|
||||
with open("po/POTFILES.in", "r") as potfiles:
|
||||
|
@ -252,12 +285,24 @@ def step5(in_files):
|
|||
|
||||
new_data = "".join(lines)
|
||||
|
||||
print(f"{Colors.BOLD}Will make the following changes to {Colors.UNDERLINE}po/POTFILES.in{Colors.CLEAR}")
|
||||
print(
|
||||
"".join([
|
||||
(Colors.GREEN if line.startswith('+') else Colors.RED + Colors.FAINT if line.startswith('-') else '') + line + Colors.CLEAR
|
||||
for line in difflib.unified_diff(old_lines, lines)
|
||||
])
|
||||
f"{Colors.BOLD}Will make the following changes to {Colors.UNDERLINE}po/POTFILES.in{Colors.CLEAR}"
|
||||
)
|
||||
print(
|
||||
"".join(
|
||||
[
|
||||
(
|
||||
Colors.GREEN
|
||||
if line.startswith("+")
|
||||
else Colors.RED + Colors.FAINT
|
||||
if line.startswith("-")
|
||||
else ""
|
||||
)
|
||||
+ line
|
||||
+ Colors.CLEAR
|
||||
for line in difflib.unified_diff(old_lines, lines)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
if yesno("Is this ok?"):
|
||||
|
@ -286,5 +331,6 @@ def run(opts):
|
|||
step5(in_files)
|
||||
step6(in_files)
|
||||
|
||||
print(f"{Colors.BOLD}STEP 6: Done! Make sure your app still builds and runs correctly.{Colors.CLEAR}")
|
||||
|
||||
print(
|
||||
f"{Colors.BOLD}STEP 6: Done! Make sure your app still builds and runs correctly.{Colors.CLEAR}"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue