File: sign.py

package info (click to toggle)
mock 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,572 kB
  • ctags: 533
  • sloc: python: 4,816; sh: 429; ansic: 66; makefile: 47
file content (44 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
# License: GPL2 or later see COPYING
# Written by Julien BALLET <lta@fb.com>
# Copyright (C) 2014 Facebook

# python library imports
import glob
import os
import subprocess

from mockbuild.trace_decorator import getLog, traceLog

requires_api_version = "1.1"


# plugin entry point
@traceLog()
def init(plugins, conf, buildroot):
    Sign(plugins, conf, buildroot)


class Sign(object):
    """Automatically sign package after build"""

    @traceLog()
    def __init__(self, plugins, conf, buildroot):
        self.plugins = plugins
        self.conf = conf
        self.buildroot = buildroot
        self.plugins.add_hook('postbuild', self.sign_results)

        getLog().info(conf)
        getLog().info("enabled package signing")

    def sign_results(self):
        rpms = glob.glob('%s/*.rpm' % self.buildroot.resultdir)
        if rpms:
            getLog().info("Signing %s", ', '.join(rpms))
            opts = self.conf['opts'] % {'rpms': ' '.join(rpms), 'resultdir': self.buildroot.resultdir}
            cmd = "{0} {1}".format(self.conf['cmd'], opts)
            getLog().info("Executing %s", cmd)
            with self.buildroot.uid_manager:
                subprocess.call(cmd, shell=True, env=os.environ)