def install_all(args): """ Description: ------------ Install all the internally defined packages locally. This will mimic the structure of NPM in order to facilitate the links. Attributes: ---------- :param parser: -p, The project path """ packages = set(Imports.CSS_IMPORTS.keys()) | set(Imports.JS_IMPORTS.keys()) project_path = args.path or os.getcwd() reports_path = utils.get_report_path(project_path, raise_error=False) sys.path.append(os.path.join(reports_path, '..')) static_path = "static" if os.path.exists(os.path.join(reports_path, '..', "ui_settings.py")): settings = __import__("ui_settings", fromlist=['object']) static_path = settings.PACKAGE_PATH module_path = os.path.join(reports_path, static_path) if not os.path.exists(module_path): os.makedirs(module_path) PyNpm.install(packages, path=module_path, is_node_server=False, update=False)
def page(args): """ Description: ------------ Create a new page in the current project. Attributes: ---------- :param parser: -p, The page / report name to be created (without the extension) :param parser: -n, The path where the new environment will be created: -p /foo/bar """ project_path = args.path or os.getcwd() sys.path.append(project_path) reports_path = utils.get_report_path(project_path) name = args.name if name.endswith(".py"): name = name[:-3] with open(os.path.join(reports_path, "%s.py" % name), "w") as f: f.write(''' from epyk.core.Page import Report from epyk.core.data import datamap, events, primitives # Create a basic report object page = Report() page.headers.dev() ''')
def compile(args): """ Description: ------------ Compile a markdown file to a valid HTML page. Attributes: ---------- :param args: """ project_path = args.path or os.getcwd() sys.path.append(project_path) reports_path = utils.get_report_path(project_path) with open(os.path.join(reports_path, "%s.md" % args.name), "w") as md: md_dta = md.read() page = Report() page.py.markdown.resolve(md_dta) try: settings = __import__("ui_settings", fromlist=['object']) if not os.path.exists(settings.VIEWS_FOLDER): # If it is not an absolute path settings.VIEWS_FOLDER = os.path.join(reports_path, '..', '..', settings.VIEWS_FOLDER) output = page.outs.html_file(path=settings.VIEWS_FOLDER, name=args.name, options={"split": split_files, "css_route": '/css', "js_route": '/js'}) except: output = page.outs.html_file(name=args.name, options={"split": False}) print(output)
def translate(args): """ Description: ------------ Translate a markdown file to a valid Epyk python page. Attributes: ---------- :param args: """ project_path = args.path or os.getcwd() sys.path.append(project_path) reports_path = utils.get_report_path(project_path) with open(os.path.join(reports_path, "%s.md" % args.name), "w") as md: md_dta = md.read() results = MarkDown.translate(md_dta) with open(os.path.join(reports_path, "%s.py" % args.name), "w") as f: f.write(''' from epyk.core.Page import Report # Create a basic report object page = Report() page.headers.dev() %s ''' % "\n".join(results))
def angular(args): """ Description: ------------ Generate an Angular Application from the Epyk page Attributes: ---------- """ project_path = args.path or os.getcwd() sys.path.append(project_path) report_path = utils.get_report_path(project_path, raise_error=False) sys.path.append(report_path) ui_setting_path = os.path.join(report_path, '..', 'ui_settings.py') auto_route, install_modules, view_folder, angular_app_path = False, False, 'views', None if os.path.exists(ui_setting_path): settings = __import__('ui_settings') install_modules = settings.INSTALL_MODULES angular_app_path = settings.ANGULAR_APP_PATH auto_route = settings.ANGULAR_AUTO_ROUTE view_folder = settings.ANGULAR_VIEWS_PATH mod = __import__(args.name, fromlist=['object']) page = utils.get_page(mod) app = page.outs.publish(server="angular", app_path=angular_app_path, module="MyModule", selector='mymodule', target_folder=view_folder, auto_route=auto_route) if install_modules: server_path, app_name = os.path.split(angular_app_path) app._app_path = server_path app.cli(app_name).npm(page.imports().requirements)
def transpile(args): """ Description: ------------ Transpile a specific report Attributes: ---------- :param name: -p, The path where the new environment will be created: -p /foo/bar :param path: -n, The name of the page to be transpiled: -n home. :param split: -s, Y / N Flag, to specify if the files should be split input 3 modules. :param output: -0. String. Optional. The output destination path. :param output: -0. String. Optional. The output destination path. :param colors: String. Optional. The list of colors as string commas delimited. """ project_path = args.path or os.getcwd() sys.path.append(project_path) report_path = utils.get_report_path(project_path, raise_error=False) sys.path.append(report_path) ui_setting_path = os.path.join(report_path, '..', 'ui_settings.py') install_modules, split_files, view_folder, settings = False, False, args.output or 'views', None if os.path.exists(ui_setting_path): settings = __import__('ui_settings') install_modules = settings.INSTALL_MODULES split_files = settings.SPLIT_FILES view_folder = settings.VIEWS_FOLDER if args.split is not None: split_files = args.split == "Y" views = [] if args.name is None: for v in os.listdir(report_path): if v.endswith(".py"): views.append(v[:-3]) else: if args.name.endswith(".py"): args.name = args.name[:-3] views = [args.name] for v in views: if v == "__init__": continue try: start = time.time() mod = __import__(v, fromlist=['object']) page = utils.get_page(mod, colors=args.colors) if settings is not None: page.node_modules(settings.PACKAGE_PATH, alias=settings.SERVER_PACKAGE_URL) output = page.outs.html_file(path=view_folder, name=v, options={ "split": split_files, "css_route": 'css', "js_route": 'js' }) print("File created in %sms, location: %s" % (round(time.time() - start, 4), output)) except Exception as err: print("Error in file %s.py" % v, err) print(traceback.format_exc())
def transpile_all(args): """ Description: ------------ Transpile to HTML all the reports in the project Views are generated by default at the same level than the ui_setting file Attributes: ---------- :param args: """ project_path = args.path or os.getcwd() sys.path.append(project_path) reports_path = utils.get_report_path(project_path) sys.path.append(reports_path) sys.path.append(os.path.join(reports_path, '..')) settings = __import__("ui_settings", fromlist=['object']) results = {"completed": [], "failed": []} for report in os.listdir(reports_path): if report.endswith(".py") and report != "__init__.py": view_name = report[:-3] mod = __import__(view_name, fromlist=['object']) importlib.reload(mod) try: page = utils.get_page(mod, template=True) page.node_modules(settings.PACKAGE_PATH, alias=settings.SERVER_PACKAGE_URL) if not os.path.exists(settings.VIEWS_FOLDER): # If it is not an aboslute path settings.VIEWS_FOLDER = os.path.join( reports_path, '..', '..', settings.VIEWS_FOLDER) options = {"css_route": '/css', "js_route": '/js'} if args.split: options = { "css_route": '/%s/css' % settings.PACKAGE_PATH, "js_route": '/%s/js' % settings.PACKAGE_PATH } if not os.path.exists(settings.PACKAGE_PATH): options["static_path"] = os.path.join( reports_path, '..', '..', settings.PACKAGE_PATH) else: options["static_path"] = settings.PACKAGE_PATH output = page.outs.html_file( path=settings.VIEWS_FOLDER, name=view_name, split_files=args.split, install_modules=settings.INSTALL_MODULES, options=options) results["completed"].append(view_name) print(output) except Exception as err: results["failed"].append(view_name) print("Error with view: %s" % view_name) print(err) return results
def requirements(args): """ Description: ------------ Get the list of external modules required for a script. Attributes: ---------- :param path: -p, the workspace path (Optional if run directly in the project root) :param exception: -e, Y/N flag :param page: -r, The page name (without the .py extension) """ project_path = args.path or os.getcwd() sys.path.append(project_path) requirements, reports_count = {}, 0 if args.pages is None: scripts = [] for fp in os.listdir(project_path): if fp.endswith(".py"): scripts.append(fp) else: scripts = args.pages.split(",") for script in scripts: if script.endswith(".py"): mod_name = script[:-3] else: mod_name = script script = "%s.py" % script report_path = utils.get_report_path(project_path, args.exception == "Y", report=script) sys.path.append(report_path) mod = __import__(mod_name, fromlist=['object']) page = utils.get_page(mod) page.outs.html() for pkg in page.imports.requirements: versions = page.imports.jsImports[pkg]['versions'] requirements[(pkg, versions[0])] = requirements.get( (pkg, versions[0]), 0) + 1 reports_count += 1 results = [] for k, v in requirements.items(): results.append({ "name": k[0], "version": k[1], "count": v, "latest": PyNpm.Npm().version(k[0]), "usage": "%0.1f%%" % (100 * v / reports_count) }) return results
def transpile(args): """ Description: ------------ Transpile a specific report Attributes: ---------- :param parser: -p, The path where the new environment will be created: -p /foo/bar :param parser: -n, The name of the page to be transpiled: -n home """ project_path = args.path or os.getcwd() sys.path.append(project_path) report_path = utils.get_report_path(project_path, raise_error=False) sys.path.append(report_path) ui_setting_path = os.path.join(report_path, '..', 'ui_settings.py') install_modules, split_files, view_folder, settings = False, False, 'views', None if os.path.exists(ui_setting_path): settings = __import__('ui_settings') install_modules = settings.INSTALL_MODULES split_files = settings.SPLIT_FILES view_folder = settings.VIEWS_FOLDER views = [] if args.name is None: for v in os.listdir(report_path): if v.endswith(".py"): views.append(v[:-3]) else: views = [args.name] for v in views: try: mod = __import__(v, fromlist=['object']) page = utils.get_page(mod) if settings is not None: page.node_modules(settings.PACKAGE_PATH, alias=settings.SERVER_PACKAGE_URL) output = page.outs.html_file(path=view_folder, name=v, split_files=split_files, install_modules=install_modules, options={ "css_route": '/css', "js_route": '/js' }) print(output) except Exception as err: print(err) print("")
def requirements(args): """ Description: ------------ Get the list of external modules required for a script. Attributes: ---------- :param parser: -p, the workspace path (Optional if run directly in the project root) :param parser: -r, The page name (without the .py extension) """ project_path = args.path or os.getcwd() sys.path.append(project_path) reprot_path = utils.get_report_path(project_path) sys.path.append(reprot_path) mod = __import__(args.page, fromlist=['object']) page = utils.get_page(mod) page.html() return page.imports().requirements
def html(args): """ Description: ------------ Transpile a specific report Attributes: ---------- :param parser: -p, The path where the new environment will be created: -p /foo/bar :param parser: -n, The name of the page to be transpiled: -n home :param parser: -split, Y / N Flag to specify if the result should be splitting in several files """ project_path = args.path or os.getcwd() sys.path.append(project_path) report_path = utils.get_report_path(project_path, raise_error=False) sys.path.append(report_path) mod = __import__(args.name, fromlist=['object']) page = utils.get_page(mod) output = page.outs.html_file(path="", name=args.name, split_files=args.split) print(output)