⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 navtemplate.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
字号:
#!/usr/bin/env python# -*- coding: ISO8859-1 -*-## Copyright 2003, 2004 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV 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 General Public License for more details.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA### $Id: navTemplate.py 3388 2006-03-14 12:32:56Z mortenv $# Authors: Morten Vold <morten.vold@itea.ntnu.no>#"""This script enables external (i.e. non-Python) NAV systems to retrieveand fill the contents of the MainTemplate Cheetah template."""import sys, osfrom nav import db, webimport nav.web.authfrom nav.db import navprofilesfrom nav.web.templates.MainTemplate import MainTemplatedef main(argv):    vars = {}    for arg in argv:        key, value = arg.split('=', 1)        vars[key] = value    if not vars.has_key('user'):        vars['user'] = 0            page = MainTemplate()    for key, value in vars.items():        # Make some special considerations for special variable names.  Anything        if key == "user":            conn = db.getConnection('navprofile', 'navprofile')            try:                id = int(value)                account = navprofiles.Account(value)                account.load()            except ValueError, TypeError:                account = navprofiles.Account.loadByLogin(value)            nav.web.auth._find_user_preferences(account, None)            page.user = account        elif key == "content":            func = lambda : vars['content']            setattr(page, key, func)        elif key == "path":            path = [ ("Home", "/") ]            list = value.split(':')            if len(list) % 2 != 0:                raise "element count of 'path' must be an even number"            while len(list) > 0:                text = list.pop(0)                url = list.pop(0)                path.append( (text, url) )            page.path = path        else:            setattr(page, key, value)    print pagedef usage():    """Print a usage summary to stderr"""    summary = """Usage: navTemplate.py [--help] [variable=value] ...Retrieves the NAV web MainTemplate and fills the variables of thetemplate according to the supplied arguments.Special variables:    user   - An account login or id; alters the contents of the             returned page according to this users settings.    path   - A list of name/url pairs that describe the path browsed             to get to this page.  The input should be formatted as:             "name:url:name:url ...".  The output will always prefix             this list with the front page url.  The last url element             may and should be omitted, as no link to the current page             is required.    content - The actual content of the page returned."""    sys.stderr.write(summary)if __name__ == '__main__':    if '--help' in sys.argv:        usage()    else:        main(sys.argv[1:])else:    raise "This module is runtime only, should not be imported"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -