File: testrepos.py

package info (click to toggle)
zypper 1.14.95-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,564 kB
  • sloc: cpp: 27,591; sh: 718; perl: 133; xml: 109; python: 39; makefile: 14
file content (59 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/python3

import argparse
import shutil
import sys
import tempfile
import subprocess

parser = argparse.ArgumentParser(description='Set up and serve a test repository.')
parser.add_argument("sourceDir")

args = parser.parse_args()

rpmbuildBin = shutil.which("rpmbuild")
if rpmbuildBin == None:
    print("The rpmbuild binary was not found in PATH")
    sys.exit(1)

createRepo = shutil.which("createrepo")
if createRepo == None:
    print("The createrepo binary was not found in PATH")
    sys.exit(1)

#create our rpmbuild directory
builddir = tempfile.mkdtemp()
if builddir == None:
    print("Unable to create temporary directory")
    sys.exit(1)

rpmbuildCmd = "{} -D '%topdir {}' -D '%_builddir %{{topdir}}/build' -D '%_rpmdir %{{topdir}}/rpms' -D '%_srcrpmdir %{{topdir}}/rpms' -D '%_buildrootdir %{{topdir}}/buildroot' -bb *.spec".format(
    rpmbuildBin,
    builddir
)

print("Building the example RPMs")

result = subprocess.call([
    "bash",
    "-c",
    rpmbuildCmd
], cwd=args.sourceDir)

if result != 0:
    sys.exit(1)

print("Building the spec files worked, going to create the repository\n")
result = subprocess.call([
    createRepo,
    "{}/rpms".format(builddir)
])

if result != 0:
    sys.exit(1)