Commit bdd79ceb authored by Vincent Pelletier's avatar Vincent Pelletier

Use timestamped logger in Updater & SlapOSControler.

parent e0ec5401
...@@ -3,7 +3,12 @@ from xml_marshaller import xml_marshaller ...@@ -3,7 +3,12 @@ from xml_marshaller import xml_marshaller
class SlapOSControler(object): class SlapOSControler(object):
def __init__(self, config, process_group_pid_set=None): def log(self, message):
print message
def __init__(self, config, process_group_pid_set=None, log=None):
if log is not None:
self.log = log
self.config = config self.config = config
# By erasing everything, we make sure that we are able to "update" # By erasing everything, we make sure that we are able to "update"
# existing profiles. This is quite dirty way to do updates... # existing profiles. This is quite dirty way to do updates...
...@@ -48,7 +53,7 @@ class SlapOSControler(object): ...@@ -48,7 +53,7 @@ class SlapOSControler(object):
def runSoftwareRelease(self, config, environment, process_group_pid_set=None, def runSoftwareRelease(self, config, environment, process_group_pid_set=None,
stdout=None, stderr=None): stdout=None, stderr=None):
print "SlapOSControler.runSoftwareRelease" self.log("SlapOSControler.runSoftwareRelease")
cpu_count = os.sysconf("SC_NPROCESSORS_ONLN") cpu_count = os.sysconf("SC_NPROCESSORS_ONLN")
os.putenv('MAKEFLAGS', '-j%s' % cpu_count) os.putenv('MAKEFLAGS', '-j%s' % cpu_count)
os.environ['PATH'] = environment['PATH'] os.environ['PATH'] = environment['PATH']
...@@ -72,7 +77,7 @@ class SlapOSControler(object): ...@@ -72,7 +77,7 @@ class SlapOSControler(object):
def runComputerPartition(self, config, environment, def runComputerPartition(self, config, environment,
process_group_pid_set=None, process_group_pid_set=None,
stdout=None, stderr=None): stdout=None, stderr=None):
print "SlapOSControler.runComputerPartition" self.log("SlapOSControler.runComputerPartition")
slap = slapos.slap.slap() slap = slapos.slap.slap()
slap.registerOpenOrder().request(self.software_profile, slap.registerOpenOrder().request(self.software_profile,
partition_reference='testing partition', partition_reference='testing partition',
......
...@@ -53,7 +53,13 @@ class Updater(object): ...@@ -53,7 +53,13 @@ class Updater(object):
realtime_output = True realtime_output = True
stdin = file(os.devnull) stdin = file(os.devnull)
def __init__(self, repository_path, revision=None, git_binary=None): def log(self, message):
print message
def __init__(self, repository_path, revision=None, git_binary=None,
log=None):
if log is not None:
self.log = log
self.revision = revision self.revision = revision
self._path_list = [] self._path_list = []
self.repository_path = repository_path self.repository_path = repository_path
...@@ -94,7 +100,7 @@ class Updater(object): ...@@ -94,7 +100,7 @@ class Updater(object):
quiet = kw.pop('quiet', False) quiet = kw.pop('quiet', False)
env = kw and dict(os.environ, **kw) or None env = kw and dict(os.environ, **kw) or None
command = format_command(*args, **kw) command = format_command(*args, **kw)
print '\n$ ' + command self.log('\n$ ' + command)
sys.stdout.flush() sys.stdout.flush()
p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE, p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env, stderr=subprocess.PIPE, env=env,
......
...@@ -169,7 +169,8 @@ branch = %(branch)s ...@@ -169,7 +169,8 @@ branch = %(branch)s
parameter_list.append(repository_path) parameter_list.append(repository_path)
subprocess.check_call(parameter_list) subprocess.check_call(parameter_list)
# Make sure we have local repository # Make sure we have local repository
updater = Updater(repository_path, git_binary=config['git_binary']) updater = Updater(repository_path, git_binary=config['git_binary'],
log=log)
updater.checkout() updater.checkout()
revision = "-".join(updater.getRevision()) revision = "-".join(updater.getRevision())
full_revision_list.append('%s=%s' % (repository_id, revision)) full_revision_list.append('%s=%s' % (repository_id, revision))
...@@ -212,7 +213,7 @@ branch = %(branch)s ...@@ -212,7 +213,7 @@ branch = %(branch)s
# Now prepare the installation of SlapOS and create instance # Now prepare the installation of SlapOS and create instance
slapos_controler = SlapOSControler(config, slapos_controler = SlapOSControler(config,
process_group_pid_set=process_group_pid_set) process_group_pid_set=process_group_pid_set, log=log)
for method_name in ("runSoftwareRelease", "runComputerPartition"): for method_name in ("runSoftwareRelease", "runComputerPartition"):
stdout, stderr = getInputOutputFileList(config, method_name) stdout, stderr = getInputOutputFileList(config, method_name)
slapos_method = getattr(slapos_controler, method_name) slapos_method = getattr(slapos_controler, method_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment