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
|
# vim: set sw=4 sts=4 et :
# Copyright: 2008 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: GPL-2
#
# Immortal lh!
#
# XXX: This is purely yay-something-works code
# This will change radically with time
import re, subprocess, sys
from .. import const
class Jobuild(object):
"""A jobuild"""
def __init__(self, jobdir, atom):
self.name = atom
self.jobdir = jobdir
self.jobuild = self._best_jobuild(atom)
def __str__(self):
return '%s jobuild object' % self.name
def _split_atom(self, atom):
regex = re.compile(r'^([<>]?=)?([a-zA-Z0-9_+-]+)/([a-zA-Z0-9_+-]+)(-|$)([0-9]+\.[0-9]+)?') # Fancy regex aye?
# >= bheekling / test-beagle - 1.0
# bheekling / build-brasero
parts = regex.findall(atom)
if not parts:
# FIXME: Custom exceptions
raise 'Invalid atom %s' % atom
parts = parts[0]
if parts[3] and not parts[4]:
# FIXME: Custom exceptions
raise 'Invalid atom %s' % atom
parts = (parts[0], parts[1], parts[2], parts[4],)
if (parts[0] and not parts[3]) or (parts[3] and not parts[0]):
# FIXME: Custom exceptions
raise 'Invalid atom %s' % atom
return parts
def _best_jobuild(self, atom):
parts = self._split_atom(atom)
data = {'maint': parts[1],
'pn': parts[2],
'pv': parts[3],
'jobtage': '%s/jobtage' % self.jobdir}
# FIXME: Add support for overlays, [<>]=, and unqualified atoms
jobuild = '%(jobtage)s/%(maint)s/%(pn)s/%(pn)s-%(pv)s.jobuild' % data
return jobuild
def get_var(self, var):
"""
Parse jobuild and get a variable
(yay-something-works function)
"""
command = 'GET "%s" "%s"' % (var, self.jobuild)
# Messages goto 3 and then to /dev/tty1
# stderr goes to stdout
# stdout goes to ${LOGFILE}
process = subprocess.Popen('\"%s\"/bin/jobuild.sh %s 3>&2 2>&1 | tee -a \"%s\"' % (const.AUTOTUA_DIR, command, const.LOGFILE), shell=True, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
process.stdin.write('ping\n')
response = process.stderr.readline()[:-1] # Remove trailing newline
if not response == 'pong':
# FIXME: Custom exceptions
raise 'Communication error: received %s when expecting "pong"' % response
response = process.stderr.readline()[:-1]
print response
|