"Fossies" - the Fresh Open Source Software Archive

Member "svnchecker-0.3/Main.py" (12 Mar 2008, 3194 Bytes) of package /linux/privat/old/svnchecker-0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "Main.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/env python
    2 
    3 # pylint: disable-msg=W0122, E0602
    4 
    5 # Copyright 2008 German Aerospace Center (DLR)
    6 #
    7 # Licensed under the Apache License, Version 2.0 (the "License");
    8 # you may not use this file except in compliance with the License.
    9 # You may obtain a copy of the License at
   10 #
   11 #     http://www.apache.org/licenses/LICENSE-2.0
   12 #
   13 # Unless required by applicable law or agreed to in writing, software
   14 # distributed under the License is distributed on an "AS IS" BASIS,
   15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   16 # See the License for the specific language governing permissions and
   17 # limitations under the License.
   18 
   19 """
   20 http://svnchecker.tigris.org
   21 """
   22 
   23 import os
   24 import sys
   25 
   26 from modules import Config, Transaction
   27 
   28 # initialize configuration and transaction
   29 try:
   30     hook = sys.argv[1]
   31     reposPath = sys.argv[2]
   32     txnName = sys.argv[3]
   33 
   34     if hook not in ["PreCommit", "PostCommit"]:
   35         raise IndexError()
   36 
   37 except IndexError:
   38     sys.stderr.write("""Usage: Main.py hook reposPath txnName
   39        hook: PreCommit or PostCommit
   40        reposPath: the path to this repository
   41        txnName: the name of the transaction about to be committed\n""")
   42     sys.exit(1)
   43 
   44 os.chdir(os.path.join(reposPath, "hooks"))
   45 
   46 transaction = Transaction.Transaction(reposPath, txnName)
   47 
   48 def finish(code):
   49     transaction.cleanup()
   50     sys.exit(code)
   51 
   52 
   53 configFilename = "svncheckerconfig.ini"
   54 localConfig = os.path.join(reposPath, "hooks", configFilename)
   55 globalConfig =  os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), configFilename)
   56 config = Config.Config(globalConfig, localConfig)
   57 config.setHooksLocation(os.path.join(reposPath, "hooks"))
   58 
   59 # which files do not belong to a profile
   60 files = transaction.getFiles().keys()
   61 toRemove = []
   62 for profile in config.getProfiles():
   63     config.setProfile(profile)
   64     transaction.setProfile(config.getString('Main.Regex', "^$"))
   65     toRemove += [filename for filename in transaction.getFiles() if filename in files]
   66 
   67 for filename in toRemove:
   68     files.remove(filename)
   69 
   70 default = "^("
   71 for filename in files:
   72     default += filename + "|"
   73 default = default.strip("|")
   74 default += ")$"
   75 
   76 
   77 for profile in config.getProfiles() + [Config.DEFAULTSECT]:
   78 
   79     config.setProfile(profile)
   80     if profile == Config.DEFAULTSECT:
   81         transaction.setProfile(default)
   82     else:
   83         transaction.setProfile(config.getString('Main.Regex', "^$"))
   84 
   85     # if there are no files in this profile continue
   86     if len(transaction.getFiles()) == 0:
   87         continue
   88 
   89     # run the configured checks
   90     for check in config.getArray('Main.%sChecks' % hook):
   91         exec("from checks.%s import run" % check)
   92         (msg, exitCode) = run(transaction, config)
   93 
   94         if not msg:
   95             continue
   96 
   97         if exitCode == 1:
   98             handlers = config.getArray('%s.FailureHandlers' % check)
   99         else:
  100             handlers = config.getArray('%s.SuccessHandlers' % check)
  101 
  102         # run the configured handlers
  103         for handler in handlers:
  104             exec("from handlers.%s import run" % handler)
  105             run(transaction, config, check, msg, exitCode)
  106 
  107         if exitCode == 1:
  108             finish(exitCode)
  109 
  110 finish(0)