1212from pathlib import Path
1313
1414# Replaces required to fix the default values set by 'tx add remote' command.
15- # Add or remove
15+ # Add or remove
1616TEXT_TO_REPLACE = {
1717 "2_" : "2." ,
1818 "3_" : "3." ,
3838 "xml_etree_" : "xml.etree." ,
3939 "xmlrpc_" : "xmlrpc." ,
4040 "xml_sax_" : "xml.sax." ,
41- "xml_" : "xml."
41+ "xml_" : "xml." ,
4242}
4343
44+
4445def parse_args ():
4546 parser = argparse .ArgumentParser (description = __doc__ )
4647 parser .add_argument (
4748 "--root-path" ,
4849 "-p" ,
4950 default = Path ("." ),
50- help = "Path to the translation files, and also the .tx/config (defaults to current directory)"
51+ help = "Path to the translation files, and also the .tx/config (defaults to current directory)" ,
5152 )
5253 parser .add_argument (
53- "tx_project" ,
54- help = "Slug of the Transifex project to query resources from"
54+ "tx_project" , help = "Slug of the Transifex project to query resources from"
5555 )
5656 return parser .parse_args ()
5757
@@ -65,11 +65,19 @@ def reset_tx_config(txconfig: Path):
6565
6666def populate_resources_from_remote (config_file : Path , tx_project : str ):
6767 """Add the remote resources from the Transifex project to .tx/config."""
68- result = subprocess .run ([
69- "tx" , "--config" , str (config_file ), "add" , "remote" ,
70- "--file-filter" , "<lang>/<resource_slug>.<ext>" ,
71- f"https://app.transifex.com/python-doc/{ tx_project } /"
72- ], check = True )
68+ result = subprocess .run (
69+ [
70+ "tx" ,
71+ "--config" ,
72+ str (config_file ),
73+ "add" ,
74+ "remote" ,
75+ "--file-filter" ,
76+ "<lang>/<resource_slug>.<ext>" ,
77+ f"https://app.transifex.com/python-doc/{ tx_project } /" ,
78+ ],
79+ check = True ,
80+ )
7381 if result .returncode != 0 :
7482 print ("Failed to add the resources from remote:" )
7583 print (result .stderr .strip ())
@@ -91,9 +99,9 @@ def patch_config(txconfig: Path):
9199 line = line .replace ("--" , "/" )
92100
93101 for pattern , replacement in TEXT_TO_REPLACE .items ():
94- if pattern in line :
95- line = line .replace (pattern , replacement )
96- break
102+ if pattern in line :
103+ line = line .replace (pattern , replacement )
104+ break
97105
98106 new_lines .append (line )
99107
@@ -102,6 +110,7 @@ def patch_config(txconfig: Path):
102110 txconfig .write_text (text + "\n " , encoding = "utf-8" )
103111 print ("Updated .tx/config with character substitutions" )
104112
113+
105114def main ():
106115 args = parse_args ()
107116 config_path = Path (".tx/config" )
0 commit comments