def render(self): """ Render dashboard section """ name = self.get_name() context = { 'plugin': self, 'name': name, 'heading': self.get_heading(), 'classes': self.get_formatted_classes(), } try: context.update(self.get_context()) return bottle.mako_template(self.get_template(), **context) except Exception: logging.exception("Plugin rendering failed: {0}".format(name)) return bottle.mako_template(self.plugin_error_template, **context)
def render(self, *args, **kwargs): kwargs['template_lookup'] = self.lookup kwargs['template_settings'] = dict(input_encoding='utf-8', output_encoding='utf-8', encoding_errors='replace') kwargs.update(**self.context) return mako_template(*args, **kwargs)
def ls_dir(path, urlpath): files = os.listdir(path) natural_sort_ci(files) etag = gen_etag(path, files, is_file=True, weak=True) handle_etag(etag) files = [os.path.join(path, f) for f in files] files = [f for f in files if not os.path.islink(f) and (os.path.isfile(f) or os.path.isdir(f))] items = [make_item_data(f) for f in files] items.sort(key=lambda i: not i['is_dir']) # dirs first files = [i['basename'] for i in items if is_audio(i['basename'])] if is_json_request(): response.headers['Content-Type'] = 'application/json' body = json.dumps(items) elif is_m3u_request(): response.headers['Content-Type'] = 'audio/x-mpegurl' body = ''.join(urljoin(request.url, urlquote(f)) + '\n' for f in files) else: response.headers['Content-Type'] = 'text/html' body = mako_template(conf.TEMPLATE, items=items, files=files, relpath=urlpath, parent=parent).encode('utf-8') return slice_partial(body)
def render(self,*args,**kwargs): kwargs['template_lookup'] = self.lookup kwargs['template_settings'] = dict( input_encoding='utf-8', output_encoding='utf-8', encoding_errors='replace' ) kwargs.update(**self.context) return mako_template(*args,**kwargs)
def ls_root(): items = [dict(size=0, basename=k, is_dir=True, is_audio=False) for k in conf.ROOTS] items.sort(key=lambda x: x['basename']) etag = gen_etag(list(conf.ROOTS), weak=True) handle_etag(etag) if is_json_request(): response.headers['Content-Type'] = 'application/json' body = json.dumps(items) else: response.headers['Content-Type'] = 'text/html' body = mako_template(conf.TEMPLATE, items=items, files=[], relpath='/', parent='/').encode('utf-8') return slice_partial(body)
def test_template_shortcut(self): result = mako_template('start ${var} end', var='middle') self.assertEqual(touni('start middle end'), result)
def render(self, *args, **kwargs): kwargs['template_lookup'] = self.lookup kwargs.update(**self.context) return mako_template(*args, **kwargs)
def mako_renderer(template, resp): return mako_template(template, resp)
def render(self,*args,**kwargs): kwargs['template_lookup'] = self.lookup kwargs.update(**self.context) return mako_template(*args,**kwargs)
def test_template_shortcut(self): result = mako_template("start ${var} end", var="middle") self.assertEqual(u"start middle end", result)
def cmd_main(): parser = ArgumentParser( description='eDocuments - a simple and productive personal documents ' 'library.', prog=sys.argv[0] ) parser.add_argument( '--install', action='store_true', help='Install the application icon, the required packages, ' 'and default config file', ) parser.add_argument( '--lang3', default='eng', metavar='LANG', help='the language used by the OCR', ) parser.add_argument( '--list-available-lang3', action='store_true', help='List the available language used by the OCR.', ) options = parser.parse_args() if options.list_available_lang3: if Path('/usr/bin/apt-cache').exists(): result = subprocess.check_output([ '/usr/bin/apt-cache', 'search', 'tesseract-ocr-']) result = str(result)[1:].strip("'") result = result.replace('\\n', '\n') result = re.sub( '\ntesseract-ocr-all - [^\n]* packages\n', '', result, flags=re.MULTILINE) result = re.sub(r'tesseract-ocr-', '', result) result = re.sub(r' - tesseract-ocr language files ', ' ', result) print(result) else: exit('Works only on Debian base OS') if options.install: if input( 'Create desktop and icon files (`edocuments.desktop` and ' '`edocuments.svg` in `~/.local/share/applications` and ' 'in `~/.local/share/icons`)?\n' ) in ['y', 'Y']: if not Path(os.path.expanduser( '~/.local/share/applications')).exists(): os.makedirs(os.path.expanduser('~/.local/share/applications')) ressource_dir = os.path.join(os.path.dirname( os.path.abspath(__file__)), 'ressources') shutil.copyfile( os.path.join(ressource_dir, 'edocuments.desktop'), os.path.expanduser( '~/.local/share/applications/edocuments.desktop') ) if not Path(os.path.expanduser( '~/.local/share/icons')).exists(): os.makedirs(os.path.expanduser('~/.local/share/icons')) shutil.copyfile( os.path.join(ressource_dir, 'edocuments.svg'), os.path.expanduser( '~/.local/share/icons/edocuments.svg') ) if input( 'Create the basic configuration ' '(~/.config/edocuments.yaml)?\n' ) in ['y', 'Y']: config = mako_template( os.path.join(ressource_dir, 'config.yaml'), lang=options.lang3 ) with open( os.path.expanduser('~/.config/edocuments.yaml'), 'w' ) as file_open: file_open.write(config) if Path('/usr/bin/apt-get').exists(): installed_packages = [] for line in str(subprocess.check_output(['dpkg', '-l'])) \ .split(r'\n'): if line.find('ii ') == 0: installed_packages.append(re.split(r' +', line)[1]) packages = [p for p in [ 'python3-pyqt5', 'sane-utils', 'imagemagick', 'tesseract-ocr', 'tesseract-ocr-' + options.lang3, 'optipng', 'poppler-utils', 'odt2txt', 'docx2txt', ] if p not in installed_packages] print(packages) if len(packages) != 0: if input( 'Install the requires packages (%s)?\n' % ', '.join(packages) ) in ['y', 'Y']: subprocess.check_call([ 'sudo', 'apt-get', 'install', '--no-install-recommends', ] + packages) else: print( 'WARNING: the package installation works only on Debian ' 'base OS' )
def dump(): rendered = bottle.mako_template('demo') rendered = rendered.replace('/static/', 'static/') with open('index.html', 'w') as f: f.write(rendered)