示例#1
0
    def store_config(self, args):
        """ Stores the config options in a config file for a later use.
        """

        # stdlib
        import os
        from io import StringIO

        # Zato
        from zato.common.util.file_system import fs_safe_now

        now = fs_safe_now()  # noqa
        file_name = 'zato.{}.config'.format(now)
        file_args = StringIO()

        for arg, value in args._get_kwargs():
            if value:
                file_args.write('{}={}\n'.format(arg, value))

        body = '# {} - {}\n{}'.format(now, self._get_user_host(),
                                      file_args.getvalue())

        open(file_name, 'w').write(body)
        file_args.close()

        self.logger.debug('Options saved in file {file_name}'.format(
            file_name=os.path.abspath(file_name)))
示例#2
0
    def reset_logger(self, args, reload_=False):

        # stdlib
        import logging
        import sys
        from imp import reload

        # Zato
        from zato.common.util.file_system import fs_safe_now

        if reload_:
            logging.shutdown()  # noqa
            reload(logging)  # noqa

        self.logger = logging.getLogger(self.__class__.__name__)  # noqa
        self.logger.setLevel(
            logging.DEBUG if self.verbose else logging.INFO)  # noqa
        self.logger.handlers[:] = []

        console_handler = logging.StreamHandler(sys.stdout)  # noqa
        console_formatter = logging.Formatter('%(message)s')  # noqa
        console_handler.setFormatter(console_formatter)
        self.logger.addHandler(console_handler)

        if args.store_log:
            verbose_handler = logging.FileHandler('zato.{}.log'.format(
                fs_safe_now()))  # noqa
            verbose_formatter = logging.Formatter(
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s')  # noqa
            verbose_handler.setFormatter(verbose_formatter)
            self.logger.addHandler(verbose_handler)
示例#3
0
文件: __init__.py 项目: danlg/zato
    def backup_current_work_dir(self):

        # Save a few keystrokes
        last_backup_work_dir = self.server.hot_deploy_config.last_backup_work_dir
        current_work_dir = self.server.hot_deploy_config.current_work_dir
        backup_work_dir = self.server.hot_deploy_config.backup_work_dir
        backup_history = self.server.hot_deploy_config.backup_history
        backup_format = self.server.hot_deploy_config.backup_format

        # Safe to use as a directory name
        fs_now = fs_safe_now()

        # Store the last backup
        self._backup_last(fs_now, current_work_dir, backup_format,
                          last_backup_work_dir)

        # Now store the same thing in the linear log of backups
        self._backup_linear_log(fs_now, current_work_dir, backup_format,
                                backup_work_dir, backup_history)
示例#4
0
    def execute(self, args):

        # stdlib
        import os
        from shutil import rmtree

        # Zato
        from zato.common.util.api import get_client_from_server_conf
        from zato.common.util.file_system import fs_safe_now

        client = get_client_from_server_conf(args.path)

        exclude = args.exclude.split(',') or []
        exclude = [elem.strip() for elem in exclude]

        tags = args.tags.split(',')
        tags = [elem.strip() for elem in tags]

        if args.with_internal:
            for item in internal_patterns:
                try:
                    exclude.remove(item)
                except ValueError:
                    pass

        request = {
            'return_internal': args.with_internal,
            'include': args.include,
            'exclude': ','.join(exclude),
            'needs_api_invoke': args.with_api_invoke,
            'needs_rest_channels': args.with_rest_channels,
            'tags': tags,
        }

        if args.with_api_invoke:
            request[
                'api_invoke_path'] = args.api_invoke_path if args.api_invoke_path else '/zato/api/invoke/{service_name}'

        if not args.dir:
            now = fs_safe_now()
            out_dir = '{}.{}'.format('apispec', now)
        else:
            out_dir = args.dir

        out_dir = os.path.abspath(out_dir)

        if os.path.exists(out_dir):
            if args.delete_dir:
                self.logger.info('Deleting %s', out_dir)
                rmtree(out_dir)
            else:
                self.logger.warn(
                    'Output directory %s already exists and --delete-dir was not provided',
                    out_dir)
                return

        os.mkdir(out_dir)

        response = client.invoke('zato.apispec.get-api-spec', request)
        data = response.data['response']['data']

        for file_path, contents in data.items():
            full_file_path = os.path.join(out_dir, file_path)
            file_dir = os.path.abspath(os.path.dirname(full_file_path))
            try:
                os.makedirs(file_dir)
            except OSError:
                pass  # Must have been already created
            finally:
                if contents:
                    f = open(full_file_path, 'w')
                    f.write(contents)
                    f.close()

        self.logger.info('Output saved to %s', out_dir)
        self.logger.info('To build the documentation, run:\ncd %s\nmake html',
                         out_dir)