def get_context_data(self, **kwargs): context = super(LinkListNavlet, self).get_context_data(**kwargs) nav_links = read_flat_config(NAV_LINKS_PATH) context['nav_links'] = nav_links context['half'] = math.ceil(len(nav_links) / 2.0) return context
def get_connection_parameters(script_name='default', database='nav'): """Return a tuple of database connection parameters. The parameters are read from db.conf, using script_name as a lookup key to find the database user to log in as. :returns: A tuple containing the following elements: (dbhost, dbport, dbname, user, password) """ # Get the config setup for the requested connection conf = config.read_flat_config('db.conf') dbhost = conf['dbhost'] dbport = conf['dbport'] db_option = 'db_%s' % database if db_option not in conf: _logger.debug("connection parameter for database %s doesn't exist, " "reverting to default 'db_nav'", database) db_option = 'db_nav' dbname = conf[db_option] user_option = 'script_%s' % script_name if user_option not in conf: _logger.debug("connection parameter for script %s doesn't exist, " "reverting to default", script_name) user_option = 'script_default' user = conf[user_option] password = conf['userpw_%s' % user] return dbhost, dbport, dbname, user, password
def test_read_flat_config(self): values = config.read_flat_config(self.mockfile) self.assertEquals(values['foo1'], 'bar1') self.assertEquals(values['foo2'], 'bar2') self.assertEquals(values['foo4'], 'bar4') self.assertFalse(values.has_key('foo3'))
import nav from nav.config import read_flat_config from nav.django.utils import get_account from nav.models.logger import LogMessage from nav.models.logger import ErrorError from nav.web.syslogger.forms import LoggerGroupSearchForm from nav.web.utils import create_title DATEFORMAT = "%Y-%m-%d %H:%M:%S" try: DOMAIN_SUFFICES = read_flat_config("nav.conf")["DOMAIN_SUFFIX"].split(",") except IOError: DOMAIN_SUFFICES = [] DOMAIN_SUFFICES = [s.strip() for s in DOMAIN_SUFFICES] logger = logging.getLogger("nav.web.syslogger") def _strip_empty_arguments(request): """Strips empty arguments and their related operator arguments from the QueryDict in request.GET and returns a new, possibly modified QueryDict. """ query = request.GET.copy() deletable = [key for key, value in query.iteritems() if not value.strip()]
import logging import nav from nav.config import read_flat_config from nav.metrics.data import get_metric_average from nav.metrics.errors import GraphiteUnreachableError from nav.metrics.graphs import get_metric_meta from nav.metrics.templates import (metric_path_for_interface, metric_path_for_cpu_load, metric_path_for_cpu_utilization) from nav.web.geomap.utils import lazy_dict, subdict, fix _logger = logging.getLogger(__name__) try: _nav_conf = read_flat_config('nav.conf') except IOError: _nav_conf = {} _domain_suffix = _nav_conf.get('DOMAIN_SUFFIX', None) def get_data(db_cursor, bounds, time_interval=None): """Reads data from database. Returns a pair of dictionaries (netboxes, connections). netboxes contains a 'lazy dictionary' (see class lazy_dict in utils.py) with information for each netbox; connections contains two lazy dictionaries for each connection (one representing each end). (The reason for using lazy_dict is that this allows postponing reading of RRD files until we know it is necessary, while still keeping the code for reading them here).
# details. You should have received a copy of the GNU General Public License # along with NAV. If not, see <http://www.gnu.org/licenses/>. # """Django configuration wrapper around the NAV configuration files""" import os import sys from nav.config import read_flat_config, getconfig from nav.db import get_connection_parameters import nav.buildconf ALLOWED_HOSTS = ['*'] try: nav_config = read_flat_config('nav.conf') except IOError: nav_config = {'SECRET_KEY': 'Very bad default value'} try: webfront_config = getconfig('webfront/webfront.conf', configfolder=nav.buildconf.sysconfdir) except IOError: webfront_config = {} DEBUG = nav_config.get('DJANGO_DEBUG', 'False').upper() in ('TRUE', 'YES', 'ON') TEMPLATE_DEBUG = DEBUG # XXX Pre Django 1.8 # Admins
from django.shortcuts import render_to_response import nav from nav.config import read_flat_config from nav.django.utils import get_account from nav.models.logger import LogMessage from nav.models.logger import ErrorError from nav.web.syslogger.forms import LoggerGroupSearchForm from nav.web.utils import create_title DATEFORMAT = "%Y-%m-%d %H:%M:%S" try: DOMAIN_SUFFICES = read_flat_config("nav.conf")["DOMAIN_SUFFIX"].split(",") except IOError: DOMAIN_SUFFICES = [] DOMAIN_SUFFICES = [s.strip() for s in DOMAIN_SUFFICES] logger = logging.getLogger("nav.web.syslogger") def _strip_empty_arguments(request): """Strips empty arguments and their related operator arguments from the QueryDict in request.GET and returns a new, possibly modified QueryDict. """ query = request.GET.copy() deletable = (key for key, value in query.items() if not value.strip())