def update_translation (self, **kw): """ Update information about an intltool-managed translation. """ translation = self.scanner.translation checkout = self.scanner.checkout if translation.subtype != 'evolution-quickref': return False filepath = os.path.join (checkout.directory, translation.scm_dir, translation.scm_file) if not os.path.exists (filepath): utils.warn('Could not locate file %s for %s' % (translation.scm_file, translation.parent.ident)) return False files = [os.path.join (translation.parent.scm_dir, translation.parent.scm_file)] origrev = db.Revision.get_last_revision (branch=translation.parent.parent, files=files) files = [os.path.join (translation.scm_dir, translation.scm_file)] thisrev = db.Revision.get_last_revision (branch=translation.parent.parent, files=files) if thisrev is None or origrev is None: return # XXX just a workaround, FIX ME! if thisrev.datetime > origrev.datetime: db.Statistic.set_statistic (translation, utils.daynum(), u'Messages', 1, 0, 1) else: db.Statistic.set_statistic (translation, utils.daynum(), u'Messages', 0, 0, 1) db.Statistic.set_statistic (translation, utils.daynum(), u'ImageMessages', 0, 0, 0) return True
def update_translation (self, **kw): """ Update information about an intltool-managed translation. """ translation = self.scanner.translation checkout = self.scanner.checkout if translation.subtype != 'intltool': return False potfile = self.get_potfile (**kw) if potfile is None: return False filepath = os.path.join (checkout.directory, translation.scm_dir, translation.scm_file) if not os.path.exists (filepath): utils.warn('Could not locate file %s for %s' % (translation.scm_file, translation.parent.ident)) return False rel_scm = utils.relative_path (filepath, config.scm_dir) mtime = os.stat(filepath).st_mtime if not kw.get('no_timestamps', False): stamp = db.Timestamp.get_timestamp (rel_scm) if mtime <= stamp: pomd5 = translation.data.get('md5', None) potmd5 = potfile.data.get('md5', None) if pomd5 != None and pomd5 == potmd5: utils.log ('Skipping file %s' % rel_scm) return True podir = os.path.join (checkout.directory, translation.scm_dir) cmd = 'msgmerge "%s" "%s" 2>&1' % (translation.scm_file, potfile.get_file_path()) owd = os.getcwd () try: os.chdir (podir) pulse.utils.log ('Processing file ' + rel_scm) popo = parsers.Po (os.popen (cmd)) stats = popo.get_stats() total = stats[0] + stats[1] + stats[2] db.Statistic.set_statistic (translation, utils.daynum(), u'Messages', stats[0], stats[1], total) finally: os.chdir (owd) # FIXME: things like .desktop files might not be reprocessed because # they haven't changed, but translators might have updated the name # or description. Rather than trying to make those things run when # po files have been updated, let's just grab these: # po.parent.parent.select_children (...) # for Application, Capplet, Applet, and Library and see if we can # provide an updated name or description. of = db.OutputFile.select (type=u'l10n', ident=translation.parent.ident, filename=translation.scm_file) try: of = of[0] except IndexError: of = db.OutputFile (type=u'l10n', ident=translation.parent.ident, filename=translation.scm_file, datetime=datetime.datetime.utcnow()) outfile_abs = of.get_file_path() outfile_rel = pulse.utils.relative_path (outfile_abs, config.web_l10n_dir) outdir = os.path.dirname (outfile_abs) if not os.path.exists (outdir): os.makedirs (outdir) utils.log ('Copying PO file %s' % outfile_rel) shutil.copyfile (os.path.join (checkout.directory, translation.scm_dir, translation.scm_file), os.path.join (outdir, translation.scm_file)) of.datetime = datetime.datetime.utcnow() of.data['revision'] = checkout.get_revision() files = [os.path.join (translation.scm_dir, translation.scm_file)] revision = db.Revision.get_last_revision (branch=translation.parent.parent, files=files) if revision != None: translation.mod_datetime = revision.datetime translation.mod_person = revision.person translation.data['md5'] = potfile.data.get('md5', None) db.Timestamp.set_timestamp (rel_scm, mtime) return True