def dereference_schemas(input_dir, output_dir, schemas): """ Dereference the parent schema files to resolve the $ref child schema. If successful, then replace the original. """ logger = logging.getLogger("generate-api-docs") output_schemas_dir = os.path.join(output_dir, "schemas") os.makedirs(output_schemas_dir, exist_ok=True) script_pn = os.path.join(sys.path[0], "deref-schema.js") logger.debug("Found %s declared schema files.", len(schemas)) for decl in schemas: input_pn = os.path.normpath(os.path.join(input_dir, schemas[decl])) output_pn = os.path.join(output_schemas_dir, os.path.basename(input_pn)) try: sh.node(script_pn, input_pn, output_pn).stdout.decode().strip() except sh.ErrorReturnCode as err: logger.debug("Trouble doing node: %s", err.stderr.decode()) msg = ("Ignore the error, and do not replace the schema. " "The lint-raml job should have been used beforehand, " "and would have already handled this.") logger.debug(msg) continue else: try: shutil.copyfile(output_pn, input_pn) except: logger.debug("Could not copy %s to %s", output_pn, input_pn)
def do_amf(file_pn, input_dir, api_version, include_warnings): """Assess the api description.""" logger = logging.getLogger("api-lint") if include_warnings: option_warnings = "-w" else: option_warnings = "" input_dir_pn = os.path.abspath(input_dir) script_pn = os.path.join(sys.path[0], "amf.js") try: # pylint: disable=E1101 sh.node(script_pn, "-t", api_version, "-f", file_pn, option_warnings, _cwd=input_dir_pn) except sh.ErrorReturnCode as err: status = False logger.error("%s\n%s", err.stderr.decode(), err.stdout.decode()) else: logger.info(" did not detect any errors") status = True return status
def dereference_schemas(api_type, input_dir, output_dir, schemas): """ Dereference the parent schema files to resolve the $ref child schema. If successful, then replace the original. """ #logger.debug("Found %s declared schema files.", len(schemas)) if "RAML" in api_type: subdir = "r" if "OAS" in api_type: subdir = "s" output_schemas_dir = os.path.join(output_dir, subdir, "schemas") script_pn = os.path.join(sys.path[0], "deref-schema.js") for schema_fn in schemas: input_pn = os.path.normpath(os.path.join(input_dir, schema_fn)) output_pn = os.path.join(output_schemas_dir, os.path.basename(input_pn)) try: sh.node(script_pn, input_pn, output_pn).stdout.decode().strip() except sh.ErrorReturnCode as err: logger.debug("Trouble doing node: %s", err.stderr.decode()) msg = ("Ignore the error, and do not replace the schema. " "The api-lint tool should have been used beforehand, " "and would have already handled this.") logger.debug(msg) continue else: try: shutil.copyfile(output_pn, input_pn) except: logger.debug("Could not copy %s to %s", output_pn, input_pn)
def dereference_schemas(schemas, release_api_dir, main_api_dir): """ Dereference the parent schema files to resolve the $ref child schema. """ script_pn = os.path.join(sys.path[0], "deref-schema.js") release_parent_dir = os.path.join(release_api_dir, "derefparents") os.makedirs(release_parent_dir, exist_ok=True) main_parent_dir = os.path.join(main_api_dir, "derefparents") os.makedirs(main_parent_dir, exist_ok=True) for schema_fn in schemas: release_input_pn = os.path.normpath(os.path.join(release_api_dir, schema_fn)) release_output_pn = os.path.normpath(os.path.join(release_parent_dir, schema_fn)) os.makedirs(os.path.split(release_output_pn)[0], exist_ok=True) try: sh.node(script_pn, release_input_pn, release_output_pn) except sh.ErrorReturnCode as err: logger.warning("Trouble doing node: %s", err.stderr.decode()) main_input_pn = os.path.normpath(os.path.join(main_api_dir, schema_fn)) main_output_pn = os.path.normpath(os.path.join(main_parent_dir, schema_fn)) os.makedirs(os.path.split(main_output_pn)[0], exist_ok=True) try: sh.node(script_pn, main_input_pn, main_output_pn) except sh.ErrorReturnCode as err: logger.warning("Trouble doing node: %s", err.stderr.decode()) sleep(1)
def instagram(video, caption): if not os.path.isfile(video): raise IOError("File %s not accessible." % video) print("Processing video " + video + " for Instagram.") video = prepare_video_to_instagram(video) thumbnail = make_thumbnail(video) node("./instagram-uploader.js", ig_user, ig_password, video, thumbnail, caption) # import ipdb; ipdb.set_trace() # Cleanup import ipdb ipdb.set_trace() [os.remove(x) for x in ["thumbnail.jpg", "short.mp4"] if os.path.isfile(x)]
def chrome(state_obj, config): BROWSER = 'Headless Chrome' OS = platform.system() + ' ' + platform.release() WIDTH = config['resolution'][0] HEIGHT = config['resolution'][1] real_img_name = get_img_name(BROWSER, OS, WIDTH, HEIGHT, state_obj) img_query = Image.objects.filter(browser_type=BROWSER, operating_system=OS, state=state_obj, device_res_width=WIDTH, device_res_height=HEIGHT) # generate new image if this image file doesn't exist if (img_query.count() == 0 or img_query.count() == 1 and not img_query.get().image_exists()): with tempfile.NamedTemporaryFile(suffix='.png') as temp_img: try: sh.node( 'screenshotScript/puppeteer.js', # where the capture.js script is '--url={0}'.format( state_obj.full_url), # url for screenshot '--imgName={0}'.format(temp_img.name), # img name '--imgWidth={0}'.format(WIDTH), # width '--imgHeight={0}'.format(HEIGHT)) # height if img_query.count() == 1: # save this file plus information into Image model img_obj = img_query.get() else: img_obj = Image(img_file=None, browser_type=BROWSER, operating_system=OS, state=state_obj, device_res_width=WIDTH, device_res_height=HEIGHT) img_obj.img_file.save(real_img_name, temp_img, save=True) return img_obj # if there is some issue with screenshotting then say so # but still create the image object except sh.ErrorReturnCode_1, e: error_msg = e.stdout print(error_msg) return
def proxyCommand(host, port, chargingport, glassfishport): print("Installing logic proxy") name = proxy.get("url").split("/")[-1][:-4] cd(name) bash('install.sh') if not os.path.isfile("config.js"): shutil.copy2("config.js.template", "config.js") with open("config.js") as f: text = f.read() text = text.replace("config.port = 80", "config.port = {}".format(port))\ .replace("'/proxy'", "''") texts = text.split("\n") texts = texts[:59] + generate_endpoints(glassfishport, chargingport) + texts[121:] text = "\n".join(texts) with open("config.js", "w") as f: f.write(text) if os.path.isdir('indexes'): rm('-rf', 'indexes') mkdir('indexes') node('fill_indexes.js') print(""" Finished! Now, go to your IdM instance (e.g. https://account.lab.fiware.org) and create an application with this settings: - URL: http://{host}:{port} - Callback URL: http://{host}:{port}/auth/fiware/callback Create a role called "seller" Attach the role to the users you prefer. Modify config.js file with: - config.oauth2.clientID: The client ID that you got when you created the Application - config.oauth2.clientSecret: The client Secret that you got when you created the Application - config.oauth2.callbackURL = http://{host}:{port}/auth/fiware/callback Please refer to http://business-api-ecosystem.readthedocs.io/en/latest/installation-administration-guide.html#configuration for details on configuration settings """.format(host=host, port=port))
def emmet(abbr: str) -> Optional[str]: npmdir = os.path.join(os.path.dirname(__file__), "htmltools") if not os.path.isdir(os.path.join(npmdir, "node_modules")): print2("Installing Node.js dependencies...\n") sh.npm("install", "@emmetio/expand-abbreviation", _cwd=npmdir) return sh.node("emmet.js", abbr, _cwd=npmdir)
def proxyCommand(host, port, chargingport, glassfishport): print("Installing logic proxy") name = proxy.get("url").split("/")[-1][:-4] cd(name) npm("install") if not os.path.isfile("config.js"): shutil.copy2("config.js.template", "config.js") text = "" with open("config.js") as f: text = f.read() text = text.replace("config.port = 80", "config.port = {}".format(port))\ .replace("'/proxy'", "''") texts = text.split("\n") texts = texts[:47] + generate_endpoints(glassfishport, chargingport) + texts[109:] text = "\n".join(texts) with open("config.js", "w") as f: f.write(text) mkdir('indexes') node('fill_indexes.js') print(""" Finished! Now, go to https://account.lab.fiware.org and create an application with this settings: - URL: http://{host}:{port} - Callback URL: http://{host}:{port}/auth/fiware/callback Create a role called "seller" Attach the role to the users you prefer. Modify config.js file with: - config.oauth2.clientID: The client ID that you got when you created the Application - config.oauth2.clientSecret: The client Secret that you got when you created the Application - config.oauth2.callbackURL = http://{host}:{port}/auth/fiware/callback Once you've done all, execute the proxy with: node server.js """.format(host=host, port=port))
def definitions(self): # The definitions are hidden in the first script tag # but are set line by line like so: # var defs = {}; # defs.Ufs = {...}; # defs.Macrorregiao = {...}; # need to grab all the code and run in JS somehow _ = self.document.xpath(".//script").re( r"(var\sdefs\s=\s{}[\s\S]+)</script>")[0] _ = _ + "process.stdout.write(JSON.stringify(defs))" _ = node(_in=_) _ = json.loads(str(_)) return _
''' ------------------------------ Script artifacts ---------------------------- ''' def log(msg, *params): print(msg.format(*params) if (params) else msg) def logFromClient(*params): client = params[0] msgLine = params[1] if ("data:" in msgLine): log("Client {} received: {}", client, msgLine) def send(data, path): msg = json.dumps(data) log("Sending: \'{}\' to {}\n", msg, path) curl("-i", "-H", 'Content-Type: application/json', "-d", msg, "127.0.0.1:9001/%s" % path) ''' ------------------------------ Script ------------------------------------- ''' sseClient = './client.js' send({'label': 'Akka'}, 'flows') for i in range(1, 5): node(sseClient, _bg = True, _out = partial(logFromClient, i)) time.sleep(1) send({'text': "message%s" % i}, "flows/akka/messages")
return url def get_accessor_server(): if args.accessors_library_server != 'SENTINEL': accessors_library_server = args.accessors_library_server elif 'ACCESSORS_LIBRARY_SERVER' in os.env: accessors_library_server = os.env['ACCESSORS_LIBRARY_SERVER'] elif 'library-server' in conf: accessors_library_server = conf['library-server'] else: accessors_library_server = 'accesors.io' return format_accessor_server(accessors_library_server) try: node_version = str(sh.node('--version')).strip() except sh.CommandNotFound: print("Accessors require that `node` is installed.") print("Please get a copy from https://nodejs.org") sys.exit(1) if node_version[0] == 'v': node_version = node_version[1:] if not semver.match(node_version, ">=0.11.0"): print("Accessors require node version >=0.11.0") print("You have node version {} installed.".format(node_version)) print("Please update your node installation") print("(You can use `nvm` to do this easily: github.com/creationix/nvm)") print("(then run `nvm use 0.11`)") sys.exit(1)