def test__using_with__no_params(self):
        with Temp_File() as temp:
            assert Files.file_extension(temp.file_path) == '.tmp'
            assert Files.exists(temp.file_path)
            assert Files.contents(temp.file_path) == '...'
        assert Files.not_exists(temp.file_path)

        with Temp_File('abc', 'txt') as temp:
            assert Files.file_extension(temp.file_path) == '.txt'
            assert Files.exists(temp.file_path)
            assert Files.contents(temp.file_path) == 'abc'
        assert Files.not_exists(temp.file_path)
Esempio n. 2
0
def run(event, context):
    load_dependency('pydot')
    channel = event.get('channel')
    data = event.get('dot')

    #slack_message("in dot to svg: {0}".format(event), [], channel)
    log_to_elk("in dot to svg: {0}".format(event))

    import dot_parser

    try:
        (fd, tmp_file) = tempfile.mkstemp('dot)')
        dot_static = '/tmp/lambdas-dependencies/pydot/dot_static'
        Process.run("chmod", ['+x', dot_static])
        data = data.replace('&lt;', '<').replace(
            '&gt;', '>'
        )  # this solved a really nasty bug caused by the fact that Slack will html encode the < and >

        # graph          = pydot.graph_from_dot_data(data).pop()
        # <from pydot>  use code below (instead of above) to get a better error message from dot parser
        graphparser = dot_parser.graph_definition()
        graphparser.parseWithTabs()
        tokens = graphparser.parseString(data)
        graph = list(tokens).pop()
        # </from pydot>
        graph.write_svg(tmp_file, prog=dot_static)
        svg_raw = Files.contents(tmp_file)
        return base64.b64encode(svg_raw.encode()).decode()
    except Exception as error:
        slack_message("[dot_to_svg] Error: {0} ".format(error), [], channel)
        return None
Esempio n. 3
0
    def test_invoke_using_map_as_param(self):
        cs_map_2 = self.folder_src_hugo + '/static/coffee/map-2.coffee'
        payload = {'coffee_script_code': Files.contents(cs_map_2)}
        result = self.zip_update_invoke(payload)
        #result = self.just_invoke(payload)

        self.save_image(result, './lambda-result.png')
    def test_invoke___jira_issues_dot_file(self):

        dot = Files.contents('../../../data/jira-test.dot')
        Dev.pprint(dot)
        params = {"dot": dot, "channel": "DDKUZTK6X"}
        svg = self.dot_to_svg.update().invoke(params)
        #how_Img.from_svg_string(svg)
        Dev.pprint(svg)
Esempio n. 5
0
    def test_puml___dudes_creation(self):

        target_file = '/tmp/dudes-puml.png'
        puml = Files.contents('../dudes/puml/first-test.puml')

        #Dev.pprint(puml)
        #self.plantuml.puml_to_png_via_local_server(puml, target_file)
        self.plantuml.puml_to_png_using_lambda_function(puml, target_file)
Esempio n. 6
0
def setup_tmp_web_root(payload):
    copy_tree('./html', web_root)
    cs_map_1 = web_root + '/coffee/map-1.coffee'
    if payload.get('coffee_script_code'):
        cs_code = payload.get('coffee_script_code')
        Files.write(cs_map_1, cs_code)

    if payload.get("queryStringParameters") and payload.get(
            "queryStringParameters").get('code'):
        cs_code = payload.get("queryStringParameters").get('code')
        Files.write(cs_map_1, cs_code)
    return Files.contents(cs_map_1)
Esempio n. 7
0
 def screenshot_file(self, html_file, img_file=None, clip=None):
     return self.screenshot_html(Files.contents(html_file), img_file, clip)
Esempio n. 8
0
 def render_file(self, html_file):
     return self.render_html(Files.contents(html_file))
Esempio n. 9
0
 def create_local_png(self, puml_file):
     png_file = '/tmp/{0}.png'.format(Files.file_name(puml_file))
     puml = Files.contents(puml_file)
     img_url = 'https://github.com/DinisCruz/Book_Generation_Z_Developer/raw/dudes-test/puml-graphs/dudes/puml/'
     puml = puml.replace("<img:", "<img:{0}".format(img_url))
     return self.plantuml.puml_to_png_using_lambda_function(puml, png_file)