-
Notifications
You must be signed in to change notification settings - Fork 0
/
_util.py
56 lines (44 loc) · 1.5 KB
/
_util.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
#!/usr/bin/env python
from optparse import OptionParser
import subprocess
import sys
import os
def parse_args():
parser = OptionParser()
parser.add_option("-r", "--release", dest="release", action="store_true",
default=False, help="stable release")
parser.add_option("-d", "--dist", action="store", dest="dist",
default="ubuntu", help="ubuntu/debian",
choices=["ubuntu", "debian"])
parser.add_option("-v", "--version", action="store", dest="version",
default=0, type="int", help="version increment")
return parser.parse_args()[0]
def cd(d):
old = os.getcwd()
os.chdir(d)
print("> CD: %s -> %s" % (old, d))
def p(cmd):
print("> %s" % cmd)
pipe = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, stdout=pipe, stderr=pipe, stdin=pipe, encoding="utf-8")
stdout, stderr = p.communicate()
return p.returncode, stdout.strip(), stderr.strip()
def clean(directory, *packages):
old = os.getcwd()
os.chdir(directory)
for package in packages:
cmd = "rm %s*.changes %s*.tar.gz %s*.tar.xz %s*.dsc %s*.upload %s*.deb %s*.build %s*.buildinfo %s*.diff.gz" % ((package,) * 9)
p(cmd)
os.chdir(old)
def failed(out):
status, stdout, stderr = out
return status != 0
def fail(out):
status, stdout, stderr = out
if status != 0:
print("#" * 24)
print(stdout)
print(stderr)
print("#" * 24)
sys.exit()
return out