def get_loaders(self): """ Returns an array of :class:`napixd.loader.Importer` used to find the managers. """ loaders = [] if 'conf' in self.options: from napixd.loader.importers import ConfImporter ci = ConfImporter(self.conf.get('managers'), self.conf) loaders.append(ci) if 'auto' in self.options: from napixd.loader.auto import AutoImporter auto_path = get_path('auto') logger.info('Using %s as auto directory', auto_path) loaders.append(AutoImporter(auto_path)) if 'recursive' in self.options: from napixd.loader.auto import RecursiveAutoImporter auto_path = get_path('auto') loaders.append(RecursiveAutoImporter(auto_path)) if 'cwd' in self.options: from napixd.loader.auto import RecursiveAutoImporter loaders.append(RecursiveAutoImporter(os.getcwd())) return loaders
def get_conf(self): """ Get the configuration from the configuration file. It set the default conf instance by calling :meth:`napixd.conf.BaseConf.set_default`. """ logger.info('Loading configuration') paths = [ get_path('conf/'), ] if 'dotconf' in self.options: try: from napixd.conf.confiture import ConfFactory except ImportError: raise CannotLaunch('dotconf option requires the external library confiture') factory = ConfFactory() else: from napixd.conf.json import CompatConfFactory factory = CompatConfFactory() loader = ConfLoader(paths, factory) try: conf = loader() except ValueError as e: raise CannotLaunch('Cannot load conf: {0}'.format(e)) return Conf.set_default(conf)
def get_template_name(name): """ Find a unique template name starting with *name* """ name = name.lower() file_name = '{0}.py'.format(name) i = 0 auto_dir = get_path('auto') while os.path.exists(os.path.join(auto_dir, file_name)): i += 1 file_name = '{0}_{1}.py'.format(name, i) return file_name
def get_webclient_path(self): """ Retrieve the web client interface statics path. """ module_file = sys.modules[self.__class__.__module__].__file__ directories = [ self.conf.get('webclient.path'), get_path('web', create=False), os.path.join(os.path.dirname(module_file), 'web'), os.path.join(os.path.dirname(napixd.__file__), 'web'), ] for directory in directories: logger.debug('Try WebClient in directory %s', directory) if directory and os.path.isdir(directory): return directory
def __init__(self, options, auto_guess_wsgi=True, **keys): self.keys = keys nooptions = [opt[2:] for opt in options if opt.startswith('no')] options = set(options) if 'only' not in options: options = options.union(self.DEFAULT_OPTIONS) if auto_guess_wsgi: guessed = None if 'uwsgi' in sys.argv[0]: guessed = 'uwsgi' options.add('uwsgi') elif 'gunicorn' in sys.argv[0]: guessed = 'gunicorn' options.add('gunicorn') self.options = options = TracingSet(options.difference(nooptions)) self.extra_web_client = {} self.set_loggers() self.conf = self.get_conf() if 'loggers' in self.options: self.set_extra_loggers() self.service_name = self.get_service_name() self.hosts = self.get_hostnames() if auto_guess_wsgi: if guessed is None: logger.warning('Cannot guess the WSGI server') else: logger.info('Running from %s', guessed) console.info('Napix version %s', __version__) console.info('Napixd Home is %s', get_path()) console.info('Options are %s', ','.join(sorted(self.options))) console.info('Starting process %s', os.getpid()) console.info('Service Name is %s', self.service_name)
def __init__(self, options): root = options.get('root') self.root = (get_path(root) if root else get_path( os.path.join(self.ROOT, self.__class__.__name__)))
#!/usr/bin/env python # -*- coding: utf-8 -*- import json import napixd from napixd.store import Loader from napixd.conf import ConfLoader from napixd.conf.json import ConfFactory conf_loader = ConfLoader([ napixd.get_path('conf/'), ], ConfFactory()) loader = Loader(conf_loader()) def load(fd, backend, reset=False): store = loader.get_store_backend(backend) if reset: store.drop() document = json.load(fd) store.load(document) def dump(backend, fd, indent): store = loader.get_store_backend(backend) document = store.dump() json.dump(document, fd, indent=indent) def move(source_backend, dest_backend, reset=False):