Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f8bc49

Browse files
authored
Move TEXT_TO_REPLACE outside function, move parse_args first
1 parent2db5351 commit9f8bc49

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

‎scripts/generate_txconfig.py‎

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,51 @@
1111
importsys
1212
frompathlibimportPath
1313

14+
# Replaces required to fix the default values set by 'tx add remote' command.
15+
# Add or remove
16+
TEXT_TO_REPLACE= {
17+
"2_":"2.",
18+
"3_":"3.",
19+
"glossary_":"glossary",
20+
"collections_":"collections.",
21+
"compression_":"compression.",
22+
"concurrent_":"concurrent.",
23+
"curses_":"curses.",
24+
"email_":"email.",
25+
"html_":"html.",
26+
"http_":"http.",
27+
"importlib_resources_":"importlib.resources.",
28+
"importlib_":"importlib.",
29+
"logging_":"logging.",
30+
"multiprocessing_":"multiprocessing.",
31+
"os_":"os.",
32+
"string_":"string.",
33+
"sys_monitoring":"sys.monitoring",
34+
"tkinter_":"tkinter.",
35+
"unittest_":"unittest.",
36+
"urllib_":"urllib.",
37+
"xml_dom_":"xml.dom.",
38+
"xml_etree_":"xml.etree.",
39+
"xmlrpc_":"xmlrpc.",
40+
"xml_sax_":"xml.sax.",
41+
"xml_":"xml."
42+
}
43+
44+
defparse_args():
45+
parser=argparse.ArgumentParser(description=__doc__)
46+
parser.add_argument(
47+
"--root-path",
48+
"-p",
49+
default=Path("."),
50+
help="Path to the translation files, and also the .tx/config (defaults to current directory)"
51+
)
52+
parser.add_argument(
53+
"tx_project",
54+
help="Slug of the Transifex project to query resources from"
55+
)
56+
returnparser.parse_args()
57+
58+
1459
defreset_tx_config(txconfig:Path):
1560
"""Create or reset the .tx/config file with basic header."""
1661
txconfig.parent.mkdir(exist_ok=True)
@@ -37,34 +82,6 @@ def patch_config(txconfig: Path):
3782
content=txconfig.read_text(encoding="utf-8").splitlines()
3883
new_lines= []
3984

40-
text_to_replace= {
41-
"2_":"2.",
42-
"3_":"3.",
43-
"glossary_":"glossary",
44-
"collections_":"collections.",
45-
"compression_":"compression.",
46-
"concurrent_":"concurrent.",
47-
"curses_":"curses.",
48-
"email_":"email.",
49-
"html_":"html.",
50-
"http_":"http.",
51-
"importlib_resources_":"importlib.resources.",
52-
"importlib_":"importlib.",
53-
"logging_":"logging.",
54-
"multiprocessing_":"multiprocessing.",
55-
"os_":"os.",
56-
"string_":"string.",
57-
"sys_monitoring":"sys.monitoring",
58-
"tkinter_":"tkinter.",
59-
"unittest_":"unittest.",
60-
"urllib_":"urllib.",
61-
"xml_dom_":"xml.dom.",
62-
"xml_etree_":"xml.etree.",
63-
"xmlrpc_":"xmlrpc.",
64-
"xml_sax_":"xml.sax.",
65-
"xml_":"xml."
66-
}
67-
6885
forlineincontent:
6986
ifline.startswith(("source_file","source_lang")):
7087
continue
@@ -73,7 +90,7 @@ def patch_config(txconfig: Path):
7390
line=line.replace("<lang>/","")
7491
line=line.replace("--","/")
7592

76-
forpattern,replacementintext_to_replace.items():
93+
forpattern,replacementinTEXT_TO_REPLACE.items():
7794
ifpatterninline:
7895
line=line.replace(pattern,replacement)
7996
break
@@ -85,30 +102,14 @@ def patch_config(txconfig: Path):
85102
txconfig.write_text(text+"\n",encoding="utf-8")
86103
print("Updated .tx/config with character substitutions")
87104

88-
89-
defparse_args():
90-
parser=argparse.ArgumentParser(description=__doc__)
91-
parser.add_argument(
92-
"--root-path",
93-
"-p",
94-
default=Path("."),
95-
help="Path to the translation files, and also the .tx/config"
96-
)
97-
parser.add_argument(
98-
"tx_project",
99-
help="Name of the Transifex project to query resources from (e.g. python-newest or python-313)"
100-
)
101-
returnparser.parse_args()
102-
103-
104105
defmain():
105106
args=parse_args()
106-
TX_CONFIG=Path(".tx/config")
107+
config_path=Path(".tx/config")
107108
ifargs.root_path:
108-
TX_CONFIG=args.root_path/TX_CONFIG
109-
reset_tx_config(TX_CONFIG)
110-
populate_resources_from_remote(TX_CONFIG,args.tx_project)
111-
patch_config(TX_CONFIG)
109+
config_path=args.root_path/config_path
110+
reset_tx_config(config_path)
111+
populate_resources_from_remote(config_path,args.tx_project)
112+
patch_config(config_path)
112113

113114

114115
if__name__=="__main__":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp