-
Notifications
You must be signed in to change notification settings - Fork 4
/
rpm.py
88 lines (71 loc) · 2.09 KB
/
rpm.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os, sys, tempfile, shutil, subprocess, tarfile, textwrap
from zeroinstall.injector.config import load_config
from zeroinstall.injector import gpg
import support
_spec_template = """
Summary: {summary}
Name: {rpm_name}-launcher
Version: 1
Release: 1
Group: Unknown
License: Unknown
Source: {rpm_name}.tar.gz
Prefix: /usr
BuildArch: noarch
Requires: zeroinstall-injector >= 0.30
Packager: {author}
%description
{description}
Note: This is a launcher package; the actual program will be run using
Zero Install.
%prep
%setup -c
%install
mkdir -p $RPM_BUILD_ROOT
cp -pR * $RPM_BUILD_ROOT
%files
#/usr/bin/*
/usr/share/applications/*.desktop
/usr/share/pixmaps/*.png
"""
def makerpm(config, iface, icon):
pkg_name = iface.get_name().lower().replace(' ', '-')
sig, = config.iface_cache.get_cached_signatures(iface.uri)[:1]
key = gpg.load_key(sig.fingerprint)
d = tempfile.mkdtemp(prefix = '0bootstrap-')
try:
os.environ['HOME'] = d
bin_dir = d + '/usr/bin'
apps_dir = d + '/usr/share/applications'
icons_dir = d + '/usr/share/pixmaps'
top_dir = d + '/rpmbuild'
rpm_sources = top_dir + '/SOURCES'
os.makedirs(bin_dir)
os.makedirs(apps_dir)
os.makedirs(icons_dir)
os.makedirs(rpm_sources)
os.makedirs(top_dir + '/BUILD')
icon_name = None
if icon:
icon_name = pkg_name + '.png'
shutil.copyfile(icon, icons_dir + '/' + icon_name)
s = open(apps_dir + '/' + pkg_name + '.desktop', 'w')
s.write(support.make_desktop_file(iface, icon_name))
s.close()
spec = _spec_template.format(rpm_name = pkg_name,
author = key.name,
summary = iface.summary,
description = iface.description)
s = open(d + '/' + pkg_name + '.spec', 'w')
s.write(spec)
s.close()
t = tarfile.open(rpm_sources + '/' + pkg_name + '.tar.gz', 'w:gz')
t.add(d + '/usr', 'usr', recursive=True)
t.close()
subprocess.check_call(['rpmbuild', '--define', '%_topdir ' + top_dir,
'-bb', d + '/' + pkg_name + '.spec'])
rpms_dir = top_dir + '/RPMS/noarch'
rpm, = os.listdir(rpms_dir)
shutil.copyfile(rpms_dir + '/' + rpm, pkg_name + '.rpm')
finally:
shutil.rmtree(d)