def translations(output=('o', 'human', "Output format e.g. json"), **kwargs): '''List translations from current project''' repo = Repository() username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() translations = GLTranslations( GLProject(repo.get_project_name(), username, password)) try: trlist = translations.list() if output == 'json': print simplejson.dumps(trlist) else: for tr in trlist: progress = str(int(round(float(tr.get('progress'))))) + "%" print "#\t%s [%s] %s" % (tr.get('master_file'), tr.get('iana_code'), progress) except: print "# Project is empty"
def push_translations(repo, username, password): # Push translations that don't exist translations = GLTranslations(GLProject(repo.get_project_name(), username, password)) try: trlist = translations.list() except: pass locale_map = repo.get_locale_map() for locale in locale_map: tr_file = repo.parse_locale(locale[0]) local_file = locale[1] found = False for tr in trlist: if tr.get('master_file') == tr_file[0] and tr.get('iana_code') == tr_file[1]: found = True if not found: try: translations.update_translation_file(local_file, tr_file[0], tr_file[1]) except: #traceback.print_exc() print "# Updating file '" + local_file + "' failed" else: print "#" print "# File already exists on server-side, use --force to force push it" print "#"
def push_translations(repo, username, password): # Push translations that don't exist translations = GLTranslations( GLProject(repo.get_project_name(), username, password)) try: trlist = translations.list() except: pass locale_map = repo.get_locale_map() for locale in locale_map: tr_file = repo.parse_locale(locale[0]) local_file = locale[1] found = False for tr in trlist: if tr.get('master_file') == tr_file[0] and tr.get( 'iana_code') == tr_file[1]: found = True if not found: try: translations.update_translation_file(local_file, tr_file[0], tr_file[1]) except: #traceback.print_exc() print "# Updating file '" + local_file + "' failed" else: print "#" print "# File already exists on server-side, use --force to force push it" print "#"
def map_master(oldFile, newFile, **kwargs): '''Map existing master file on server to new a location on your local repository. This also changes the filename on server-side to match your local directory structure.''' repo = Repository() username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() mf = GLMasterFile(GLProject(repo.get_project_name(), username, password), repo.relative_to_root(oldFile), repo.relative_path(repo.file_path(oldFile)), None) if not mf.isAvailableRemotely(): print "Error: File " + oldFile + " is not available on the server." return try: if repo.rename_master_file(oldFile, newFile): mf.rename(newFile, repo.relative_path(repo.file_path(newFile))) repo.commit( ) # Commit the rename to local repo after successful request to server translations = GLTranslations( GLProject(repo.get_project_name(), username, password)) trlist = translations.list() repo.save_status(trlist) print "Successfully mapped master %s => %s" % (oldFile, newFile) else: print "Error when mapping master file." except EnvironmentError as err: print err
def map_master(oldFile, newFile, **kwargs): '''Map existing master file on server to new a location on your local repository. This also changes the filename on server-side to match your local directory structure.''' repo = Repository() username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() mf = GLMasterFile(GLProject(repo.get_project_name(), username, password), repo.relative_to_root(oldFile), repo.relative_path(repo.file_path(oldFile)), None) if not mf.isAvailableRemotely(): print "Error: File " + oldFile + " is not available on the server." return try: if repo.rename_master_file(oldFile, newFile): mf.rename(newFile, repo.relative_path(repo.file_path(newFile))) repo.commit() # Commit the rename to local repo after successful request to server translations = GLTranslations(GLProject(repo.get_project_name(), username, password)) trlist = translations.list() repo.save_status(trlist) print "Successfully mapped master %s => %s" % (oldFile, newFile) else: print "Error when mapping master file." except EnvironmentError as err: print err
def pull(**kwargs): '''Pull available translations from server''' repo = Repository() username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() exitVal = 0 try: translations = GLTranslations( GLProject(repo.get_project_name(), username, password)) trlist = translations.list() repo.save_status(trlist) print "#" for tr in trlist: local_file = repo.get_mapped_locale(tr.get('master_file'), tr.get('iana_code')) if local_file is None: print "# Warning: Skipping file %s (%s). Map local file first\n# e.g. with command: gl map-locale %s %s %s.\n# You can also force download files \ to their default locations with parameter --force" % ( tr.get('master_file'), tr.get('iana_code'), tr.get('master_file'), tr.get('iana_code'), tr.get('filename')) print "#" continue translations.save_translation_file( tr.get('master_file'), tr.get('iana_code'), repo.relative_to_root(local_file)) print "# Translation file %s updated" % local_file print "#" except: print traceback.format_exc() print "#" print "# Project is empty" print "#" exitVal = 1 sys.exit(exitVal)
def pull(**kwargs): '''Pull available translations from server''' repo = Repository(); username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() exitVal = 0 try: translations = GLTranslations(GLProject(repo.get_project_name(), username, password)) trlist = translations.list() repo.save_status(trlist) print "#" for tr in trlist: local_file = repo.get_mapped_locale(tr.get('master_file'), tr.get('iana_code')) if local_file is None: print "# Warning: Skipping file %s (%s). Map local file first\n# e.g. with command: gl map-locale %s %s %s.\n# You can also force download files \ to their default locations with parameter --force" % (tr.get('master_file'), tr.get('iana_code'), tr.get('master_file'), tr.get('iana_code'), tr.get('filename')) print "#" continue translations.save_translation_file(tr.get('master_file'), tr.get('iana_code'), repo.relative_to_root(local_file)) print "# Translation file %s updated" % local_file print "#" except: print traceback.format_exc() print "#" print "# Project is empty" print "#" exitVal = 1 sys.exit(exitVal)
def translations(output=('o', 'human', "Output format e.g. json"), **kwargs): '''List translations from current project''' repo = Repository(); username = kwargs.get('username') password = kwargs.get('password') if username == '' or password == '': username, password = prompt_userpw() translations = GLTranslations(GLProject(repo.get_project_name(), username, password)) try: trlist = translations.list() if output == 'json': print simplejson.dumps(trlist) else: for tr in trlist: progress = str(int(round(float(tr.get('progress'))))) + "%" print "#\t%s [%s] %s" % (tr.get('master_file'), tr.get('iana_code'), progress) except: print "# Project is empty"