comparison bitten/slave.py @ 48:757aa3bf9594

* Simplify code for making snapshot archives. * The build slave now unpacks a snapshot after transmission.
author cmlenz
date Fri, 24 Jun 2005 17:13:07 +0000
parents 083e848088ee
children b4c51e32952b
comparison
equal deleted inserted replaced
47:083e848088ee 48:757aa3bf9594
23 import sys 23 import sys
24 import tempfile 24 import tempfile
25 import time 25 import time
26 26
27 from bitten import __version__ as VERSION 27 from bitten import __version__ as VERSION
28 from bitten.util import 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 32
33 def greeting_received(self, profiles): 33 def greeting_received(self, profiles):
68 if msg.get_content_type() == 'application/tar': 68 if msg.get_content_type() == 'application/tar':
69 workdir = tempfile.mkdtemp(prefix='bitten') 69 workdir = tempfile.mkdtemp(prefix='bitten')
70 archive_name = msg.get('Content-Disposition', 'snapshot.tar.gz') 70 archive_name = msg.get('Content-Disposition', 'snapshot.tar.gz')
71 archive_path = os.path.join(workdir, archive_name) 71 archive_path = os.path.join(workdir, archive_name)
72 file(archive_path, 'wb').write(msg.get_payload()) 72 file(archive_path, 'wb').write(msg.get_payload())
73 logging.info('Received snapshot archive: %s', archive_path) 73 logging.debug('Received snapshot archive: %s', archive_path)
74 74
75 # TODO: Spawn the build process 75 # Unpack the archive
76 prefix = archive.unpack(archive_path, workdir)
77 path = os.path.join(workdir, prefix)
78 logging.info('Unpacked snapshot to %s' % path)
79
80 # Fix permissions
81 for root, dirs, files in os.walk(workdir, topdown=False):
82 for dirname in dirs:
83 os.chmod(os.path.join(root, dirname), 0700)
84 for filename in files:
85 os.chmod(os.path.join(root, filename), 0400)
76 86
77 xml = xmlio.Element('ok') 87 xml = xmlio.Element('ok')
78 self.channel.send_rpy(msgno, beep.MIMEMessage(xml)) 88 self.channel.send_rpy(msgno, beep.MIMEMessage(xml))
89
90 # TODO: Start the build process
79 91
80 else: 92 else:
81 xml = xmlio.Element('error', code=500)['Sorry, what?'] 93 xml = xmlio.Element('error', code=500)['Sorry, what?']
82 self.channel.send_err(msgno, beep.MIMEMessage(xml)) 94 self.channel.send_err(msgno, beep.MIMEMessage(xml))
83 95
Copyright (C) 2012-2017 Edgewall Software