Skip to content

Commit

Permalink
Fixed rhbz826821, glossary-push failed on big compendium po file
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesni committed Jun 29, 2012
1 parent 4e298c9 commit db2c517
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
14 changes: 11 additions & 3 deletions zanataclient/publicanutil.py
Expand Up @@ -313,17 +313,20 @@ def pofile_to_json(self, filepath):
def glossary_to_json(self, filepath, lang, sourcecomments):
pofile = self.create_pofile(filepath)
entries = []
jsons = []
targetlocales = []
targetlocales.append(lang)
srclocales = []
srclocales.append('en-US')
i = 0

for item in pofile:
while i < len(pofile):
entry= {'srcLang':'en-US','glossaryTerms':'', 'sourcereference':''}
target_comments=[]
source_comments=[]
comments=''
reflist = []
item = pofile[i]
references = item.occurrences

for ref in references:
Expand All @@ -346,9 +349,14 @@ def glossary_to_json(self, filepath, lang, sourcecomments):
entry['glossaryTerms'] = terms
entries.append(entry)

glossary = {'sourceLocales':srclocales, 'glossaryEntries':entries, 'targetLocales':targetlocales}
if len(entries) == 300 or i == len(pofile)-1:
glossary = {'sourceLocales':srclocales, 'glossaryEntries':entries, 'targetLocales':targetlocales}
jsons.append(json.dumps(glossary))
entries = []

return json.dumps(glossary)
i+=1

return jsons

def save_to_pofile(self, path, translations, pot, create_skeletons, locale, doc_name):
"""
Expand Down
36 changes: 25 additions & 11 deletions zanataclient/zanatacmd.py
Expand Up @@ -506,20 +506,34 @@ def pull_command(self, locale_map, project_id, iteration_id, filelist, lang_list


def poglossary_push(self, path, url, username, apikey, lang, sourcecomments):
i = 0
jsons = []
publicanutil = PublicanUtility()
json = publicanutil.glossary_to_json(path, lang, sourcecomments)
jsons = 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 glossary to the server")
except UnavailableServiceError:
self.log.error("Service Temporarily Unavailable, stop processing!")
except ZanataException, e:
self.log.error(str(e))
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 UnAvaliableResourceException:
self.log.error("Can not push glossary to the server")
sys.exit(1)
except UnavailableServiceError:
self.log.error("Service Temporarily Unavailable, stop processing!")
sys.exit(1)
except ZanataException, e:
self.log.error(str(e))
sys.exit(1)

i+=1

self.log.info("Successfully pushed glossary to the server")

def csvglossary_push(self, path, url, username, apikey, locale_map, comments_header):
csvconverter = CSVConverter()
Expand Down

0 comments on commit db2c517

Please sign in to comment.