mirror of
https://github.com/libretro/RetroArch
synced 2024-07-05 09:48:42 +00:00
Stop Crowdin Daily Workflow from activating with empty API key (#13440)
* Stop Crowdin Daily Workflow from activating with empty API key * Make sure that the API key is always reset
This commit is contained in:
parent
c29fd8e53a
commit
c28df9ccef
|
@ -9,11 +9,17 @@ import urllib.request
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
# Check Crowdin API Key
|
# Check Crowdin API Key
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print('Please provide Crowdin API Key!')
|
|
||||||
exit()
|
|
||||||
|
|
||||||
api_key = sys.argv[1]
|
try:
|
||||||
|
api_key = sys.argv[1] # IndexError, if no key is given
|
||||||
|
if not api_key: # if key is empty
|
||||||
|
raise ValueError
|
||||||
|
except IndexError:
|
||||||
|
print('Please provide Crowdin API Key!')
|
||||||
|
raise
|
||||||
|
except ValueError:
|
||||||
|
print("Crowdin API Key can't be empty!")
|
||||||
|
raise
|
||||||
|
|
||||||
# Apply Crowdin API Key
|
# Apply Crowdin API Key
|
||||||
crowdin_config_file = open('crowdin.yaml', 'r')
|
crowdin_config_file = open('crowdin.yaml', 'r')
|
||||||
|
@ -24,12 +30,13 @@ crowdin_config_file = open('crowdin.yaml', 'w')
|
||||||
crowdin_config_file.write(crowdin_config)
|
crowdin_config_file.write(crowdin_config)
|
||||||
crowdin_config_file.close()
|
crowdin_config_file.close()
|
||||||
|
|
||||||
# Download Crowdin CLI
|
try: # catch any exception after crowdin.yaml was changed
|
||||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
# Download Crowdin CLI
|
||||||
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
jar_name = 'crowdin-cli.jar'
|
jar_name = 'crowdin-cli.jar'
|
||||||
|
|
||||||
if not os.path.isfile(jar_name):
|
if not os.path.isfile(jar_name):
|
||||||
print('download crowdin-cli.jar')
|
print('download crowdin-cli.jar')
|
||||||
crowdin_cli_file = 'crowdin-cli.zip'
|
crowdin_cli_file = 'crowdin-cli.zip'
|
||||||
crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file
|
crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file
|
||||||
|
@ -44,34 +51,44 @@ if not os.path.isfile(jar_name):
|
||||||
os.remove(crowdin_cli_file)
|
os.remove(crowdin_cli_file)
|
||||||
shutil.rmtree(jar_dir)
|
shutil.rmtree(jar_dir)
|
||||||
|
|
||||||
print('convert *.h to *.json')
|
print('convert *.h to *.json')
|
||||||
for item in os.listdir(dir_path):
|
for item in os.listdir(dir_path):
|
||||||
if item.endswith(".h"):
|
if item.endswith(".h"):
|
||||||
subprocess.run(['python3', 'h2json.py', item])
|
subprocess.run(['python3', 'h2json.py', item])
|
||||||
|
|
||||||
print('upload source *.json')
|
print('upload source *.json')
|
||||||
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'upload', 'sources'])
|
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'upload', 'sources'])
|
||||||
|
|
||||||
print('wait for crowdin server to process data')
|
print('wait for crowdin server to process data')
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
print('download translation *.json')
|
print('download translation *.json')
|
||||||
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'download'])
|
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'download'])
|
||||||
|
|
||||||
print('convert *.json to *.h')
|
print('convert *.json to *.h')
|
||||||
for file in os.listdir(dir_path):
|
for file in os.listdir(dir_path):
|
||||||
if file.startswith('msg_hash_') and file.endswith('.json'):
|
if file.startswith('msg_hash_') and file.endswith('.json'):
|
||||||
print(file)
|
print(file)
|
||||||
subprocess.run(['python3', 'json2h.py', file])
|
subprocess.run(['python3', 'json2h.py', file])
|
||||||
|
|
||||||
print('fetch translation progress')
|
print('fetch translation progress')
|
||||||
subprocess.run(['python3', 'fetch_progress.py'])
|
subprocess.run(['python3', 'fetch_progress.py'])
|
||||||
|
|
||||||
# Reset Crowdin API Key
|
# Reset Crowdin API Key
|
||||||
crowdin_config_file = open('crowdin.yaml', 'r')
|
crowdin_config_file = open('crowdin.yaml', 'r')
|
||||||
crowdin_config = crowdin_config_file.read()
|
crowdin_config = crowdin_config_file.read()
|
||||||
crowdin_config_file.close()
|
crowdin_config_file.close()
|
||||||
crowdin_config = crowdin_config.replace(api_key, '_secret_')
|
crowdin_config = crowdin_config.replace(api_key, '_secret_')
|
||||||
crowdin_config_file = open('crowdin.yaml', 'w')
|
crowdin_config_file = open('crowdin.yaml', 'w')
|
||||||
crowdin_config_file.write(crowdin_config)
|
crowdin_config_file.write(crowdin_config)
|
||||||
crowdin_config_file.close()
|
crowdin_config_file.close()
|
||||||
|
except:
|
||||||
|
# Reset Crowdin API Key no matter what
|
||||||
|
crowdin_config_file = open('crowdin.yaml', 'r')
|
||||||
|
crowdin_config = crowdin_config_file.read()
|
||||||
|
crowdin_config_file.close()
|
||||||
|
crowdin_config = crowdin_config.replace(api_key, '_secret_')
|
||||||
|
crowdin_config_file = open('crowdin.yaml', 'w')
|
||||||
|
crowdin_config_file.write(crowdin_config)
|
||||||
|
crowdin_config_file.close()
|
||||||
|
raise
|
||||||
|
|
Loading…
Reference in New Issue
Block a user