コード例 #1
0
ファイル: views.py プロジェクト: 10sr/hue
def get_help_fs(app_name):
  """
  Creates a local file system for a given app's help directory.
  """
  app = appmanager.get_desktop_module(app_name)
  if app is not None:
    if app.help_dir is None:
      raise PopupException("No help available for app '%s'." % app_name)
    return LocalSubFileSystem(app.help_dir)
  else:
    raise PopupException("App '%s' is not loaded, so no help is available for it!" % app_name)
コード例 #2
0
ファイル: views.py プロジェクト: maduhu/HDP-hue
def get_help_fs(app_name):
    """
  Creates a local file system for a given app's help directory.
  """
    app = appmanager.get_desktop_module(app_name)
    if app is not None:
        if app.help_dir is None:
            raise PopupException("No help available for app '%s'." % app_name)
        return LocalSubFileSystem(app.help_dir)
    else:
        raise PopupException(
            "App '%s' is not loaded, so no help is available for it!" %
            app_name)
コード例 #3
0
ファイル: views.py プロジェクト: ranade1/hue-3
def view(request, app, path):
    """
  Views and renders a file at a given path.

  Markdown files are parsed through markdown; others
  are just pasted in <pre>'s.

  TODO: Expose a way to do images.
  """

    path = _unquote_path(path)
    fs = get_help_fs(app)

    if fs.isdir(path):
        for i in INDEX_FILENAMES:
            tmp_path = os.path.join(path, i)
            if fs.isfile(tmp_path):
                path = tmp_path

    if not fs.isfile(path):
        raise PopupException("Could not find or read the file: %s (app %s)" %
                             (path, app))

    content = fs.open(path, 'r').read()
    if isinstance(content, bytes):
        content = str(content, 'utf-8', errors='replace')
    if path.lower().endswith(".md"):
        content = ('<div class="print rendered-markdown">' +
                   markdown.markdown(content, ['extra']) + '</div>')
    elif path.lower().endswith(".html"):
        content = '<div class="print">%s</div>' % (content, )
    else:
        # TODO(todd) escape content?
        content = '<pre>' + content + '</pre>'

    data = {
        'content':
        content,
        'apps':
        sorted([x for x in appmanager.DESKTOP_MODULES if x.help_dir],
               key=lambda app: app.menu_index),
        'title':
        appmanager.get_desktop_module(app).nice_name,
        'current':
        app,
        'is_embeddable':
        request.GET.get('is_embeddable', False),
    }
    return render("display.mako", request, data)
コード例 #4
0
ファイル: views.py プロジェクト: 10sr/hue
def view(request, app, path):
  """
  Views and renders a file at a given path.

  Markdown files are parsed through markdown; others
  are just pasted in <pre>'s.

  TODO: Expose a way to do images.
  """

  path = _unquote_path(path)
  fs = get_help_fs(app)

  if fs.isdir(path):
    for i in INDEX_FILENAMES:
      tmp_path = os.path.join(path, i)
      if fs.isfile(tmp_path):
        path = tmp_path

  if not fs.isfile(path):
    raise PopupException("Could not find or read the file: %s (app %s)" % (path, app))

  content = fs.open(path, 'r').read()
  content = unicode(content, 'utf-8', errors='replace')
  if path.lower().endswith(".md"):
    content = ('<div class="print rendered-markdown">' +
               markdown.markdown(content, ['extra']) +
               '</div>')
  elif path.lower().endswith(".html"):
    content = '<div class="print">%s</div>' % (content,)
  else:
    # TODO(todd) escape content?
    content = '<pre>' + content + '</pre>'

  data = {
    'content': content,
    'apps': sorted([ x for x in appmanager.DESKTOP_MODULES if x.help_dir ],
      key = lambda app: app.menu_index),
    'title': appmanager.get_desktop_module(app).nice_name,
    'current': app,
    'is_embeddable': request.GET.get('is_embeddable', False),
  }
  return render("display.mako", request, data)
コード例 #5
0
def view(request, app, path):
    """
  Views and renders a file at a given path.

  Markdown files are parsed through markdown; others
  are just pasted in <pre>'s.

  TODO: Expose a way to do images.
  """

    path = _unquote_path(path)
    fs = get_help_fs(app)

    if fs.isdir(path):
        for i in INDEX_FILENAMES:
            tmp_path = os.path.join(path, i)
            if fs.isfile(tmp_path):
                path = tmp_path

    if not fs.isfile(path):
        raise PopupException("Could not find or read the file: %s (app %s)" % (path, app))

    content = fs.open(path, "r").read()
    content = unicode(content, "utf-8", errors="replace")
    if path.lower().endswith(".md"):
        content = '<div class="print rendered-markdown">' + markdown.markdown(content, ["extra"]) + "</div>"
    elif path.lower().endswith(".html"):
        content = '<div class="print">%s</div>' % (content,)
    else:
        # TODO(todd) escape content?
        content = "<pre>" + content + "</pre>"

    data = {
        "content": content,
        "apps": sorted([x for x in appmanager.DESKTOP_MODULES if x.help_dir], key=lambda x: x.nice_name.lower()),
        "title": appmanager.get_desktop_module(app).nice_name,
    }
    return render("display.mako", request, data)