def get(self, actionType, encFilePath): filePath = unescape(encFilePath) logging.debug("Action (%s) File(%s)" % (actionType, filePath)) if (actionType == "play"): try: logging.debug("Playing: %s" % filePath) pB_audio.playSong(filePath) except Exception, e: logging.error("Exception raised from playListModify") logging.error(traceback.format_exc())
def get(self, search): loader = tornado.template.Loader('templates/') # parse the query try: parsed = ply.yacc.parse(unescape(search)) ((query, args), typeofdata) = convert(parsed) # execute the query conn = sqlite3.connect('db.sqlite') cur = conn.cursor() cur.execute(query, *(args,)) results = cur.fetchall() cur.close() self.write(loader.load('search_results.html').generate(results=results, typeofdata=typeofdata)) except QueryError as e: self.write('Your query was incorrect: %s' % e.message)
def _index(): # Gather, convert and process assets DOCTYPE = '<!DOCTYPE html>' style = StringIO() head = E.HEAD() body = E.BODY() templates = [] template_names = [] def visit(node, f): for c in node.getchildren(): visit(c, f) if c.tag != 'template': continue names = [n[1:] for n in c.keys() if n and n[0] == ':'] if not names: _log.error('Unbound template found (%s)', f) continue for name in names: if name in template_names: _log.error('Duplicate template "%s" found (%s)', name, f) continue template = E.SCRIPT( id='template-{0}'.format(name), type='text/x-angulate-template' ) template.text = c.text template.extend(c.getchildren()) templates.append(template) template_names.extend(names) node.remove(c) return for dirpath, dirnames, filenames in os.walk(_view_path): for filename in filenames: ext = os.path.splitext(filename)[-1] filename = os.path.join(dirpath, filename) handler = build.style_handler.get(ext) if handler: style.write(handler(filename)) continue handler = build.template_handler.get(ext) if not handler: continue contents = handler(filename) if not contents: _log.warning('View is empty (%s)', filename) continue try: dom = html.fromstring('<head></head>' + contents) except Exception as e: _log.error('Parse error (%s) %s', filename, e) continue for e in dom.getchildren(): if e.tag == 'head': head.extend(e.getchildren()) elif e.tag == 'body': visit(e, filename) body.text = (body.text or '') + (e.text or '') body.extend(e.getchildren()) elif e.tag == 'template': visit(E.BODY(e), filename) else: _log.error('View is invalid (%s)', filename) continue s = 'angulate.registerTemplate("{0}", "{1}");' templates.append( E.SCRIPT( '\n'.join([ s.format(name, 'template-{0}'.format(name)) for name in template_names ]), type='text/javascript')) # Append styles head.append(E.STYLE(style.getvalue())) # Append compiled runtime and Javascript functions body.extend([ E.SCRIPT( compiler.runtime(), type='text/javascript'), E.SCRIPT( '\n'.join(f for f in client.compiled()), type='text/javascript') ]) # Append bundle for b in _bundle_files: assert len(b) in [2, 3], 'Invalid bundle file config' if len(b) == 2: body.append(E.SCRIPT( src='bundle/{0}'.format(b[1]), type='text/javascript')) elif _cdn: link = html.tostring(E.SCRIPT( src='bundle/{0}'.format(b[2]), type='text/javascript' ), encoding='utf-8') link = link.decode('utf-8').replace('</script>', '<\/script>') body.extend([ E.SCRIPT( src=b[1], type='text/javascript'), E.SCRIPT( "window.{0} || document.write('{1}')".format(b[0], link), type='text/javascript') ]) else: body.append(E.SCRIPT( src='bundle/{0}'.format(b[2]), type='text/javascript')) # Append templates body.extend(templates) # Bootstrap angular body.append(E.SCRIPT( '\n'.join([ 'window.app = angular.module("app", ["ngAnimate", "angulate"]);', 'window.app.run(["$rootScope", function($rootScope) {', ' $rootScope._session = avalon.session;', ' avalon.scope = $rootScope;' '}])', 'angular.bootstrap(document, ["app"]);' ]), type='text/javascript')) return unescape(html.tostring(E.HTML(head, body), doctype=DOCTYPE, encoding='utf-8'))