def push_command(self, file_list, srcfolder, project_id, iteration_id, copytrans, plural_support = False, import_param = None): """ Push the content of publican files to a Project version on Zanata server @param args: name of the publican file """ publicanutil = PublicanUtility() for filepath in file_list: self.log.info("\nPushing the content of %s to server:"%filepath) plural_exist = publicanutil.check_plural(filepath) if plural_exist and not plural_support: self.log.error("The plural is only supported in zanata server >= 1.6, this file will be ignored") break body, filename = publicanutil.potfile_to_json(filepath, srcfolder) try: result = self.update_template(project_id, iteration_id, filename, body, copytrans) if result: self.log.info("Successfully pushed %s to the server"%filepath) except UnAuthorizedException, e: self.log.error(str(e)) break except BadRequestBodyException, e: self.log.error(str(e)) continue
def push_command(self, file_list, srcfolder, project_id, iteration_id, copytrans, plural_support=False, import_param=None): """ Push the content of publican files to a Project version on Zanata server @param args: name of the publican file """ publicanutil = PublicanUtility() for filepath in file_list: self.log.info("\nPushing the content of %s to server:" % filepath) plural_exist = publicanutil.check_plural(filepath) if plural_exist and not plural_support: self.log.error( "The plural is only supported in zanata server >= 1.6, this file will be ignored" ) break body, filename = publicanutil.potfile_to_json(filepath, srcfolder) try: result = self.update_template(project_id, iteration_id, filename, body, copytrans) if result: self.log.info("Successfully pushed %s to the server" % filepath) except UnAuthorizedException, e: self.log.error(str(e)) break except BadRequestBodyException, e: self.log.error(str(e)) continue
def import_po(self, potfile, trans_folder, project_id, iteration_id, lang_list, locale_map, merge, project_type): sub_dir = "" publicanutil = PublicanUtility() for item in lang_list: if not locale_map: lang = item else: if item in locale_map: lang = locale_map[item] else: lang = item if '/' in potfile: request_name = potfile.replace('/', ',') sub_dir = potfile[0:potfile.rfind('/')] else: request_name = potfile self.log.info("Pushing %s translation for %s to server:" % (item, potfile)) if project_type == "podir": folder = os.path.join(trans_folder, item) if not os.path.isdir(folder): self.log.error( "Can not find translation, please specify path of the translation folder" ) continue pofile = os.path.join(folder, potfile + '.po') elif project_type == "gettext": filename = item.replace('-', '_') + '.po' if sub_dir: path = os.path.join(trans_folder, sub_dir) else: path = trans_folder pofile = os.path.join(path, filename) if not os.path.isfile(pofile): self.log.error("Can not find the %s translation for %s" % (item, potfile)) continue body = publicanutil.pofile_to_json(pofile) if not body: self.log.error("No content or all entries are obsolete in %s" % pofile) sys.exit(1) self.commit_translation(project_id, iteration_id, request_name, pofile, lang, body, merge)
def import_po(self, zanata, potfile, trans_folder, project_id, iteration_id, lang_list, locale_map, merge, project_type): sub_dir = "" publicanutil = PublicanUtility() for item in lang_list: if not locale_map: lang = item else: if item in locale_map: lang = locale_map[item] else: lang = item if '/' in potfile: request_name = potfile.replace('/', ',') sub_dir = potfile.split('/')[0] else: request_name = potfile if project_type == "publican": folder = os.path.join(trans_folder, item) if not os.path.isdir(folder): self.log.error("Can not find translation, please specify path of the translation folder") continue pofile = os.path.join(folder, potfile+'.po') elif project_type == "software": folder = os.path.join(trans_folder, 'po') filename = item.replace('-','_')+'.po' if sub_dir: path = os.path.join(folder, sub_dir) else: path = folder pofile = os.path.join(path, filename) if not os.path.isfile(pofile): self.log.error("Can not find the %s translation for %s"%(item, potfile)) continue self.log.info("Pushing %s translation for %s to server:"%(item, potfile)) body = publicanutil.pofile_to_json(pofile) if not body: self.log.error("No content or all entries are obsolete in %s"%pofile) sys.exit(1) self.commit_translation(zanata, project_id, iteration_id, request_name, pofile, lang, body, merge)
def poglossary_push(self, path, url, username, apikey, lang, sourcecomments): publicanutil = PublicanUtility() json = publicanutil.glossary_to_json(path, lang, sourcecomments) glossary = GlossaryService(url) try: content = glossary.commit_glossary(username, apikey, json) if content: self.log.info("Successfully pushed glossary to the server") except UnAvaliableResourceException: self.log.error("Can not push") except UnavailableServiceError: self.log.error("Service Temporarily Unavailable, stop processing!") except BadRequestBodyException, e: self.log.error(e.msg)
def pull_command(self, locale_map, project_id, iteration_id, filelist, lang_list, output, project_type, skeletons): """ Retrieve the content of documents in a Project version from Zanata server. If the name of publican file is specified, the content of that file will be pulled from server. Otherwise, all the document of that Project iteration will be pulled from server. @param args: the name of publican file """ publicanutil = PublicanUtility() # if file no specified, retrieve all the files of project for file_item in filelist: pot = "" result = "" folder = "" if '/' in file_item: name = file_item.split('/')[-1] folder = file_item[0:file_item.rfind('/')] request_name = file_item.replace('/', ',') else: name = file_item request_name = file_item self.log.info("\nFetching the content of %s from Zanata server: " % name) try: pot = self.zanata_resource.documents.retrieve_template( project_id, iteration_id, request_name) except UnAuthorizedException, e: self.log.error(str(e)) break except UnAvaliableResourceException, e: self.log.error("Can't find pot file for %s on server" % name) break
def poglossary_push(self, path, lang, sourcecomments): i = 0 jsons = [] publicanutil = PublicanUtility() jsons = publicanutil.glossary_to_json(path, lang, sourcecomments) size = len(jsons) if size > 1: self.log.warn("The file is big, try to divide it to small parts. It may take a long time to push!") while i < size: if size > 1: self.log.info("Push part %s of glossary file" % i) try: self.zanata_resource.glossary.commit_glossary(jsons[i]) except ZanataException, e: self.log.error(str(e)) sys.exit(1) i += 1
def push_trans_command(self, transfolder, project_id, iteration_id, lang_list, locale_map, project_type, merge): filelist = "" folder = "" publicanutil = PublicanUtility() try: filelist = self.zanata_resource.documents.get_file_list( project_id, iteration_id) except ZanataException, e: self.log.error(str(e))
def push_command(self, zanata, file_list, srcfolder, project_id, iteration_id, copytrans, import_param = None): """ Push the content of publican files to a Project version on Zanata server @param args: name of the publican file """ publicanutil = PublicanUtility() for filepath in file_list: self.log.info("\nPushing the content of %s to server:"%filepath) body, filename = publicanutil.potfile_to_json(filepath, srcfolder) try: result = zanata.documents.commit_template(project_id, iteration_id, body, copytrans) if result: self.log.info("Successfully pushed %s to the server"%filepath) except UnAuthorizedException, e: self.log.error(e.msg) break except BadRequestBodyException, e: self.log.error(e.msg) continue
def push_trans_command(self, zanata, transfolder, project_id, iteration_id, lang_list, locale_map, project_type, merge): publicanutil = PublicanUtility() for item in lang_list: if not locale_map: lang = item else: if item in locale_map: lang = locale_map[item] else: lang = item self.log.info("\nPushing %s translation for %s to server:"%(item, project_id)) if project_type == "podir": folder = os.path.join(transfolder, item) if not os.path.isdir(folder): self.log.error("Can not find translation, please specify path of the translation folder") continue filelist = publicanutil.get_file_list(folder, ".po") for filepath in filelist: self.log.info("\nPushing the content of %s to server:"%filepath) filename = publicanutil.strip_path(filepath, folder, '.po') if '/' in filename: request_name = filename.replace('/', ',') else: request_name = filename body = publicanutil.pofile_to_json(filepath) if not body: self.log.error("No content or all entries are obsolete in %s"%filepath) sys.exit(1) self.commit_translation(zanata, project_id, iteration_id, request_name, filepath, lang, body, merge)
def poglossary_push(self, path, url, username, apikey, lang, sourcecomments): i = 0 jsons = [] publicanutil = PublicanUtility() jsons = publicanutil.glossary_to_json(path, lang, sourcecomments) glossary = GlossaryService(url) size = len(jsons) if size > 1: self.log.warn( "The file is big, try to devide it to small parts. It may take a long time to push!" ) while i < size: if size > 1: self.log.info("Push part %s of glossary file" % i) try: glossary.commit_glossary(username, apikey, jsons[i]) except ZanataException, e: self.log.error(str(e)) sys.exit(1) i += 1
import_param['locale_map'] = None importpo = True else: log.info("Importing source documents only") if args: try: full_path = search_file(tmlfolder, args[0]) filelist.append(full_path) except NoSuchFileException, e: log.error(e.msg) sys.exit(1) else: if not command_options.has_key('srcfile'): #get all the pot files from the template folder publicanutil = PublicanUtility() filelist = publicanutil.get_file_list(tmlfolder, ".pot") if not filelist: log.error("The template folder is empty") sys.exit(1) if command_options.has_key('force'): force = True zanatacmd.del_server_content(zanata, tmlfolder, project_id, iteration_id, filelist, force, "gettext") if importpo: zanatacmd.push_command(zanata, filelist, tmlfolder, project_id, iteration_id, copytrans, plural_support, import_param) else: zanatacmd.push_command(zanata, filelist, tmlfolder, project_id, iteration_id, copytrans, plural_support)
"srcfile option is not used for podir type project, ignored" ) if tmlfolder == "": tmlfolder = self.process_srcdir_withsub(self.command_options) if self.args: try: full_path = self.search_file(tmlfolder, self.args[0]) filelist.append(full_path) except NoSuchFileException, e: log.error(e.msg) sys.exit(1) else: #get all the pot files from the template folder publicanutil = PublicanUtility() filelist = publicanutil.get_file_list(tmlfolder, ".pot") if not filelist: log.error("The template folder is empty") sys.exit(1) deletefiles = True return project_type, deletefiles, tmlfolder, filelist def read_project_config(self, command_options): project_config = {} config = ZanataConfig() #Read the project configuration file using --project-config option config_file = [os.path.join(os.getcwd(), filename) for filename\ in ['zanata.xml', 'flies.xml']]