Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Created June 1, 2012 20:25
Show Gist options
  • Save fuzzy/2854936 to your computer and use it in GitHub Desktop.
Save fuzzy/2854936 to your computer and use it in GitHub Desktop.
Handles making building world/kern a little more pleasant on the eyes, not done yet, only supports FreeBSD and doesn't log at the moment.
#!/usr/bin/env python
import os, re, sys, time
import subprocess as SP
class oList(list):
def join(self):
retv = ''
for i in self:
retv += i+' '
return retv
args = oList(sys.argv)
BN = os.path.basename(sys.argv[0])
OS = os.uname()[0]
LG = open('/tmp/%s-build.log' % OS, 'w+')
args.pop(0)
if OS == 'FreeBSD' or OS == 'DragonflyBSD' or OS == 'OpenBSD':
cmd = 'make'
elif OS == 'NetBSD': cmd = '/usr/src/build.sh'
else:
print 'You are on an unsupported platform.'
sys.exit(1)
try:
if args[0].find('help') != -1 or args[0] == '-h':
print 'Usage: %s <make args for /usr/src>' % bname
print 'Example: %s -j4 buildkernel KERNCONF=CUSTOM' % bname
sys.exit(0)
except IndexError:
print 'Usage: %s <make args for /usr/src>' % bname
print 'Example: %s -j4 buildkernel KERNCONF=CUSTOM' % bname
sys.exit(0)
os.chdir('/usr/src')
st_time = time.time()
proc = SP.Popen('%s %s' % (cmd, args.join()), bufsize=0,
stdout=SP.PIPE, stderr=SP.STDOUT, close_fds=False, shell=True)
tp_time = None
try:
while 1:
buf = proc.stdout.readline()
if not buf:
break
LG.write(buf.strip())
if buf.strip().find('>>> ') != -1:
if buf.strip().find('stage') != -1:
if tp_time == None:
print buf.strip()+' '*20
tp_time = time.time()
else:
tmp = time.time()
print buf.strip()+' (Last step runtime: %.02f sec)%s' % ((tmp - tp_time), ' '*5)
tp_time = tmp
else: print buf.strip()+' '*25
elif buf.strip().find('==> ') != -1 and buf.strip()[0] == '=':
sys.stdout.write('%s%s\r' % (buf.strip(), ' '*25))
sys.stdout.flush()
except OSError:
print 'Something went horridly wrong.'
sys.exit(-1)
proc.poll()
LG.flush()
LG.close()
if proc.returncode != None:
print 'Total runtime: %d seconds.' % (time.time() - st_time)
else:
print 'There was an error in the build, check /tmp/%s-build.log for details.' % OS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment