comparison c_kernel/kernel.py @ 9:101e99452042

Dockerized project :)
author Brendan Rius <brendan@omixy.com>
date Sat, 26 Mar 2016 14:54:39 +0000
parents aa54c85303b6
children
comparison
equal deleted inserted replaced
8:ca8f6aa0f6ed 9:101e99452042
26 26
27 def new_temp_file(self, **kwargs): 27 def new_temp_file(self, **kwargs):
28 """Create a new temp file to be deleted when the kernel shuts down""" 28 """Create a new temp file to be deleted when the kernel shuts down"""
29 # We don't want the file to be deleted when closed, but only when the kernel stops 29 # We don't want the file to be deleted when closed, but only when the kernel stops
30 kwargs['delete'] = False 30 kwargs['delete'] = False
31 kwargs['mode'] = 'w'
31 file = tempfile.NamedTemporaryFile(**kwargs) 32 file = tempfile.NamedTemporaryFile(**kwargs)
32 self.files.append(file.name) 33 self.files.append(file.name)
33 return file 34 return file
34 35
35 @staticmethod 36 @staticmethod
36 def execute_command(cmd): 37 def execute_command(cmd):
37 """Execute a command and returns the return code, stdout and stderr""" 38 """Execute a command and returns the return code, stdout and stderr"""
38 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 39 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39 stdout, stderr = p.communicate() 40 stdout, stderr = p.communicate()
40 return p.returncode, stdout, stderr 41 return p.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
41 42
42 @staticmethod 43 @staticmethod
43 def compile_with_gcc(source_filename, binary_filename): 44 def compile_with_gcc(source_filename, binary_filename):
44 args = ['gcc', source_filename, '-std=c11', '-o', binary_filename] 45 args = ['gcc', source_filename, '-std=c11', '-o', binary_filename]
45 return CKernel.execute_command(args) 46 return CKernel.execute_command(args)