コード例 #1
0
ファイル: test_logger.py プロジェクト: kerwin612/RepoGuard
    def setup_method(self, _):
        # Make sure that it has not been yet instantiated
        LoggerFactory._instance = None
        logging.root = logging.RootLogger(logging.WARNING)
        logging.Logger.root = logging.root

        self.factory = LoggerFactory(config=_LOGGER_CONFIG.splitlines())
        assert self.factory.create().root.handlers
        assert id(self.factory) == id(LoggerFactory())
コード例 #2
0
ファイル: checker.py プロジェクト: kerwin612/RepoGuard
    def checker(hook, repo_path, txn_name, profile_name, halt_on_exception):
        """
        Function to singularize the repoguard in precommit or postcommit mode.
        
        :param hook: Execute the repoguard as pre- or postcommit.
        :type hook: string
        
        :param repo_path: The path to the repository.
        :type repo_path: string
        
        :param txn_name: The name of the current transaction.
        :type txn_name: string
        
        :param halt_on_exception: Flag which indicates whether we halt on unexpected exceptions or not.
        :type halt_on_exception: boolean
        """
        
        logger = LoggerFactory().create('%s.tools.checker' % constants.NAME)
        try:
            hooks_path = os.path.abspath(os.path.join(repo_path, "hooks"))
            project_config = os.path.join(hooks_path, constants.CONFIG_FILENAME)
            os.chdir(hooks_path)
            
            logger.debug("RepoGuard initializing...")
            repoguard = RepoGuard(hook, repo_path)
        
            logger.debug("Loading transaction...")
            repoguard.load_transaction(txn_name)
    
            logger.debug("Loading configuration...")
            main_config = RepoGuardConfig(constants.CONFIG_PATH)
            repoguard.load_config(main_config.template_dirs, project_config)
            
            logger.debug("Validating configuration...")
            if main_config.validate:
                repoguard.validate()
            else:
                logger.warning("Validation skipped.")
            
            logger.debug("RepoGuard running...")
            if profile_name:
                result = repoguard.run_profile(profile_name)
            else:   
                result = repoguard.run()

            logger.debug("RepoGuard finished with %s.", result)
            if result == constants.SUCCESS:
                return 0
            else:
                return 1
        except validate.ValidateError:
            logger.exception("The configuration is invalid!")
            return 1
        except: # pylint: disable=W0702
            logger.exception(
                "An unexpected error occurred during the RepoGuard run! Halt on exception is '%s'." % halt_on_exception)
            if not halt_on_exception:
                return 0
            else:
                return 1
コード例 #3
0
ファイル: validator.py プロジェクト: kerwin612/RepoGuard
    def __init__(self, propagate=1, override=None, excepts=False):
        """
        Constructor.
        
        :param propagate: If this evaluates to false, logging messages are not 
                          passed by this logger or by child loggers to higher 
                          level (ancestor) loggers.
        :type propagate: boolean
        
        :param override: Overrides the default log level for the intern logger.
        :type override: NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL
        """

        Validator.__init__(self)

        self.check_regex = re.compile(constants.CHECK_REGEX)
        self.handler_regex = re.compile(constants.HANDLER_REGEX)

        self.default_profile = False
        self.main = None
        self.errors = 0
        self.excepts = excepts

        self.valid_checks = []
        self.valid_handlers = []

        self.logger = LoggerFactory().create(self.__module__, propagate,
                                             override)

        self.check_manager = CheckManager()
        self.handler_manager = HandlerManager()
コード例 #4
0
ファイル: checker.py プロジェクト: kerwin612/RepoGuard
    def __init__(self, hook, repository_path):
        """
        Constructor.
        
        :param hook: The hook that has to be executed. Valid values are 
                     constants.PRECOMMIT or constants.POSTCOMMIT.
        :type hook: constants.PRECOMMIT, constants.POSTCOMMIT.
        :param repository_path: The path to the current repository.
        :type repository_path: string
        """

        self.hook = hook
        self.repository_path = repository_path

        self.checks = CheckManager()
        self.handlers = HandlerManager()
        self.result = constants.SUCCESS
        self.main = None
        self.transaction = None

        self.logger = LoggerFactory().create(self.__module__)
コード例 #5
0
ファイル: config.py プロジェクト: kerwin612/RepoGuard
    def validate(self, parser):
        """
        Validates repoguard configuration files.
        
        :param parser: Command line parser.
        :type parser: optparse object.
        """

        parser.add_option("-q",
                          "--quiet",
                          action="store_false",
                          dest="verbose",
                          help="be vewwy quiet (I'm hunting wabbits).",
                          default=True)
        options, args = parser.parse_args()

        if len(args) != 2:
            parser.print_help()
            return 1

        path = args[1]

        logging.basicConfig(format="%(message)s")
        logger = LoggerFactory().create('%s.tools.config' % constants.NAME)
        if options.verbose:
            level = logger.level
        else:
            level = logging.CRITICAL
        main_config = RepoGuardConfig(constants.CONFIG_PATH)
        config_validator = ConfigValidator(override=level)
        config_obj = ProjectConfig(path,
                                   template_dirs=main_config.template_dirs)
        for extend, path in config_obj.extended.iteritems():
            logger.info("Extending %s (%s)", extend, path)
        else:
            logger.info("Nothing to extend.")
        if config_validator.validate(config_obj):
            return 0
        else:
            return 1
コード例 #6
0
    def __new__(cls, transaction):
        """
        Overriden __new__ method that handles the automatic transaction
        iniialisation.
        
        :param cls: The class that has to be created.
        :type cls: Module
        
        :param transaction: The current transaction for this module.
        :type transaction: C{Transaction}
        
        :return: Returns the created module object.
        :rtype: Module
        """

        obj = super(Module, cls).__new__(cls)

        # Initialize transaction.
        obj.transaction = transaction

        # Generate an own logger for every module.
        obj.logger = LoggerFactory().create(cls.__module__)

        return obj