def __init__(self, home_dir=None): super(Service, self).__init__() self.changes = {} self.home_dir = home_dir = ( os.environ.get("MOYA_SERVICE_HOME", None) or DEFAULT_HOME_DIR ) settings_path = os.path.join(home_dir, "moya.conf") try: with io.open(settings_path, "rt") as f: self.settings = SettingsContainer.read_from_file(f) except IOError: self.error("unable to read {}".format(settings_path)) return -1 logging_setting = self.settings.get("projects", "logging", "logging.ini") logging_path = os.path.join(self.home_dir, logging_setting) try: init_logging(logging_path) except Exception as e: log.error("unable to initialize logging from '%s'", logging_path) sys.stderr.write( "unable to initialize logging from '{}' ({})\n".format(logging_path, e) ) return -1 log.debug("read conf from %s", settings_path) log.debug("read logging from %s", logging_path) temp_dir_root = self.settings.get("service", "temp_dir", tempfile.gettempdir()) self.debug_memory = objgraph and self.settings.get_bool( "service", "debug_memory", False ) self.temp_dir = os.path.join(temp_dir_root, "moyasrv") try: os.makedirs(self.temp_dir) except OSError: pass for path in self._get_projects(self.settings, self.home_dir): log.debug("reading project settings %s", path) try: self.add_project(path) except: log.exception("error adding project from '%s'", path) for server_name in self.servers: path = os.path.join(self.temp_dir, "{}.changes".format(server_name)) try: if not os.path.exists(path): with open(path, "wb"): pass except IOError as e: sys.stderr.write("{}\n".format(text_type(e))) return -1 self.changes[server_name] = os.path.getmtime(path) self.build_all()
def __init__(self, home_dir=None): super(Service, self).__init__() self.changes = {} self.home_dir = home_dir = os.environ.get('MOYA_SERVICE_HOME', None) or DEFAULT_HOME_DIR settings_path = os.path.join(home_dir, 'moya.conf') try: with io.open(settings_path, 'rt') as f: self.settings = SettingsContainer.read_from_file(f) except IOError: self.error('unable to read {}'.format(settings_path)) return -1 logging_setting = self.settings.get('projects', 'logging', 'logging.ini') logging_path = os.path.join(self.home_dir, logging_setting) try: init_logging(logging_path) except Exception as e: log.error("unable to initialize logging from '%s'", logging_path) sys.stderr.write( "unable to initialize logging from '{}' ({})\n".format( logging_path, e)) return -1 log.debug('read conf from %s', settings_path) log.debug('read logging from %s', logging_path) temp_dir_root = self.settings.get('service', 'temp_dir', tempfile.gettempdir()) self.temp_dir = os.path.join(temp_dir_root, 'moyasrv') try: os.makedirs(self.temp_dir) except OSError: pass for path in self._get_projects(self.settings, self.home_dir): log.debug('reading project settings %s', path) try: self.add_project(path) except: log.exception("error adding project from '%s'", path) for server_name in self.servers: path = os.path.join(self.temp_dir, "{}.changes".format(server_name)) try: if not os.path.exists(path): with open(path, 'wb'): pass except IOError as e: sys.stderr.write("{}\n".format(text_type(e))) return -1 self.changes[server_name] = os.path.getmtime(path) self.build_all()
def __init__(self, home_dir=None): super(Service, self).__init__() self.changes = {} self.home_dir = home_dir = os.environ.get('MOYA_SRV_HOME', None) or DEFAULT_HOME_DIR settings_path = os.path.join(home_dir, 'moya.conf') try: with io.open(settings_path, 'rt') as f: self.settings = SettingsContainer.read_from_file(f) except IOError: self.error('unable to read {}'.format(settings_path)) return -1 logging_setting = self.settings.get('projects', 'logging', 'logging.ini') logging_path = os.path.join(self.home_dir, logging_setting) try: init_logging(logging_path) except Exception as e: log.exception('error reading logging') log.debug('read conf from %s', settings_path) log.debug('read logging from %s', logging_path) temp_dir_root = self.settings.get('service', 'temp_dir', tempfile.gettempdir()) self.temp_dir = os.path.join(temp_dir_root, 'moyasrv') try: os.makedirs(self.temp_dir) except OSError: pass for path in self._get_projects(): log.debug('reading project settings %s', path) try: self.add_project(path) except: log.exception("error adding project from '%s'", path) for server_name in self.servers: path = os.path.join(self.temp_dir, "{}.changes".format(server_name)) try: if not os.path.exists(path): with open(path, 'wb'): pass except IOError as e: sys.stderr.write("{}\n".format(text_type(e))) return -1 self.changes[server_name] = os.path.getmtime(path) self.build_all()
def test_init(self): """Test reading logging conf""" loggingconf.init_logging(join(self.path, 'logging.ini')) loggingconf.init_logging(join(self.path, 'extend.ini'))