Login | Register
My pages Projects Community openCollabNet

Discussions > Commits > svn commit: r144 - trunk/repoguard: src/repoguard/core src/repoguard/tools test/repoguard_test/core

repoguard
Discussion topic

Back to topic list

svn commit: r144 - trunk/repoguard: src/repoguard/core src/repoguard/tools test/repoguard_test/core

Author schlauch
Full name Tobias Schlauch
Date 2012-10-10 14:05:41 PDT
Message Author: schlauch
Date: 2012-10-10 14:05:40-0700
New Revision: 144

Modified:
   trunk/repoguard/src/​repoguard/core/check​er.py
   trunk/repoguard/src/​repoguard/tools/chec​ker.py
   trunk/repoguard/test​/repoguard_test/core​/test_checker.py

Log:
Fixes ISSUE #48:
- Introduced run_profile method to clearly separate stand-alone and transaction-specific usage. This method just executes the the profile but does not check the regular expression constraint.
- Added option -p to for the precommit/postcommit command to make use of it.

Modified: trunk/repoguard/src/​repoguard/core/check​er.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/src/repoguar​d/core/checker.py?vi​ew=diff&pathrev=​144&r1=143&r​2=144
====================​====================​====================​==================
--- trunk/repoguard/src/​repoguard/core/check​er.py (original)
+++ trunk/repoguard/src/​repoguard/core/check​er.py 2012-10-10 14:05:40-0700
@@ -118,73 +118,97 @@
         :rtype: constants.SUCCESS, constants.ERROR
         """
         
- self.logger.debug("Running run...")
- combined_profile_regexes = self._combined_profi​le_regexes()
- self.logger.debug("Default ignore regex: %s", combined_profile_regexes)
-
- # Process executing
- for profile in self.main.profiles:
- self.logger.debug("Running profile '%s'...", profile.name)
- ignores = list()
- if not profile.regex is None:
- self.transaction.profile = profile.regex
- else:
- # default profile: covers all files
- # which are not handled by a special profile
- self.transaction.profile = ".*"
- if not combined_profile_regexes is None:
- ignores = [combined_profile_regexes]
+ try:
+ self.logger.debug("Running run...")
+ combined_profile_regexes = self._combined_profi​le_regexes()
+ self.logger.debug("Default ignore regex: %s", combined_profile_regexes)
+
+ # Process executing
+ for profile in self.main.profiles:
+ ignores = list()
+ if not profile.regex is None:
+ self.transaction.profile = profile.regex
+ else:
+ # default profile: covers all files
+ # which are not handled by a special profile
+ self.transaction.profile = ".*"
+ if not combined_profile_regexes is None:
+ ignores = [combined_profile_regexes]
+
+ # if there are no files in this profile continue.
+ if not self.transaction.get​_files(ignore_list=i​gnores):
+ self.logger.debug("Profile '%s' skipped.", profile.name)
+ continue
+ self._run_profile(profile)
                 
- # if there are no files in this profile continue. However, we should give the default profile a chance!
- if not self.transaction.get​_files(ignore_list=i​gnores) and profile.name != "default":
- self.logger.debug("Profile '%s' skipped.", profile.name)
- continue
+ self.logger.debug("Run finished with %s.", self.result)
+ return self.result
+ finally:
+ self.logger.debug("Cleaning up transaction.")
+ self.transaction.cleanup()
+
+ def run_profile(self, name):
+ """ Runs a specific profile. """
+
+ try:
+ profile_found = False
+ for profile in self.main.profiles:
+ if name == profile.name:
+ self._run_profile(profile)
+ profile_found = True
+
+ if not profile_found:
+ self.result = constants.ERROR
+ self.logger.error("No profile with name '%s' exists." % name)
+ else:
+ self.logger.debug("Run finished with %s.", self.result)
+ return self.result
+ finally:
+ self.logger.debug("Cleaning up transaction.")
+ self.transaction.cleanup()
+
+ def _run_profile(self, profile):
+ process = profile.get_process(self.hook)
+ if not process:
+ self.logger.debug(
+ "%s process skipped." % self.hook.capitalize()
+ )
+ return
+
+ self.logger.debug("Running profile '%s'...", profile.name)
+ protocol = Protocol(profile.name)
+ # run the configured checks
+ for name, config, interp in process.checks:
+ self.logger.debug("Loading check %s...", name)
+ check = self.checks.fetch(name, self.transaction)
+ self.logger.debug("Starting check %s...", name)
+ entry = check.run(config, interp)
+ self.logger.debug(
+ "Check %s finished with %s.", name, entry.result
+ )
+ protocol.append(entry)
             
- process = profile.get_process(self.hook)
- if not process:
+ # run the configured handlers when a message was returned
+ if entry.msg:
                 self.logger.debug(
- "%s process skipped." % self.hook.capitalize()
+ "Running handler after check %s...", entry.check
                 )
- continue
-
- protocol = Protocol(profile.name)
- # run the configured checks
- for name, config, interp in process.checks:
- self.logger.debug("Loading check %s...", name)
- check = self.checks.fetch(name, self.transaction)
- self.logger.debug("Starting check %s...", name)
- entry = check.run(config, interp)
+ self.handlers.singul​arize(self.transacti​on, process, entry)
                 self.logger.debug(
- "Check %s finished with %s.", name, entry.result
+ "Handler after check %s finished.", entry.check
                 )
- protocol.append(entry)
-
- # run the configured handlers when a message was returned
- if entry.msg:
- self.logger.debug(
- "Running handler after check %s...", entry.check
- )
- self.handlers.singul​arize(self.transacti​on, process, entry)
- self.logger.debug(
- "Handler after check %s finished.", entry.check
- )
-
- # cancel the _process chain when an abortonerror was detected.
- if interp == constants.ABORTONERROR and not protocol.success:
- msg = "Profile %s aborted after check %s."
- self.logger.debug(msg, profile.name, entry.check)
- break
-
- # cumulativ execution of all handlers.
- self.logger.debug("Running handler summarize...")
- self.handlers.summar​ize(self.transaction​, process, protocol)
- self.logger.debug("Handler summarize finished.")
             
- if not protocol.success:
- self.result = constants.ERROR
- self.logger.debug("Profile %s finished.", profile.name)
+ # cancel the _process chain when an abortonerror was detected.
+ if interp == constants.ABORTONERROR and not protocol.success:
+ msg = "Profile %s aborted after check %s."
+ self.logger.debug(msg, profile.name, entry.check)
+ break
+
+ # cumulativ execution of all handlers.
+ self.logger.debug("Running handler summarize...")
+ self.handlers.summar​ize(self.transaction​, process, protocol)
+ self.logger.debug("Handler summarize finished.")
         
- self.logger.debug("Cleaning up transaction.")
- self.transaction.cleanup()
- self.logger.debug("Run finished with %s.", self.result)
- return self.result
+ if not protocol.success:
+ self.result = constants.ERROR
+ self.logger.debug("Profile %s finished.", profile.name)

Modified: trunk/repoguard/src/​repoguard/tools/chec​ker.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/src/repoguar​d/tools/checker.py?v​iew=diff&pathrev​=144&r1=143&​r2=144
====================​====================​====================​==================
--- trunk/repoguard/src/​repoguard/tools/chec​ker.py (original)
+++ trunk/repoguard/src/​repoguard/tools/chec​ker.py 2012-10-10 14:05:40-0700
@@ -31,8 +31,8 @@
 from repoguard.tools.base import Tool
 
 
-description = "Runs the %s as %s." % (constants.NAME, '%s')
-usage = """
+_DESCRIPTION = "Runs the %s as %s." % (constants.NAME, '%s')
+_USAGE = """
   repoguard %s [options] repo_path [txn_name]
 Arguments:
   repo_path\tThe path to this repository
@@ -49,21 +49,17 @@
     """
     
     def __init__(self):
- """
- Constructor.
- """
-
         Tool.__init__(self, "Checker tools v0.1")
         
     @Tool.command_method(
         command = constants.PRECOMMIT,
- description = description % constants.PRECOMMIT,
- usage = usage % constants.PRECOMMIT
+ description = _DESCRIPTION % constants.PRECOMMIT,
+ usage = _USAGE % constants.PRECOMMIT
     )
     @Tool.command_method(
         command = constants.POSTCOMMIT,
- description = description % constants.POSTCOMMIT,
- usage = usage % constants.POSTCOMMIT
+ description = _DESCRIPTION % constants.POSTCOMMIT,
+ usage = _USAGE % constants.POSTCOMMIT
     )
     def commit(self, parser):
         """
@@ -76,7 +72,12 @@
         :rtype: 0 for success else error.
         """
         
- args = parser.parse_args()[1]
+ parser.add_option(
+ "-p", "--profile", dest="profile_name", default=None,
+ help="Concrete profile which should be executed."
+ )
+
+ options, args = parser.parse_args()
         if not len(args) in [2, 3]:
             parser.print_help()
             return 1
@@ -85,10 +86,10 @@
         if len(args) == 2:
             hook, repo_path = args
             txn_name = None
-
- return self.checker(hook, repo_path, txn_name)
+ return self.checker(hook, repo_path, txn_name, options.profile_name)
     
- def checker(self, hook, repo_path, txn_name):
+ @staticmethod
+ def checker(hook, repo_path, txn_name, profile_name):
         """
         Function to singularize the repoguard in precommit or postcommit mode.
         
@@ -114,28 +115,32 @@
         logger.debug("RepoGuard initializing...")
         repoguard = RepoGuard(hook, repo_path)
         try:
- try:
- logger.debug("Loading transaction...")
- repoguard.load_trans​action(txn_name)
-
- logger.debug("Loading configuration...")
- main_config = RepoGuardConfig(cons​tants.CONFIG_PATH)
- repoguard.load_confi​g(main_config.templa​te_dirs, project_config)
- if main_config.validate:
- repoguard.validate()
- else:
- logger.warning("Validation skipped.")
- logger.debug("RepoGuard running...")
- result = repoguard.run()
- except ValidateError, exc:
- msg = "Configuration validation error cause: %s"
- logger.exception(msg, str(exc))
- except Exception, exc:
- msg = "%s exception cause: '%s'"
- logger.exception(msg, exc.__class__.__name__, str(exc))
- finally:
- logger.debug("RepoGuard finished with %s.", result)
- if result == constants.SUCCESS:
- return 0
+ logger.debug("Loading transaction...")
+ repoguard.load_trans​action(txn_name)
+
+ logger.debug("Loading configuration...")
+ main_config = RepoGuardConfig(cons​tants.CONFIG_PATH)
+ repoguard.load_confi​g(main_config.templa​te_dirs, project_config)
+
+ if main_config.validate:
+ repoguard.validate()
             else:
- return 1
+ logger.warning("Validation skipped.")
+
+ logger.debug("RepoGuard running...")
+ if profile_name:
+ result = repoguard.run_profil​e(profile_name)
+ else:
+ result = repoguard.run()
+ except ValidateError, exc:
+ msg = "Configuration validation error cause: %s"
+ logger.exception(msg, str(exc))
+ except Exception, exc:
+ msg = "%s exception cause: '%s'"
+ logger.exception(msg, exc.__class__.__name__, str(exc))
+
+ logger.debug("RepoGuard finished with %s.", result)
+ if result == constants.SUCCESS:
+ return 0
+ else:
+ return 1

Modified: trunk/repoguard/test​/repoguard_test/core​/test_checker.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/test/repogua​rd_test/core/test_ch​ecker.py?view=diff​&pathrev=144&r​1=143&r2=144
====================​====================​====================​==================
--- trunk/repoguard/test​/repoguard_test/core​/test_checker.py (original)
+++ trunk/repoguard/test​/repoguard_test/core​/test_checker.py 2012-10-10 14:05:40-0700
@@ -130,3 +130,14 @@
             large_changset.append("A Project/vendors/deli%f" % random.random())
         self._set_transactio​n_changeset(large_ch​angset)
         self._checker.run()
+
+ def test_run_profile_success(self):
+ self._checker.run_pr​ofile("ProjectA")
+
+ assert self._checker.checks​.fetch.call_count == 1
+ assert self._checker.checks​.fetch.call_args[0][​0] == "PyLint"
+
+ def test_run_missing_profile(self):
+ self._checker.run_pr​ofile("UNDEFINED_PRO​FILE")
+
+ assert self._checker.checks​.fetch.call_count == 0

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r144 - trunk/repoguard: src/repoguard/core src/repoguard/tools test/repoguard_test/core schlauch Tobias Schlauch 2012-10-10 14:05:41 PDT
Messages per page: