author Nicolas Chauvat <>
Mon, 23 Jun 2008 13:42:22 +0200
changeset 6 6aad8b499e86
parent 0 7710b138d4eb
permissions -rw-r--r--
fix reST markup

# Copyright (c) 2004 LOGILAB S.A. (Paris, FRANCE).
# --
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""Basic plugin for some debian files, using standard debian command line tools

FIXME: add dput support

__revision__ = '$Id:,v 1.7 2004-10-13 09:37:28 adim Exp $'

import os
import commands

import gobject

from oobrother.plugins import AbstractPlugIn
from import ConfigurableListWindow
from oobrother.config_tools import PluggableConfig, ConfigurableNode
debsign_options = (
    ('gpg-key-id', {'type': 'string',
                    'default':os.environ.get('GPGKEYID', '')}),

class DebianPlugin(AbstractPlugIn):
    """a plugin for text file, propo"""
    name = 'debian'
    mimetypes = ('application/x-debian-package',
    def __init__(self):
        AbstractPlugIn.__init__(self, config_file='debian.ini')
        self.lintian_window = LintianReportWindow()
        plug = PluggableConfig('options', 'debsign.ini', debsign_options)
        self.debsign_conf = ConfigurableNode('debsign', plug)
    def get_actions(self, thefile):
        """return actions provided by this plugin for the give file"""
        actions = []
        if thefile.basename.endswith('.changes'):
            actions.append( ('show content', self.cb_debc) )
            actions.append( ('sign', self.cb_debsign) )
            actions.append( ('lintian', self.cb_lintian) )
        return actions

    def cb_lintian(self, menuitem, thefile):
        """execute lintian"""
    def cb_debc(self, menuitem, thefile):
        """execute debc"""
        self.execute_in_console('debc %s' % thefile.abspath)        
    def cb_debsign(self, menuitem, thefile):
        """execute debsign"""
        keyid = self.debsign_conf.cfg['gpg-key-id']
        self.execute_in_console('debsign -k %s %s' % (keyid, thefile.abspath))

    def subconfiguration(self):
        """return subconfiguration objects if any"""
        return [self.lintian_window, self.debsign_conf]

class LintianReportWindow(ConfigurableListWindow):
    """display lintian report in a 3 columns list (configurable)"""
    name = 'lintian'
    options = (
        ('all-checks', {'type': 'yn', 'default': True}),
        # FIXME: use a multiple choice using lintian existing checks (anyway
        # to get them dynamically ?)
        ('checks', {'type': 'csv', 'default': ()}),
    def __init__(self):
        ConfigurableListWindow.__init__(self, 'lintian.ini',
                                        (gobject.TYPE_STRING, # type
                                         gobject.TYPE_STRING, # path
                                         gobject.TYPE_STRING, # message
                                        ('Type', 'Package', 'Message'),
        self.init_columns(self.cfg['columns'], (0, 0, 0))
    def lintian(self, thefile):
        """check the given wrapped package using checkpackage in a safe
        cmd = 'lintian'
        if not self.cfg['all-checks']:
            cmd = 'lintian %s' % ','.join(self.cfg['checks'])
        self.set_title('lintian: %s' % thefile.abspath)
        output = commands.getoutput("%s %s" % (cmd, thefile.abspath))
        for line in output.splitlines():
            self.append_line( line.split(':', 2) )

def register(registry):
    """register plugins from this module to the plugins registry"""