Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 def checkout (self):
     """
     Check out or clone the repository from the server.
     """
     cmd = self.get_checkout_command ()
     if cmd is None:
         raise NotImplementedError ('%s does not implement the checkout method.'
                                    % self.__class__.__name__)
     utils.log ('Checking out %s (%s) from %s'
                % (self.scm_module, self.scm_branch, self.server_dir))
     topdir = os.path.join (config.scm_dir, self.server_dir, self.module_dir)
     if not os.path.exists (topdir):
         os.makedirs (topdir)
     owd = os.getcwd ()
     try:
         os.chdir (topdir)
         (status, output) = commands.getstatusoutput (cmd)
         if status != 0:
             utils.warn (
                 'Failed to check out %s (%s) from %s with command\n                      %s'
                 % (self.scm_module, self.scm_branch, self.server_dir, cmd))
             self.error = output.split('\n')[-1]
     finally:
         os.chdir (owd)
Exemplo n.º 3
0
    def process_file (self, dirname, basename, **kw):
        """
        Process an OAF server file for a panel applet.
        """
        if not re.match('.*\.server(\.in)+$', basename):
            return
        filename = os.path.join (dirname, basename)
        branch = self.scanner.branch
        checkout = self.scanner.checkout
        bserver, bmodule, bbranch = branch.ident.split('/')[2:]

        rel_ch = utils.relative_path (filename, checkout.directory)
        rel_scm = utils.relative_path (filename, config.scm_dir)
        mtime = os.stat(filename).st_mtime

        if not kw.get('no_timestamps', False):
            stamp = db.Timestamp.get_timestamp (rel_scm)
            if mtime <= stamp:
                utils.log ('Skipping file %s' % rel_scm)
                data = {'parent' : branch}
                data['scm_dir'], data['scm_file'] = os.path.split (rel_ch)
                applets = db.Branch.select (type=u'Applet', **data)
                for applet in applets:
                    self.scanner.add_child (applet)
                return
        utils.log ('Processing file %s' % rel_scm)

        owd = os.getcwd ()
        try:
            os.chdir (checkout.directory)
            dom = xml.dom.minidom.parse (
                os.popen ('LC_ALL=C intltool-merge -x -q -u po "' + rel_ch + '" - 2>/dev/null'))
        except:
            utils.warn ('Could not process file %s' %
                        utils.relative_path (filename, config.scm_dir))
            os.chdir (owd)
            return
        os.chdir (owd)
        for server in dom.getElementsByTagName ('oaf_server'):
            is_applet = False
            applet_name = {}
            applet_desc = {}
            applet_icon = None
            applet_iid = server.getAttribute ('iid')
            if applet_iid == '':
                continue
            if applet_iid.startswith ('OAFIID:'):
                applet_iid = applet_iid[7:]
            if applet_iid.startswith ('GNOME_'):
                applet_iid = applet_iid[6:]
            for oafattr in server.childNodes:
                if oafattr.nodeType != oafattr.ELEMENT_NODE or oafattr.tagName != 'oaf_attribute':
                    continue
                if oafattr.getAttribute ('name') == 'repo_ids':
                    for item in oafattr.childNodes:
                        if item.nodeType != item.ELEMENT_NODE or item.tagName != 'item':
                            continue
                        if item.getAttribute ('value') == 'IDL:GNOME/Vertigo/PanelAppletShell:1.0':
                            is_applet = True
                            break
                    if not is_applet:
                        break
                if oafattr.getAttribute ('name') == 'name':
                    lang = oafattr.getAttribute ('xml:lang')
                    if lang == '':
                        lang = 'C'
                    value = oafattr.getAttribute ('value')
                    if value != '':
                        applet_name[lang] = value
                if oafattr.getAttribute ('name') == 'description':
                    lang = oafattr.getAttribute ('xml:lang')
                    if lang == '':
                        lang = 'C'
                    value = oafattr.getAttribute ('value')
                    if value != '':
                        applet_desc[lang] = value
                if oafattr.getAttribute ('name') == 'panel:icon':
                    applet_icon = oafattr.getAttribute ('value')
                    if applet_icon == '':
                        applet_icon = None
            if not is_applet or applet_icon == None:
                continue
            ident = '/'.join(['/applet', bserver, bmodule, applet_iid, bbranch])
            applet = db.Branch.get_or_create (ident, u'Applet')
            applet.update (name=applet_name, desc=applet_desc)
            if applet_icon != None:
                self.appleticons.append ((applet, applet_icon))

            data = {}
            for key in ('scm_type', 'scm_server', 'scm_module', 'scm_branch', 'scm_path'):
                data[key] = getattr(branch, key)
            data['scm_dir'], data['scm_file'] = os.path.split (rel_ch)
            applet.update (data)
            self.scanner.add_child (applet)

        db.Timestamp.set_timestamp (rel_scm, mtime)
Exemplo n.º 4
0
    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