Transifex pull: made script more kind when networks fails

This commit is contained in:
Federico Fissore 2015-06-30 14:21:55 +02:00
parent a414fdee77
commit d5253e1690
1 changed files with 20 additions and 6 deletions

View File

@ -2,11 +2,11 @@
#vim:set fileencoding=utf-8 sw=2 expandtab
from transifex import Transifex
import requests
import getpass
import sys
def main():
import getpass
import sys
print 'Use your account to talk with Transifex.'
user = raw_input('Username: ')
passwd = getpass.getpass('Password: ')
@ -14,18 +14,32 @@ def main():
for lang in sys.argv[1:]:
fname = 'Resources_%s.po' % lang
print "Updating %s from Transifex..." % fname,
sys.stdout.flush()
try:
lang = trans.canonical_lang(lang)
trans.pull(lang, fname)
pull(trans, lang, fname)
except RuntimeError, e:
print e.message
continue
except IOError, e:
print e.strerror
continue
print
def pull(trans, lang, fname):
count = 0
print "Updating %s from Transifex...\n" % fname,
sys.stdout.flush()
while count < 5:
count += 1
try:
trans.pull(lang, fname)
return
except requests.exceptions.HTTPError, e:
print " *** Retrying %s from Transifex...\n" % fname,
sys.stdout.flush()
if count >= 5:
raise Exception("Too many retries")
if __name__ == '__main__':
main()