'Run xgettext for project sources'

def run(self):

    prj_name = self.distribution.get_name()
    if (self.build_dir != u'.'):
        fullname = os.path.join(self.build_dir, self.output)
    else:
        fullname = self.output
    log.info((u'Generate    POT    file:    ' + fullname))
    if (not os.path.isdir(self.build_dir)):
        log.info((u'Make    directory:    ' + self.build_dir))
        os.makedirs(self.build_dir)
    self.spawn((([u'xgettext', u'--keyword=N_', u'-p', self.build_dir, u'-o', self.output] + glob.glob(u'cola/*.py')) + glob.glob(u'cola/*/*.py')))
    self._force_LF(fullname)
    if self.english:
        log.info(u'Regenerating    English    PO    file...')
        if prj_name:
            en_po = ((prj_name + u'-') + u'en.po')
        else:
            en_po = u'en.po'
        self.spawn([u'msginit', u'--no-translator', u'-l', u'en', u'-i', os.path.join(self.build_dir, self.output), u'-o', os.path.join(self.build_dir, en_po)])
    if self.no_lang:
        return
    for po in glob.glob(os.path.join(self.build_dir, u'*.po')):
        if (self.lang is not None):
            po_lang = os.path.splitext(os.path.basename(po))[0]
            if (prj_name and po_lang.startswith((prj_name + u'-'))):
                po_lang = po_lang[5:]
            if (po_lang not in self.lang):
                continue
        new_po = (po + u'.new')
        cmd = (u'msgmerge    %s    %s    -o    %s' % (po, fullname, new_po))
        self.spawn(cmd.split())
        log.info((u'%s    -->    %s' % (new_po, po)))
        self._force_LF(new_po, po)
        os.unlink(new_po)
