Beispiel #1
0
def run(event, context):
    code = event.get('code')
    (fd, puml_file) = tempfile.mkstemp('.puml')
    png_file = puml_file.replace(".puml", ".png")
    #(fd, png_file) = tempfile.mkstemp('png')
    Files.write(puml_file, code)
    os.environ['GRAPHVIZ_DOT'] = './dot_static'

    result_1 = subprocess.run(
        ['java', '-jar', './plantuml.jar', '-tpng', '-o', '/tmp', puml_file],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)

    result_2 = subprocess.run(['ls', '-l', '/tmp'], stdout=subprocess.PIPE)
    if os.path.exists(png_file):
        with open(png_file, "rb") as image_file:
            png = base64.b64encode(image_file.read()).decode()
    else:
        png = None

    result = {
        "puml_file": puml_file,
        "png_file": png_file,
        "result_1_stdout": result_1.stdout.decode(),
        "result_1_stderr": result_1.stderr.decode(),
        "result_2_stdout": result_2.stdout.decode(),
        "png": png
    }
    return result
 def create_temp_file(self, new_code=None):
     self.folder = Files.temp_folder('tmp_lambda_')
     if new_code: self.lambda_code = new_code
     self.tmp_file = Files.path_combine(self.folder,
                                        '{0}.py'.format(self.file_name))
     Files.write(self.tmp_file, self.lambda_code)
     assert Files.exists(self.tmp_file)
     return self
def run(event, context):
    file_name = event.get('file_name')  # get file_name from lambda params
    tmp_path = '/tmp'  # location of lambda temp folder
    tmp_file = Files.path_combine(
        tmp_path, file_name)  # create file name (in temp folder)

    Files.write(tmp_file, 'some text')  # create file (with some text)

    return Files.find(tmp_path + '/*.*')  # return list of files in temp folder
Beispiel #4
0
 def save(self, path):
     Files.write(path, self.puml)
     return self
Beispiel #5
0
 def __enter__(self):
     Files.write(self.file_path, self.contents)
     return self
Beispiel #6
0
 def __enter__(self):
     Files.write(self.file_path, self.html)
     return self