def setup_file_and_db(self, file_contents=fr_terminology_extract): cache = statsdb.StatsCache(os.path.join(self.path, "stats.db")) filename = os.path.join(self.path, "test.po") with open(filename, "w") as fh: fh.write(file_contents) f = factory.getobject(filename) return f, cache
def makeReport(): out = StringIO() out.write( '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n' '<HTML><HEAD>\n' '<META NAME="generator" CONTENT="postatus.py">\n' '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n' '<TITLE>po file status - {date}</TITLE>\n' '</HEAD><BODY>\n' '<H1>po file status - {date}</H1>\n') stats = statsdb.StatsCache() webPoFiles = listWebPoFiles() for lang in listLangs(): out.write( '<br/><H2>{lang}</H2><br/>\n' '<table><tr><th>Filename</th><th>Percentage translated</th><th>Total number of messages</th></tr>\n' .format(lang=lang)) for po in listPoFiles(lang, webPoFiles): path = os.path.join(SRT_ROOT, po) totals = stats.filetotals(path) total = totals["total"] if total: transPercent = totals["translated"] / float( totals["total"]) * 100 else: transPercent = 0.0 out.write( "<tr><td>{po}</td><td>{transPercent:.2f}%</td><td>{total}</td></tr>\n" .format(po=po.replace("/", "/"), transPercent=transPercent, total=totals["total"])) out.write('</table>\n') out.write('</BODY></HTML>\n') return out.getvalue()
def update_file(self, filename): # Adapted from Document.__init__() from translate.storage import factory, statsdb newstore = factory.getobject(filename) oldfilename = self._trans_store.filename oldfileobj = self._trans_store.fileobj #get a copy of old stats before we convert from translate.filters import checks oldstats = statsdb.StatsCache().filestats(oldfilename, checks.UnitChecker(), self._trans_store) from translate.convert import pot2po self._trans_store = pot2po.convert_stores(newstore, self._trans_store, fuzzymatching=False) self._trans_store.fileobj = oldfileobj #Let's attempt to keep the old file and name if possible #FIXME: ugly tempfile hack, can we please have a pure store implementation of statsdb import tempfile import os tempfd, tempfilename = tempfile.mkstemp() os.write(tempfd, str(self._trans_store)) self.update_stats(filename=tempfilename) os.close(tempfd) os.remove(tempfilename) self.controller.compare_stats(oldstats, self.stats) # store filename or else save is confused self._trans_store.filename = oldfilename self._correct_header(self._trans_store) self.nplurals = self._compute_nplurals(self._trans_store)
def get_stats_totals(self): """Return totals for word and string counts.""" if not self.filename: return {} from translate.storage import statsdb totals = statsdb.StatsCache().file_extended_totals(self.filename, self._trans_store) return totals
def update_stats(self, filename=None): self.stats = None if self._trans_store is None: return if filename is None: filename = self.filename from translate.storage import statsdb stats = statsdb.StatsCache().filestatestats(filename, self._trans_store, extended=True) self._valid_units = stats['total'] self.stats = fix_indexes(stats) return self.stats
def test_quickstats(self): statscache = statsdb.StatsCache() dbstats = self.store.getquickstats() filestats = statscache.filetotals(self.store.file.path) self.assertEqual(dbstats['total'], filestats['total']) self.assertEqual(dbstats['totalsourcewords'], filestats['totalsourcewords']) self.assertEqual(dbstats['untranslated'], filestats['untranslated']) self.assertEqual(dbstats['untranslatedsourcewords'], filestats['untranslatedsourcewords']) self.assertEqual(dbstats['fuzzy'], filestats['fuzzy']) self.assertEqual(dbstats['fuzzysourcewords'], filestats['fuzzysourcewords']) self.assertEqual(dbstats['translated'], filestats['translated']) self.assertEqual(dbstats['translatedsourcewords'], filestats['translatedsourcewords']) self.assertEqual(dbstats['translatedtargetwords'], filestats['translatedtargetwords'])
def update_checks(self, checker=None, filename=None): self.checks = None if self._trans_store is None: return if filename is None: filename = self.filename if checker is None: checker = self._checker else: self._checker = checker from translate.storage import statsdb errors = statsdb.StatsCache().filechecks(filename, checker, self._trans_store) self.checks = fix_indexes(errors, self._valid_units) return self.checks
def makeReport(): date = datetime.now().strftime("%Y-%b-%d %H:%M") out = StringIO() out.write(f"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META NAME="generator" CONTENT="postatus.py"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <TITLE>po file status - {date}</TITLE> </HEAD><BODY> <H1>po file status - {date}</H1> """) stats = statsdb.StatsCache() webPoFiles = listWebPoFiles() for lang in listLangs(): out.write( f'<br/><H2>{lang}</H2><br/>\n' '<table>\n' '<tr><th>Filename</th>' '<th>Percentage translated</th>' '<th>Total number of messages</th>' '</tr>\n' ) for po in listPoFiles(lang, webPoFiles): path = os.path.join(SRT_ROOT, po) try: totals = stats.filetotals(path) except Exception as e: sys.stderr.write(f"Unable to load {path}: {e}") raise e total = totals["total"] if total: transPercent = totals["translated"] / float(totals["total"]) * 100 else: transPercent = 0.0 out.write( f"<tr><td>{po.replace('/', '/')}</td>" f"<td>{transPercent:.2f}%</td>" f"<td>{totals['total']}</td>" f"</tr>\n" ) out.write('</table>\n') out.write('</BODY></HTML>\n') return out.getvalue()
def calcstats(filename): statscache = statsdb.StatsCache() return statscache.filetotals(filename, extended=True)