Example #1
0
 def setUp(self):
     path = os.path.abspath(os.path.dirname(__file__))
     templates_path = join(path, "templates")
     self.fs = fsopendir(templates_path)
     self.archive = Archive()
     self.archive.init_cache("templates", SettingsContainer.create(type="dict"))
     self.archive.init_cache("fragment", SettingsContainer.create(type="dict"))
     self.engine = MoyaTemplateEngine(self.archive, self.fs, {})
Example #2
0
    def run(self):
        parser = self.get_argparse()
        self.args = args = parser.parse_args(sys.argv[1:])
        self.console = Console()

        if args.subcommand not in ['install']:
            self.home_dir = args.home or os.environ.get(
                'MOYA_SERVICE_HOME', None) or DEFAULT_HOME_DIR
            settings_path = os.path.join(self.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

        method_name = "run_" + args.subcommand.replace('-', '_')
        try:
            return getattr(self, method_name)() or 0
        except CommandError as e:
            self.error(text_type(e))
        except Exception as e:
            if args.debug:
                raise
            self.error(text_type(e))
Example #3
0
    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()
Example #4
0
    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()
Example #5
0
    def load(self):
        settings = SettingsContainer.read_os(self.settings_path)

        self.name = settings.get('service', 'name')
        self.domains = settings.get_list('service', 'domains')
        self.location = settings.get('service', 'location')
        self.ini = settings.get_list('service', 'ini') or ['production.ini']

        self.master_settings = settings
Example #6
0
    def load(self):
        settings = SettingsContainer.read_os(self.settings_path)

        self.name = settings.get('service', 'name')
        self.domains = settings.get_list('service', 'domains')
        self.location = settings.get('service', 'location')
        self.ini = settings.get_list('service', 'ini') or ['production.ini']

        self.master_settings = settings
Example #7
0
    def load(self):
        settings = SettingsContainer.read_os(self.settings_path)

        self.name = settings.get("service", "name")
        self.domains = settings.get_list("service", "domains")
        self.location = settings.get("service", "location")
        self.ini = settings.get_list("service", "ini") or ["production.ini"]

        self.master_settings = settings
Example #8
0
    def get_project_settings(cls, project_name):
        """Get the settings for a single project"""
        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:
                service_settings = SettingsContainer.read_from_file(f)
        except IOError:
            log.error("unable to read moya service settings from '{}'", settings_path)
            return -1

        for path in cls._get_projects(service_settings, home_dir):
            try:
                settings = SettingsContainer.read_os(path)
            except Exception as e:
                log.error("error reading '%s' (%s)", path, e)
            if settings.get("service", "name", None) == project_name:
                return settings
        return None
Example #9
0
    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()
Example #10
0
    def run(self):
        parser = self.get_argparse()
        self.args = args = parser.parse_args(sys.argv[1:])
        self.console = Console()

        self.home_dir = args.home or os.environ.get('MOYA_SRV_HOME', None) or DEFAULT_HOME_DIR

        settings_path = os.path.join(self.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

        method_name = "run_" + args.subcommand.replace('-', '_')
        try:
            return getattr(self, method_name)() or 0
        except CommandError as e:
            self.error(text_type(e))
        except Exception as e:
            if args.debug:
                raise
            self.error(text_type(e))
Example #11
0
 def read_project(self, path):
     settings = SettingsContainer.read_os(path)
     return settings
Example #12
0
 def read_project(self, path):
     settings = SettingsContainer.read_os(path)
     return settings