Ejemplo n.º 1
0
def npm(args):
    """
  Description:
  ------------
  Install the external packages relying on the NPM Javascript command line availabke on the NodeJs server.
  This will not install the packages using the definition in Imports but on the ones in the NPM configuration.

  Attributes:
  ----------
  :param parser: -pkg, String, The packages list comma separated
  :param parser: -s, Path of the NodeJs server
  """
    Imports.npm(args.packages.split(","),
                path=args.server,
                is_node_server=True,
                update=False)
Ejemplo n.º 2
0
def update(args):
    """
  Description:
  ------------
  Install only the defined packages locally.

  The install will rely on the version and configuration in the Imports module

  Attributes:
  ----------
  :param parser: -pkg, String, The packages list comma separated
  :param parser: -p, The project path
  """
    Imports.npm(args.packages.split(","),
                path=args.path,
                is_node_server=False,
                update=True)
Ejemplo n.º 3
0
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)
    Imports.npm(packages, path=module_path, is_node_server=False, update=False)
Ejemplo n.º 4
0
  def html_file(self, path=None, name=None, split_files=False, install_modules=False, options=None):
    """
    Description:
    ------------
    Function used to generate a static HTML page for the report

    Usage::

      Attributes:
    ----------
    :param path: The path in which the output files will be created
    :param name: The filename without the extension

    :return: The file full path
    """
    options = options or {}
    if path is None:
      path = os.path.join(os.getcwd(), "outs")
    if not os.path.exists(path):
      os.makedirs(path)
    if name is None:
      name = int(time.time())
    html_file_path = os.path.join(path, "%s.html" % name)
    htmlParts = []
    cssParts = dict(self._report.body.style.get_classes_css())
    order_components = list(self._report.components.keys())
    for component_id in order_components:
      component = self._report.components[component_id]
      if component.name == 'Body':
        continue

      if component.options.managed:
        htmlParts.append(component.html())
      cssParts.update(component.style.get_classes_css())
    body = str(self._report.body.set_content(self._report, "\n".join(htmlParts)))
    results = self._to_html_obj(htmlParts, cssParts, split_js=split_files)
    if split_files:
      results['cssImports'] = '%s\n<link rel="stylesheet" href="%s/%s.css" type="text/css">\n\n' % (results['cssImports'], options.get("css_route", './css'), name)
      body = '%s\n\n<script language="javascript" type="text/javascript" src="%s/%s.js"></script>' % (body, options.get("js_route", './js'), name)
      static_path = path
      if options.get("static_path") is not None:
        static_path = os.path.join(path, options.get("static_path"))
      if not os.path.exists(os.path.join(static_path, 'css')):
        os.makedirs(os.path.join(static_path, 'css'))
      with open(os.path.join(static_path, 'css', "%s.css" % name), "w") as f:
        f.write(results['cssStyle'])

      if not os.path.exists(os.path.join(static_path, 'js')):
        os.makedirs(os.path.join(static_path, 'js'))
      with open(os.path.join(static_path, 'js', "%s.js" % name), "w") as f:
        f.write(";".join(results['jsFrgsCommon'].values()))

    # Add the worker sections when no server available
    for js_id, wk_content in self._report._props.get('js', {}).get("workers", {}).items():
      body += '\n<script id="%s" type="javascript/worker">\n%s\n</script>' % (js_id, wk_content)
    with open(html_file_path, "w") as f:
      results['body'] = body
      results['header'] = self._report.headers
      f.write(HtmlTmplBase.STATIC_PAGE % results)
    if install_modules and self._report._node_modules is not None:
      Imports.npm(self._report.imports().requirements, path=self._report._node_modules[0], is_node_server=False)
    return html_file_path