1
0

file i/o: use 'with' keyword

This commit is contained in:
SomberNight
2017-11-12 14:33:46 +01:00
parent 8fcf1656d3
commit c65d01ea96
8 changed files with 22 additions and 20 deletions

View File

@@ -23,7 +23,8 @@ crowdin_api_key = None
filename = '~/.crowdin_api_key'
if os.path.exists(filename):
crowdin_api_key = open(filename).read().strip()
with open(filename) as f:
crowdin_api_key = f.read().strip()
if "crowdin_api_key" in os.environ:
crowdin_api_key = os.environ["crowdin_api_key"]
@@ -32,8 +33,9 @@ if crowdin_api_key:
# Push to Crowdin
print('Push to Crowdin')
url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
files = {crowdin_file_name: open(locale_file_name,'rb')}
requests.request('POST', url, files=files)
with open(locale_file_name,'rb') as f:
files = {crowdin_file_name: f}
requests.request('POST', url, files=files)
# Build translations
print('Build translations')
response = requests.request('GET', 'https://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key).content
@@ -52,9 +54,8 @@ for name in zfobj.namelist():
if not os.path.exists(name[16:]):
os.mkdir(name[16:])
else:
output = open(name[16:], 'wb')
output.write(zfobj.read(name))
output.close()
with open(name[16:], 'wb') as output:
output.write(zfobj.read(name))
# Convert .po to .mo
print('Installing')