'Sign RPM with rpmsign.'

def AddSignatureToRPM(self, rpm_filename):

    args = [('--define=%%_gpg_name    %s' % self.gpg_name), ("--define=__gpg_sign_cmd    %%{__gpg}    gpg    --force-v3-sigs    --digest-algo=sha1    --batch    --no-verbose    --no-armor    --passphrase-fd    3    --no-secmem-warning    -u    '%s'    -sbo    %%{__signature_filename}    %%{__plaintext_filename}" % self.gpg_name), '--addsign', rpm_filename]
    try:
        output_log = cStringIO.StringIO()
        rpmsign = pexpect.spawn('rpmsign', args)
        rpmsign.logfile_read = output_log
        rpmsign.expect('Enter    pass    phrase:')
        rpmsign.sendline(self.password)
        rpmsign.wait()
    except pexpect.ExceptionPexpect:
        output_log.seek(0)
        logging.exception(output_log.read())
        raise
    try:
        output = subprocess.check_output(['rpm', '--checksig', rpm_filename])
        if ('pgp' not in output):
            raise SigningError(('PGP    missing    checksig    %s' % rpm_filename))
    except subprocess.CalledProcessError:
        logging.exception('Bad    signature    verification    on    %s', rpm_filename)
        raise SigningError(('Bad    signature    verification    on    %s' % rpm_filename))
