def pip_install_dependency(target): path_lambda_dependencies = Files.path_combine('.', '../../../_lambda_dependencies/') folder_create(path_lambda_dependencies) path_install = Files.path_combine(path_lambda_dependencies, target) if folder_not_exists(path_install): return Process.run('pip3', ['install','-t',path_install,target]) return folder_exists(path_install)
def issues(self): data = [] path_metadata = self.path_metadata() for path in Files.find(Files.path_combine(self.path(), '*.json')): if path != path_metadata: data.append(Json.load_file(path)) return data
def create__by_key(self): all_data = {} file_filter = Files.path_combine(self.file_system.folder_data, '**/*.json') for path in Files.find(file_filter): if self.filename_metadata not in path: # don't load metadata file data = Json.load_file(path) key = data.get('Key') all_data[key] = { 'path': path.replace(self.file_system.folder_data, '')[1:], 'links': {}, 'data': data, } for link in self.links.all(): from_key = link[0] link_type = link[1] to_key = link[2] issue = all_data.get(from_key) if issue: links = issue.get('links') if links.get(link_type) is None: links[link_type] = [] links[link_type].append(to_key) Json.save_file_pretty(self.path__by_key(), all_data) return all_data
def test_render__with_clip_params(self): #params = ['/examples/bootstrap-cdn.html' ,0 ,0 ,500 ,50 ] params = ['examples/wardley_map/cup-of-tea.html', 250, 50, 600, 200] png_data = self.browser_commands.render(None, None, params) Files.delete(self.png_file) self._save_png_data(png_data) assert Files.exists(self.png_file)
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 test_sending_files_to_firefox_send(self): print('-------') file_metadata = Files.file_contents( '/tmp/_firefox_send__file_metadata') bytes_1 = Files.file_contents_as_bytes('/tmp/_firefox_send__bytes_1') bytes_2 = Files.file_contents_as_bytes('/tmp/_firefox_send__bytes_2') bytes_3 = Files.file_contents_as_bytes('/tmp/_firefox_send__bytes_3') print(file_metadata) print(len(bytes_1)) print(len(bytes_2)) print(len(bytes_3)) ws = create_connection("wss://send.firefox.com/api/ws") print("sending file_metadata") ws.send(file_metadata) target_details = ws.recv() print(f'target_details: {target_details}') print("sending bytes_1") ws.send(bytes_1) print("sending bytes_2") ws.send(bytes_2) print("sending bytes_3") ws.send(bytes_3) result = ws.recv() print(f'result: {result}')
def use_lambda_file(self,lambda_file): file_path = Files.path_combine(self.get_root_folder(), lambda_file) if Files.exists(file_path) is False: return { 'status': 'error', 'data': 'could not find lambda file `{0}` in root folder `{1}`'.format(lambda_file, self.get_root_folder())} target_file = Files.path_combine(self.tmp_folder, '{0}.py'.format(self.lambda_name)) Files.copy(file_path,target_file) return { 'status': 'ok', 'file_path': file_path, 'target_file': target_file }
def test_render(self): params = ['examples/wardley_map/cup-of-tea.html'] png_data = self.browser_commands.render(None, None, params) Files.delete(self.png_file) self._save_png_data(png_data) assert Files.exists(self.png_file)
def test__using_with_valid_zip_and_target_folder(self): test_zip = parent_folder(__file__) target_folder = '/tmp/unzip_test' with Zip_Folder(test_zip) as (zip_file): with Unzip_File(zip_file, target_folder, True) as temp_folder: assert Files.exists(temp_folder) is True assert Files.exists(temp_folder) is False
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 upload_dependency(target): s3 = S3() s3_bucket = AWS_Config().lambda_s3_bucket() s3_file = 'lambdas-dependencies/{0}.zip'.format(target) path_libs = Files.path_combine('../../../_lambda_dependencies/', target) if Files.not_exists(path_libs): raise Exception(f"In Lambda upload_dependency, could not find dependency for: {target} , which resolved to {path_libs}") s3.folder_upload(path_libs, s3_bucket, s3_file) return s3.file_exists(s3_bucket, s3_file)
def test_add_file(self): lambda_file = Files.path_combine( __file__, '../../../../osbot_aws/lambdas/dev/hello_world.py') assert Files.exists(lambda_file) self.package.add_file(lambda_file) assert self.package.get_files() == ['/hello_world.py'] self.package.aws_lambda.handler = 'hello_world.run' self.package.update() assert self.package.invoke() == 'From lambda code, hello None'
def test__init__(self): temp_file = Temp_File() assert Files.exists(temp_file.tmp_folder) assert Files.not_exists(temp_file.tmp_file) assert Files.not_exists(temp_file.file_path) assert temp_file.tmp_folder in temp_file.file_path assert '/' == temp_file.file_path.replace(temp_file.tmp_folder, '').replace( temp_file.tmp_file, '')
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 __init__(self, web_page, headless=True): self.web_page = web_page self.title = 'browser view' self.web_root = Files.path_combine(Files.parent_folder(__file__), '../web_root') self.api_browser = API_Browser(headless=headless).sync__setup_browser() self.web_server = Web_Server(self.web_root) self.render_page = Render_Page(api_browser=self.api_browser, web_server=self.web_server)
def __init__(self): self.web_page = '/datatables/simple.html' self.web_root = Files.path_combine(Files.parent_folder(__file__), '../web_root') self.api_browser = API_Browser().sync__setup_browser() self.render_page = Render_Page(api_browser=self.api_browser, web_root=self.web_root) self.table_width = '100%' self.columns_defs = None self.table_title = None
def start(self): if Files.not_exists(self.web_root): Files.folder_create(self.web_root) # make sure root folder exists self.server_proc = subprocess.Popen( [self.python_path, "-m", "http.server", str(self.port)], cwd=self.web_root) self.wait_for_server_started() return self
def test_screenshot_url(self): #url = 'https://github.com/GoogleChrome/puppeteer' #url = 'https://www.google.co.uk' #url = 'http://visjs.org/examples/network/other/manipulation.html' #url = 'http://visjs.org/examples/graph3d/01_basics.html' url = 'https://getbootstrap.com/docs/4.3/examples/dashboard/' tmp_img = '/tmp/test_screenshot_html.png' Files.delete(tmp_img) self.render_page.screenshot_url(url, tmp_img) assert Files.exists(tmp_img)
def __init__(self, headless=True): self.web_page = '/vis-js/simple.html' self.web_root = Files.path_combine(Files.parent_folder(__file__), '../web_root') chrome = Chrome().headless(headless) self.api_browser = API_Browser(chrome.sync().browser()) self.render_page = Render_Page(api_browser=self.api_browser, web_root=self.web_root) self.bot_name = 'GS_Bot' self.options = None
def test_file_extension(self): assert Files.file_extension('/path/to/somefile.ext') == '.ext' assert Files.file_extension('/path/to/somefile.') == '.' assert Files.file_extension('/path/to/somefile..') == '.' assert Files.file_extension('/path/to/somefile') == '' assert Files.file_extension('/a/b.c/d') == '' assert Files.file_extension('/a/b.c/.git') == '' assert Files.file_extension('/a/b.c/a.git') == '.git' assert Files.file_extension('/a/b.c/a.git.abc') == '.abc' assert Files.file_extension(None) == ''
def get_files(self): all_files = [] for root, dirs, files in os.walk(self.tmp_folder): for file in files: file_path = Files.path_combine(root,file).replace(self.tmp_folder,'') all_files.append(file_path) return all_files
def test_download(self): from osbot_utils.utils.Http import GET #print(GET('https://srv-file4.gofile.io/download/ePB3QX/aa-some-text.txt')) bytes = GET( 'https://srv-file7.gofile.io/download/UL8zkd/JS_Siemens-original.pdf', encoding=None) print(Files.save_bytes_as_file(bytes, '/tmp/temp-2.pdf'))
def test_screenshot_file(self): with Temp_File(self.html, 'html') as temp_file: clip = {'x': 1, 'y': 1, 'width': 180, 'height': 30} img_file = self.render_page.screenshot_file(temp_file.file_path, self.tmp_img, clip=clip) assert Files.exists(img_file)
def json_report(self): from gw_bot.api.gw.Report_Xml_Parser import Report_Xml_Parser test_file = '/tmp/macros.xml-report.xml' xml_report = Files.contents(test_file) parser = Report_Xml_Parser(xml_report) json_report = parser.parse_document() return parser.analysis_report_summary(json_report)
def test_screenshot(self): #target = 'work/with-slider' target = 'work/test-1' (self.jp.login().open_notebook(target).ui_hide_input_boxes() #.browser_width(1200) .screenshot()) assert Files.exists(self.jp.tmp_screenshot)
def test_upload(self): tmp_folder = Temp_Folder_With_Lambda_File( self.lambda_name).create_temp_file() (self.aws_lambda.set_s3_bucket(self.s3_bucket).set_s3_key( self.s3_key).set_folder_code(tmp_folder.folder)) downloaded_file = self.aws_lambda.s3().file_download( self.s3_bucket, self.s3_key) # download file uploaded assert file_exists(downloaded_file) is True unzip_location = tmp_folder.folder + '_unzipped' Files.unzip_file(downloaded_file, unzip_location) # unzip it assert file_contents(Files.find(unzip_location + '/*').pop( )) == tmp_folder.lambda_code # confirm unzipped file's contents self.aws_lambda.s3().file_delete(self.s3_bucket, self.s3_key)
async def pdf(self, url=None, page=None, full_page=True, file_pdf=None, clip=None, viewport=None, js_code=None, delay=None): if url: await self.open(url, page=page) await self.js_execute(js_code) if delay: await asyncio.sleep(delay) if file_pdf is None: file_pdf = Files.temp_file('.pdf') page = await self.page() if viewport: await self.viewport(viewport) if clip: full_page = False await page.pdf({'path': file_pdf, 'fullPage': full_page, 'clip': clip}) return file_pdf
def create(self): if self.exists() is True: return { 'status': 'error', 'data': 'issue type already existed: {0}'.format(self.name) } Files.folder_create(self.path()) if self.create_metadata(): return { 'status': 'ok', 'data': 'issue type created: {0}'.format(self.name) } return { 'status': 'error', 'data': 'issue type metadata file not created: {0}'.format(self.name) }
def __init__(self, web_root=None): self.src_tmp = '/tmp/temp_web_server' self.python_path = 'python3' if web_root: self.web_root = web_root else: self.web_root = self.src_tmp + '/html' self.html_file = Files.path_combine(self.web_root, 'index.html') self.port = Misc.random_number(10000, 60000) self.server_proc = None
def delete(self): """ Delete Issue Type and all issues (be careful since this will delete all issues in this issue type) :return: Bool """ if self.exists(): return Files.folder_delete_all(self.path()) return False