Example #1
0
 def create_temp_file(self, new_code=None):
     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):
    load_dependency('plantuml')
    dot_static = '/tmp/lambdas-dependencies/plantuml/dot_static'
    plantuml_jar = '/tmp/lambdas-dependencies/plantuml/plantuml.jar'

    Process.run("chmod", ['+x', dot_static])
    Process.run("chmod", ['+x', plantuml_jar])

    os.environ['PLANTUML_LIMIT_SIZE'] = str(
        4096 * 4)  # set max with to 4 times the default (16,384)
    os.environ['GRAPHVIZ_DOT'] = dot_static
    (fd, puml_file) = tempfile.mkstemp('.puml')
    png_file = puml_file.replace(".puml", ".png")
    code = event.get('puml')
    Files.write(puml_file, code)

    subprocess.run([
        'java', '-jar', plantuml_jar, '-Xmx2512m', '-tpng', '-o', '/tmp',
        puml_file
    ],
                   stdout=subprocess.PIPE,
                   stderr=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

    return {"png_base64": png}
Example #3
0
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
 def setup(self):
     secret_data = json.loads(Secrets(self.secret_id).value())
     storage_file = '/tmp/gmail_storage_token.json'
     Files.write(storage_file, secret_data['storage'])
     store = file.Storage(storage_file)
     creds = store.get()
     self.service = build('gmail', 'v1', http=creds.authorize(Http()))
     # note: 'storage.json file created using storage
     # SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
     # if not creds or creds.invalid:
     #    flow = client.flow_from_clientsecrets(self.credentials_file, SCOPES)
     #    flags = argparser.parse_args('--auth_host_name localhost --logging_level INFO'.split())
     #    creds = run_flow(flow, store, flags)
     return self
Example #5
0
    def save(self, data):
        try:
            post              = frontmatter.Post(data.get('content'))
            post.metadata     = data.get('metadata')
            for key, value in post.metadata.items():
                default_value = '' if key not in ['sessions'] else []
                post.metadata[key] = value if value else default_value

            file_path = self.md_file_path(data['path'] )

            Files.write(file_path, frontmatter.dumps(post))
            if Files.exists(file_path):
                return { 'status': 'ok', 'data': data }
            else:
                return {'status': 'error', 'data': 'file not saved ok: {0}'.format(file_path) }
        except Exception as error:
            return { 'status': 'error', 'data': error }
Example #6
0
 def __enter__(self):
     Files.write(self.file_path, self.contents)
     return self
Example #7
0
 def save(self, path):
     Files.write(path, self.puml)
     return self
Example #8
0
 def __enter__(self):
     Files.write(self.file_path, self.html)
     return self