Coverage for /media/ldata/code/tendril/tendril/frontend/blueprints/gsymlib/views.py: 0%

# Coverage for /media/ldata/code/tendril/tendril/frontend/blueprints/gsymlib/views.py : 0%

## 96 statements 0 run 96 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | # Copyright (C) 2015 Chintalagiri Shashank # # This file is part of Tendril. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ This file is part of tendril See the COPYING, README, and INSTALL files for more information """ import os from urllib import urlencode from urllib2 import unquote from collections import namedtuple from flask import render_template, abort, request from flask_user import login_required import tendril.gedaif.gsymlib from . import gsymlib as blueprint from tendril.utils.fsutils import get_path_breadcrumbs from tendril.utils.fsutils import Crumb from tendril.utils.config import GEDA_SYMLIB_ROOT def is_geda_folder(path): if path is not None: path = os.path.join(GEDA_SYMLIB_ROOT, path) else: path = GEDA_SYMLIB_ROOT if os.path.isdir(path): return True return False Subfolder = namedtuple('Subfolder', 'name path') def get_geda_browser_context(path): if not is_geda_folder(path): abort(404) if path is not None: path = os.path.join(GEDA_SYMLIB_ROOT, path) else: path = GEDA_SYMLIB_ROOT flatten_folders = False flatten_folders_st = 'off' if request.args.get('flattenFolders') == u'on': flatten_folders = True flatten_folders_st = 'on' resolve_generators = False resolve_generators_st = 'off' if request.args.get('resolveGenerators') == u'on': resolve_generators = True resolve_generators_st = 'on' show_generators = True hide_generators = False hide_generators_st = 'off' if request.args.get('hideGenerators') == u'on': show_generators = False hide_generators = True hide_generators_st = 'on' show_images = False show_images_st = 'off' if request.args.get('showImages') == u'on': show_images = True show_images_st = 'on' if not flatten_folders: subfolders = [Subfolder(name=x, path=os.path.relpath(os.path.join(path, x), GEDA_SYMLIB_ROOT)) # noqa for x in os.listdir(path) if os.path.isdir(os.path.join(path, x))] # noqa else: subfolders = [] symbols = tendril.gedaif.gsymlib.gen_symlib(path, include_generators=show_generators, # noqa resolve_generators=resolve_generators, # noqa recursive=flatten_folders) if symbols is None: symbols = [] queryst = urlencode({'showImages': show_images_st, 'hideGenerators': hide_generators_st, 'resolveGenerators': resolve_generators_st, 'flattenFolders': flatten_folders_st}) context = {'path': os.path.relpath(path, GEDA_SYMLIB_ROOT), 'subfolders': sorted(subfolders, key=lambda y: y.name), 'breadcrumbs': get_path_breadcrumbs(path, GEDA_SYMLIB_ROOT, rootst="gEDA Symbol Library"), # noqa 'symbols': sorted(symbols, key=lambda y: y.ident), 'show_images': show_images, 'resolve_generators': resolve_generators, 'hide_generators': hide_generators, 'flatten_folders': flatten_folders, 'query_string': queryst} return context def get_geda_symbol_context(ident): symbol = tendril.gedaif.gsymlib.get_symbol(ident, get_all=True) symbol = [x for x in symbol if x.status != 'Generator'] navpath = os.path.relpath(symbol[0].fpath, GEDA_SYMLIB_ROOT) breadcrumbs = get_path_breadcrumbs(navpath, rootst="gEDA Symbol Library") if symbol[0].is_virtual: breadcrumbs.insert(-1, Crumb(name=os.path.splitext(symbol[0].fname)[0] + '.gen', # noqa path='detail/' + os.path.splitext(symbol[0].fname)[0] + '.gen')) # noqa return {'ident': ident, 'symbol': symbol[0], 'sympaths': [os.path.relpath(sym.fpath, GEDA_SYMLIB_ROOT) for sym in symbol], # noqa 'imgpaths': [sym.img_repr_fname for sym in symbol], 'breadcrumbs': breadcrumbs} def get_geda_generator_context(gen): generator = tendril.gedaif.gsymlib.get_generator(gen) navpath = os.path.relpath(generator.fpath, GEDA_SYMLIB_ROOT) navpath = os.path.splitext(navpath)[0] + '.gen' genobj = tendril.gedaif.gsymlib.GSymGeneratorFile(generator.fpath) return {'genname': gen, 'generator': generator, 'breadcrumbs': get_path_breadcrumbs(navpath, rootst="gEDA Symbol Library"), # noqa 'sympaths': [os.path.relpath(generator.fpath, GEDA_SYMLIB_ROOT)], 'genpath': os.path.relpath(generator.genpath, GEDA_SYMLIB_ROOT), 'genobj': genobj} @blueprint.route('/') @blueprint.route('/detail/<path:gen>.gen') @blueprint.route('/detail/<path:ident>') @blueprint.route('/<path:path>') @login_required def main(path=None, ident=None, gen=None): stage = {'crumbroot': "/gsymlib"} if path is None and ident is None and gen is None: stage.update(get_geda_browser_context(None)) return render_template('gsymlib_browse.html', stage=stage, pagetitle='gEDA Library Browser') if path is not None and is_geda_folder(path): stage.update(get_geda_browser_context(path)) return render_template('gsymlib_browse.html', stage=stage, pagetitle='gEDA Library Browser') if ident is not None: ident = unquote(ident) if ident in tendril.gedaif.gsymlib.gsymlib_idents: stage.update(get_geda_symbol_context(ident)) return render_template('gsymlib_symbol.html', stage=stage, pagetitle='gEDA Symbol Detail') if gen is not None: gen += '.gen' gen = unquote(gen) if gen in tendril.gedaif.gsymlib.generator_names: stage.update(get_geda_generator_context(gen)) return render_template('gsymlib_generator.html', stage=stage, pagetitle='gEDA Generator Detail') abort(404)