comparison bitten/slave.py @ 51:5caccd7b247e

Proper archive format negotiation; improved representation of parsed XML content in {{{bitten.util.xmlio}}}.
author cmlenz
date Sun, 26 Jun 2005 16:06:30 +0000
parents b4c51e32952b
children 033366d81def
comparison
equal deleted inserted replaced
50:0d5ad32948b7 51:5caccd7b247e
27 from bitten import __version__ as VERSION 27 from bitten import __version__ as VERSION
28 from bitten.util import archive, beep, xmlio 28 from bitten.util import archive, beep, xmlio
29 29
30 30
31 class Slave(beep.Initiator): 31 class Slave(beep.Initiator):
32 """Build slave."""
32 33
33 def greeting_received(self, profiles): 34 def greeting_received(self, profiles):
34 if OrchestrationProfileHandler.URI not in profiles: 35 if OrchestrationProfileHandler.URI not in profiles:
35 err = 'Peer does not support the Bitten orchestration profile' 36 err = 'Peer does not support the Bitten orchestration profile'
36 logging.error(err) 37 logging.error(err)
42 """Handler for communication on the Bitten build orchestration profile from 43 """Handler for communication on the Bitten build orchestration profile from
43 the perspective of the build slave. 44 the perspective of the build slave.
44 """ 45 """
45 URI = 'http://bitten.cmlenz.net/beep/orchestration' 46 URI = 'http://bitten.cmlenz.net/beep/orchestration'
46 47
47 def handle_connect(self, init_elem=None): 48 def handle_connect(self):
48 """Register with the build master.""" 49 """Register with the build master."""
50 self.recipe_path = None
51
49 def handle_reply(cmd, msgno, msg): 52 def handle_reply(cmd, msgno, msg):
50 if cmd == 'ERR': 53 if cmd == 'ERR':
51 if msg.get_content_type() == beep.BEEP_XML: 54 if msg.get_content_type() == beep.BEEP_XML:
52 elem = xmlio.parse(msg.get_payload()) 55 elem = xmlio.parse(msg.get_payload())
53 if elem.tagname == 'error': 56 if elem.name == 'error':
54 raise beep.TerminateSession, \ 57 raise beep.TerminateSession, '%s (%d)' \
55 '%s (%d)' % (elem.gettext(), int(elem.code)) 58 % (elem.gettext(), int(elem.attr['code']))
56 raise beep.TerminateSession, 'Registration failed!' 59 raise beep.TerminateSession, 'Registration failed!'
57 logging.info('Registration successful') 60 logging.info('Registration successful')
58 61
59 sysname, nodename, release, version, machine = os.uname() 62 sysname, nodename, release, version, machine = os.uname()
60 logging.info('Registering with build master as %s', nodename) 63 logging.info('Registering with build master as %s', nodename)
64 ] 67 ]
65 self.channel.send_msg(beep.MIMEMessage(xml), handle_reply) 68 self.channel.send_msg(beep.MIMEMessage(xml), handle_reply)
66 69
67 def handle_msg(self, msgno, msg): 70 def handle_msg(self, msgno, msg):
68 content_type = msg.get_content_type() 71 content_type = msg.get_content_type()
69 if content_type in ('application/tar', 'application/zip'): 72 if content_type == beep.BEEP_XML:
73 elem = xmlio.parse(msg.get_payload())
74 if elem.name == 'build':
75 # Received a build request
76 self.recipe_path = elem.attr['recipe']
77
78 xml = xmlio.Element('proceed')[
79 xmlio.Element('accept', type='application/tar',
80 encoding='bzip2'),
81 xmlio.Element('accept', type='application/tar',
82 encoding='gzip'),
83 xmlio.Element('accept', type='application/zip')
84 ]
85 self.channel.send_rpy(msgno, beep.MIMEMessage(xml))
86
87 elif content_type in ('application/tar', 'application/zip'):
88 # Received snapshot archive for build
70 workdir = tempfile.mkdtemp(prefix='bitten') 89 workdir = tempfile.mkdtemp(prefix='bitten')
71 90
72 archive_name = msg.get('Content-Disposition') 91 archive_name = msg.get('Content-Disposition')
73 if not archive_name: 92 if not archive_name:
74 if content_type == 'application/tar': 93 if content_type == 'application/tar':
75 encoding = msg.get('Content-Transfer-Encoding') 94 encoding = msg.get('Content-Transfer-Encoding')
76 if encoding == 'gzip': 95 if encoding == 'gzip':
77 archive_name = 'snapshot.tar.gz' 96 archive_name = 'snapshot.tar.gz'
78 elif encoding == 'bzip2': 97 elif encoding == 'bzip2':
79 archive_name = 'snapshot.tar.bz2' 98 archive_name = 'snapshot.tar.bz2'
80 else: 99 elif not encoding:
81 archive_name = 'snapshot.tar' 100 archive_name = 'snapshot.tar'
82 else: 101 else:
83 archive_name = 'snapshot.zip' 102 archive_name = 'snapshot.zip'
84 archive_path = os.path.join(workdir, archive_name) 103 archive_path = os.path.join(workdir, archive_name)
85 file(archive_path, 'wb').write(msg.get_payload()) 104 file(archive_path, 'wb').write(msg.get_payload())
98 os.chmod(os.path.join(root, filename), 0400) 117 os.chmod(os.path.join(root, filename), 0400)
99 118
100 xml = xmlio.Element('ok') 119 xml = xmlio.Element('ok')
101 self.channel.send_rpy(msgno, beep.MIMEMessage(xml)) 120 self.channel.send_rpy(msgno, beep.MIMEMessage(xml))
102 121
103 # TODO: Start the build process 122 self.execute_build(path, self.recipe_path)
104 123
105 else: 124 def execute_build(self, basedir, recipe):
106 xml = xmlio.Element('error', code=500)['Sorry, what?'] 125 logging.info('Would now build in directory %s using recipe %s',
107 self.channel.send_err(msgno, beep.MIMEMessage(xml)) 126 basedir, recipe)
127 # TODO: Start the build process
108 128
109 129
110 def main(): 130 def main():
111 from optparse import OptionParser 131 from optparse import OptionParser
112 132
Copyright (C) 2012-2017 Edgewall Software