class _Test ():
	def __init__(self):
		self._logger=Logger(name='test_iccs_file_filters', level=Logger.DEBUG, 
						showDate=True, 
						showTime=True, 
						showName=False,
						showFunc=False)
		self._debug = self._logger.logger.debug
		self.log = self._logger.log
	
	def setup (self):	
		tower = "accurev.7.2.1.rel"
		self.log("BEGIN test")
		self.log("tower = '" + tower + "'")
		initFileFilters (tower)
		self.filtering = DirEntryFiltering()
		
	def run (self):
		self.testDirs ()

	def finish (self):
		sourcePath="/nif/code/Framework_Services/Generic_Client.ss/reynolds.SCR21941.sol.ada.7.2.0.wrk"
		self._debug("'" + sourcePath + "'" + str (re.match(re.compile("^" + VIEW_PATTERN + "$"), sourcePath)))
		self._debug("'" + sourcePath + "'" + str (re.search(re.compile(VIEW_PATTERN), sourcePath)))
		self.log("explicit filters:" + str(fileFilters.explicitFilterNames()).replace(",","\n"))
		self.log("pattern filters:" + str(fileFilters.patternFilterNames()).replace(",","\n"))
		self.log("END test")
				
	def testDirs (self):
		self.testDir("/nif")
		self.testDir("/nif/code")
		self.testDir("/nif/code/Slices/")
		self.testDir("/nif/code/Slices/Shadow_Deployment.ss")
		self.testDir("/nif/code/Slices/Shadow_Deployment.ss/accurev.7.2.1.rel")
		self.testDir("/nif/environment")
		self.testDir("/nif/environment/setup.ss")
		self.testDir("/nif/environment/setup.ss/latest.wrk")
		self.testDir("/nif/rational/base/ada")
		self.testDir("/nif/rational/base/ada/rational.ss")
		self.testDir("/nif/rational/base/ada/rational.ss/sun4_solaris2.ada95.4.2.0.rel")
		self.testDir("/nif/rational/base/ada/rational.ss/power.vw_ppc.ada95.4.2.0.rel")
		self.testDir("/nif/rational/base/ada/rts_vads_exec.ss")
		self.testDir("/nif/rational/base/ada/rts_vads_exec.ss/sun4_solaris2.ada95.4.2.0.rel")
		self.testDir("/nif/rational/base/ada/rts_vads_exec.ss/power.vw_ppc.ada95.4.2.0.rel")
		self.testDir("/nif/rational/config")
		self.testDir("/nif/tools")

	def testDir (self, dir):
		self.log("")
		self.log("Testing '" + dir + "'")
		nonExcludedEntries = self.filtering.allNonExcludedEntriesIn (dir, fileFilters)
		keys = nonExcludedEntries.keys()
		self.log("Got " + str(len(keys)) + " included entries:")
		keys.sort()
		for sourceEntry in keys:
			if nonExcludedEntries [sourceEntry].explicitlyIncluded:
				self.log("    '" + sourceEntry + "'" )
			else:
				self._logger.warning("implicitly included (matched no filter) '" + sourceEntry + "'" )
Example #2
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase4Popen")
     self.runner = support.runner.Runner()
     self.dir = "/"
     self.badDir = "/nosuchdir"
     self.popenArgs = ["uname", "-a"]
     self.badPopenArgs = ["nosuchprog", ]
 def __init__(self):
     self._logger = Logger(name='test_iccs_file_filters',
                           level=Logger.DEBUG,
                           showDate=True,
                           showTime=True,
                           showName=False,
                           showFunc=False)
     self._debug = self._logger.logger.debug
     self.log = self._logger.log
Example #4
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase5Call")
     self.runner = Runner()
     self.dir = "/"
     self.badDir = "/nosuchdir"
     self.args = ["uname", "-a"]
     self.badArgs = [
         "nosuchprog",
     ]
Example #5
0
class TestCase1(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase")
        self.runner = support.runner.Runner()
        self.command = "print('foo')"

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log("Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        self.runner.runOrLog(self.command)

    def test02_DoIt(self):
        self.logger.log("Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        self.runner.runOrLog(self.command)

    def test03_HandleExcep(self):
        self.logger.log("Exercising runAndHandle.  Exception should be logged and not reraised.")
        self.runner.runOrLog("print(nonExistentVar)")

    def test04_ReraiseExcep(self):
        self.logger.log("Exercising runAndHandle.  Exception should be logged and reraised.")
        self.assertRaises(
            support.runner.Runner.Failed,
            self.runner.runOrLog, "print(nonExistentVar)", doReraise=True)
Example #6
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.xterm_runner_tests.TestCase1")
     self.runner = XtermRunner()
     self.dir = "/"
     self.badDir = "/nosuchdir"
     self.popenArgs = ["uname", "-a"]
     self.badPopenArgs = [
         "nosuchprog",
     ]
     self.xtermArgs1 = ["-geometry", "90x40"]
     self.xtermArgs2 = ["-geometry", "90x40-10-10"]
     self.badXtermArgs = [
         "-badxtermarg",
     ]
	def __init__(self):
		self._logger=Logger(name='test_iccs_file_filters', level=Logger.DEBUG, 
						showDate=True, 
						showTime=True, 
						showName=False,
						showFunc=False)
		self._debug = self._logger.logger.debug
		self.log = self._logger.log
class TestCase1(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.xterm_runner_tests.TestCase1")
        self.runner = XtermRunner()
        self.dir = "/"
        self.badDir = "/nosuchdir"
        self.popenArgs = ["uname", "-a"]
        self.badPopenArgs=["nosuchprog",]
        self.xtermArgs1 = ["-geometry", "90x40"]
        self.xtermArgs2 = ["-geometry", "90x40-10-10"]
        self.badXtermArgs = ["-badxtermarg",]


    def tearDown(self):
        self._xtermRunner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log("Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        self.runner.xtermOrLog(xtermArgs=self.xtermArgs1, 
                               popenArgs=self.popenArgs, 
                               dir=self.dir)
#        (output, errors)=self.runner.xtermOrLog(self.popenArgs, self.dir)
#        self.assertTrue(output=="")
#        self.assertTrue(errors=="")
        
    def test02_DoIt(self):
        self.logger.log("Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
#        self.runner.xtermOrLog(self.xtermArgs2, self.popenArgs, self.dir)
        (output, errors)=self.runner.xtermOrLog(self.xtermArgs1, self.popenArgs, self.dir)
        print ("output:")
        print (output)
        print ("errors:")
        print (errors)
        self.assertTrue(errors==None)
#        self.assertTrue("SunOS" in output or "Linux" in output)

    def test04_ReraiseExcep(self):
        self.logger.log("Exercising popenAndHandle. errors should not be None")
        (output, errors)=self.runner.xtermOrLog(self.badXtermArgs, self.popenArgs, self.dir)
        print ("output:")
        print (output)
        print ("errors:")
        print (errors)
        self.assertTrue(errors != None)
        
    def test05_ReraiseExcep(self):
        self.logger.log("Exercising popenAndHandle.  Exception should be logged and reraised.")
        self.assertRaises(
                        XtermRunner.Failed, 
                        self.runner.xtermOrLog, self.xtermArgs1, self.popenArgs, self.badDir)
Example #9
0
class TestCase2NameSpace(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase2NameSpace")
        self.runner = Runner()
        self.bad_command = "atexit.register(abs, 0)"

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test03_ReraiseExcep(self):
        self.logger.info(
            "Exercising operation not in namespace.  Exception should be logged and raised."
        )
        self.assertRaises(Runner.Failed,
                          self.runner.execOrLog,
                          self.bad_command,
                          doReraise=True)
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.xterm_runner_tests.TestCase1")
     self.runner = XtermRunner()
     self.dir = "/"
     self.badDir = "/nosuchdir"
     self.popenArgs = ["uname", "-a"]
     self.badPopenArgs=["nosuchprog",]
     self.xtermArgs1 = ["-geometry", "90x40"]
     self.xtermArgs2 = ["-geometry", "90x40-10-10"]
     self.badXtermArgs = ["-badxtermarg",]
Example #11
0
class TestCase3Eval(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase3Eval")
        self.runner = Runner()
        self.expression = "square(parm)"
        self.bad_expression = "nonExistentVar"

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.info(
            "Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        result = self.runner.evalOrLog(self.expression, globals(), locals())

    def test02_DoIt(self):
        self.logger.info(
            "Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        parm = 3
        result = self.runner.evalOrLog(self.expression, globals(), locals())
        self.assertEquals(result, 9)

    # No no_reraise test here because there is no no_reraise option in evalOrLog.

    def test04_ReraiseExcep(self):
        self.logger.info(
            "Exercising evalAndHandle.  Exception should be logged and reraised."
        )
        self.assertRaises(Runner.Failed, self.runner.evalOrLog,
                          self.bad_expression, globals(), locals())
Example #12
0
class TestCase3Eval(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase3Eval")
        self.runner = support.runner.Runner()
        self.command = "square(parm)"

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log("Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        result = self.runner.evalOrLog(self.command, globals(), locals())

    def test02_DoIt(self):
        self.logger.log("Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        parm = 3
        result = self.runner.evalOrLog(self.command, globals(), locals())
        self.assertEquals(result, 9)

    def test04_ReraiseExcep(self):
        self.logger.log("Exercising evalAndHandle.  Exception should be logged and reraised.")
        self.assertRaises(
            support.runner.Runner.Failed,
            self.runner.evalOrLog, "print(nonExistentVar)")
Example #13
0
class TestCase5Call(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase5Call")
        self.runner = Runner()
        self.dir = "/"
        self.badDir = "/nosuchdir"
        self.args = ["uname", "-a"]
        self.badArgs = [
            "nosuchprog",
        ]

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.info(
            "Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        self.runner.callOrLog(self.args, self.dir)

    def test02_DoIt(self):
        self.logger.info(
            "Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        self.runner.callOrLog(self.args, self.dir)

    # No no_reraise test here because there is no no_reraise option in callOrLog.

    def test04_ReraiseExcep(self):
        self.logger.info(
            "Exercising callAndHandle.  Exception should be logged and reraised."
        )
        self.assertRaises(Runner.Failed, self.runner.callOrLog, self.badArgs,
                          self.dir)

    def test05_ReraiseExcep(self):
        self.logger.info(
            "Exercising callAndHandle.  Exception should be logged and reraised."
        )
        self.assertRaises(Runner.Failed, self.runner.callOrLog, self.args,
                          self.badDir)
Example #14
0
class TestCase4Popen(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCase4Popen")
        self.runner = support.runner.Runner()
        self.dir = "/"
        self.badDir = "/nosuchdir"
        self.popenArgs = ["uname", "-a"]
        self.badPopenArgs = ["nosuchprog", ]

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log("Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        (output, errors) = self.runner.popenOrLog(self.popenArgs, self.dir)
        self.assertTrue(output == "")
        self.assertTrue(errors == "")

    def test02_DoIt(self):
        self.logger.log("Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        (output, errors) = self.runner.popenOrLog(self.popenArgs, self.dir)
        self.assertTrue(errors == "")
        self.assertTrue("SunOS" in output or "Linux" in output)

    def test04_ReraiseExcep(self):
        self.logger.log("Exercising popenAndHandle.  Exception should be logged and reraised.")
        self.assertRaises(
            support.runner.Runner.Failed,
            self.runner.popenOrLog, self.badPopenArgs, self.dir)

    def test05_ReraiseExcep(self):
        self.logger.log("Exercising popenAndHandle.  Exception should be logged and reraised.")
        self.assertRaises(
            support.runner.Runner.Failed,
            self.runner.popenOrLog, self.popenArgs, self.badDir)
Example #15
0
class TestCase2NameSpace(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.runner_tests.TestCaseNameSpace")
        self.runner = support.runner.Runner()
        self.command = "atexit.register(abs, 0)"

    def tearDown(self):
        self.runner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log("Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        self.runner.runOrLog(self.command, globals(), locals())

    def test02_DoIt(self):
        self.logger.log("Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        self.runner.runOrLog(self.command, globals(), locals())

    def test03_HandleExcep(self):
        self.logger.log("Exercising operation not in namespace.  Exception should be raised.")
        self.runner.runOrLog(self.command)
Example #16
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase3Eval")
     self.runner = support.runner.Runner()
     self.command = "square(parm)"
Example #17
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCaseNameSpace")
     self.runner = support.runner.Runner()
     self.command = "atexit.register(abs, 0)"
Example #18
0
"""
import file_filters
import os
import re
import shutil
from stats import stats
import support.runner
from support.string_utils import su
from support.local_logging import Logger, LineLogger, FunctionLogger
# import time

lineLogger = LineLogger()
runner = support.runner.runner
_logger = Logger(name='dir_entries.py',
                 level=Logger.DEBUG,
                 showDate=True,
                 showTime=True,
                 showName=False,
                 showFunc=True)
_debug = _logger.logger.debug
_log = _logger.logger.info


class Utils(object):
    """Place to collect various utilities
	TODO: refactor later
	"""
    NEW_NIF_CODE = "/src/code"
    NEW_NIF_IDL = "/src/idl"

    skipClean = False
class _Test():
    def __init__(self):
        self._logger = Logger(name='test_iccs_file_filters',
                              level=Logger.DEBUG,
                              showDate=True,
                              showTime=True,
                              showName=False,
                              showFunc=False)
        self._debug = self._logger.logger.debug
        self.log = self._logger.log

    def setup(self):
        tower = "accurev.7.2.1.rel"
        self.log("BEGIN test")
        self.log("tower = '" + tower + "'")
        initFileFilters(tower)
        self.filtering = DirEntryFiltering()

    def run(self):
        self.testDirs()

    def finish(self):
        sourcePath = "/nif/code/Framework_Services/Generic_Client.ss/reynolds.SCR21941.sol.ada.7.2.0.wrk"
        self._debug(
            "'" + sourcePath + "'" +
            str(re.match(re.compile("^" + VIEW_PATTERN + "$"), sourcePath)))
        self._debug("'" + sourcePath + "'" +
                    str(re.search(re.compile(VIEW_PATTERN), sourcePath)))
        self.log("explicit filters:" +
                 str(fileFilters.explicitFilterNames()).replace(",", "\n"))
        self.log("pattern filters:" +
                 str(fileFilters.patternFilterNames()).replace(",", "\n"))
        self.log("END test")

    def testDirs(self):
        self.testDir("/nif")
        self.testDir("/nif/code")
        self.testDir("/nif/code/Slices/")
        self.testDir("/nif/code/Slices/Shadow_Deployment.ss")
        self.testDir("/nif/code/Slices/Shadow_Deployment.ss/accurev.7.2.1.rel")
        self.testDir("/nif/environment")
        self.testDir("/nif/environment/setup.ss")
        self.testDir("/nif/environment/setup.ss/latest.wrk")
        self.testDir("/nif/rational/base/ada")
        self.testDir("/nif/rational/base/ada/rational.ss")
        self.testDir(
            "/nif/rational/base/ada/rational.ss/sun4_solaris2.ada95.4.2.0.rel")
        self.testDir(
            "/nif/rational/base/ada/rational.ss/power.vw_ppc.ada95.4.2.0.rel")
        self.testDir("/nif/rational/base/ada/rts_vads_exec.ss")
        self.testDir(
            "/nif/rational/base/ada/rts_vads_exec.ss/sun4_solaris2.ada95.4.2.0.rel"
        )
        self.testDir(
            "/nif/rational/base/ada/rts_vads_exec.ss/power.vw_ppc.ada95.4.2.0.rel"
        )
        self.testDir("/nif/rational/config")
        self.testDir("/nif/tools")

    def testDir(self, dir):
        self.log("")
        self.log("Testing '" + dir + "'")
        nonExcludedEntries = self.filtering.allNonExcludedEntriesIn(
            dir, fileFilters)
        keys = nonExcludedEntries.keys()
        self.log("Got " + str(len(keys)) + " included entries:")
        keys.sort()
        for sourceEntry in keys:
            if nonExcludedEntries[sourceEntry].explicitlyIncluded:
                self.log("    '" + sourceEntry + "'")
            else:
                self._logger.warning(
                    "implicitly included (matched no filter) '" + sourceEntry +
                    "'")
Example #20
0
class TestCase1(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.logger = Logger("support.xterm_runner_tests.TestCase1")
        self.runner = XtermRunner()
        self.dir = "/"
        self.badDir = "/nosuchdir"
        self.popenArgs = ["uname", "-a"]
        self.badPopenArgs = [
            "nosuchprog",
        ]
        self.xtermArgs1 = ["-geometry", "90x40"]
        self.xtermArgs2 = ["-geometry", "90x40-10-10"]
        self.badXtermArgs = [
            "-badxtermarg",
        ]

    def tearDown(self):
        self._xtermRunner = None
        unittest.TestCase.tearDown(self)

    def test01_EffortOnly(self):
        self.logger.log(
            "Exercising effortOnly=True.  Command should not execute.")
        self.runner.setEffortOnly(True)
        self.runner.xtermOrLog(xtermArgs=self.xtermArgs1,
                               popenArgs=self.popenArgs,
                               dir=self.dir)
#        (output, errors)=self.runner.xtermOrLog(self.popenArgs, self.dir)
#        self.assertTrue(output=="")
#        self.assertTrue(errors=="")

    def test02_DoIt(self):
        self.logger.log(
            "Exercising effortOnly=False.  Command should execute.")
        self.runner.setEffortOnly(False)
        #        self.runner.xtermOrLog(self.xtermArgs2, self.popenArgs, self.dir)
        (output, errors) = self.runner.xtermOrLog(self.xtermArgs1,
                                                  self.popenArgs, self.dir)
        print("output:")
        print(output)
        print("errors:")
        print(errors)
        self.assertTrue(errors == None)


#        self.assertTrue("SunOS" in output or "Linux" in output)

    def test04_ReraiseExcep(self):
        self.logger.log("Exercising popenAndHandle. errors should not be None")
        (output, errors) = self.runner.xtermOrLog(self.badXtermArgs,
                                                  self.popenArgs, self.dir)
        print("output:")
        print(output)
        print("errors:")
        print(errors)
        self.assertTrue(errors != None)

    def test05_ReraiseExcep(self):
        self.logger.log(
            "Exercising popenAndHandle.  Exception should be logged and reraised."
        )
        self.assertRaises(XtermRunner.Failed, self.runner.xtermOrLog,
                          self.xtermArgs1, self.popenArgs, self.badDir)
Example #21
0
class Runner():
    class Failed(Exception):
        pass

    def __init__(self, effortOnly=False):
        self._effortOnly = effortOnly
        self._logger = Logger(name='support.runner.Runner', level=Logger.DEBUG)

    def setEffortOnly(self, effortOnly):
        self._effortOnly = effortOnly

    def runOrLog(self, command, globals=None, locals=None, doReraise=False):
        if self._effortOnly:
            self._logger.info("Would do: " + command)
        else:
            self._logger.info(command)
            self.tryExec(command, globals, locals, doReraise)

    def tryExec(self, command, globals=None, locals=None, doReraise=False):
        try:
            exec command in globals, locals
        except Exception:
            self._logger.logger.exception('EXCEPTION raised while running "' +
                                          command + '"')
            if doReraise:
                self._logger.error("Raising Runner.Failed")
                raise self.Failed()
            else:
                self._logger.info("Continuing...")

    def evalOrLog(self, command, globals=None, locals=None):
        if self._effortOnly:
            self._logger.info("Would do: " + command)
        else:
            self._logger.info(command)
            return self.tryEval(command, globals, locals)

    def tryEval(self, command, globals=None, locals=None):
        """Evaluates the expression in command and returns the result.  Always
        reraises any exceptions.
        """
        try:
            return eval(command, globals, locals)
        except Exception:
            self._logger.logger.exception(
                'EXCEPTION raised while evaluating "' + command + '"')
            self._logger.error("Raising Runner.Failed")
            raise self.Failed()

    def _commandMessage(self, popenArgs, dir):
        return "Popen(args=" + str(popenArgs) + ", dir=" + str(dir)

    def popenOrLog(self, popenArgs, dir=None):
        if self._effortOnly:
            self._logger.info("Would do " +
                              self._commandMessage(popenArgs, dir))
            return ("", "")
        else:
            self._logger.info(self._commandMessage(popenArgs, dir))
            return self.tryPopen(popenArgs, dir)

    def tryPopen(self, popenArgs, dir=None):
        """Issue the command associated with the given Popen arguments list.
        Returns the results of the command in a (output, errors) tuple.
        """
        try:
            p1 = subprocess.Popen(args=popenArgs,
                                  env=os.environ,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  cwd=dir)
            (output, errors) = p1.communicate()
        except OSError, e:
            self._logger.logger.exception(
                'EXCEPTION raised while running "' +
                self._commandMessage(popenArgs, dir) + '"')
            self._logger.error("Raising Runner.Failed")
            raise self.Failed()
        return output, errors
Example #22
0
 def __init__(self, effortOnly=False):
     self._effortOnly = effortOnly
     self._logger = Logger(
         name='support.runner.Runner',
         level=Logger.DEBUG)
Example #23
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase3Eval")
     self.runner = Runner()
     self.expression = "square(parm)"
     self.bad_expression = "nonExistentVar"
Example #24
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase1ExecOrLog")
     self.runner = Runner()
     self.command = "print('foo')"
     self.bad_command = "print(nonExistentVar)"
Example #25
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.logger = Logger("support.runner_tests.TestCase")
     self.runner = support.runner.Runner()
     self.command = "print('foo')"
Example #26
0
"""Specifies the files, directories, etc. to be explicitly included and 
excluded when importing into AccuRev. 
"""
import os
import re
from support.local_logging import Logger, LineLogger, FunctionLogger

_logger = Logger(name=__name__,
                 level=Logger.NONDEBUG,
                 showDate=True,
                 showTime=True,
                 showName=False,
                 showFunc=True)
_debug = _logger.logger.debug


class DirEntryBase(object):
    """Base class for various directory entry kind specification classes. 
	"""
    pass


class Exclude(DirEntryBase):
    """A directory entry of this class was explicitly excluded by a filter. 
	"""
    pass


class NonExcludedEntry(DirEntryBase):
    """Directory entries of this class were not excluded by a filter. 
	If explicitlyIncluded=True, they were explicitly included by a filter.
Example #27
0
class Runner():
    class Failed(Exception):
        pass

    def __init__(self, effortOnly=False):
        self._effortOnly = effortOnly
        self._logger = Logger(
            name='support.runner.Runner',
            level=Logger.DEBUG)

    def setEffortOnly(self, effortOnly):
        self._effortOnly = effortOnly

    def runOrLog(self, command, globals=None, locals=None, doReraise=False):
        if self._effortOnly:
            self._logger.info("Would do: " + command)
        else:
            self._logger.info(command)
            self.tryExec(command, globals, locals, doReraise)

    def tryExec(self, command, globals=None, locals=None, doReraise=False):
        try:
            exec command in globals, locals
        except Exception:
            self._logger.logger.exception('EXCEPTION raised while running "' + command + '"')
            if doReraise:
                self._logger.error("Raising Runner.Failed")
                raise self.Failed()
            else:
                self._logger.info("Continuing...")

    def evalOrLog(self, command, globals=None, locals=None):
        if self._effortOnly:
            self._logger.info("Would do: " + command)
        else:
            self._logger.info(command)
            return self.tryEval(command, globals, locals)

    def tryEval(self, command, globals=None, locals=None):
        """Evaluates the expression in command and returns the result.  Always
        reraises any exceptions.
        """
        try:
            return eval(command, globals, locals)
        except Exception:
            self._logger.logger.exception('EXCEPTION raised while evaluating "' + command + '"')
            self._logger.error("Raising Runner.Failed")
            raise self.Failed()

    def _commandMessage(self, popenArgs, dir):
        return "Popen(args=" + str(popenArgs) + ", dir=" + str(dir)

    def popenOrLog(self, popenArgs, dir=None):
        if self._effortOnly:
            self._logger.info("Would do " + self._commandMessage(popenArgs, dir))
            return ("", "")
        else:
            self._logger.info(self._commandMessage(popenArgs, dir))
            return self.tryPopen(popenArgs, dir)

    def tryPopen(self, popenArgs, dir=None):
        """Issue the command associated with the given Popen arguments list.
        Returns the results of the command in a (output, errors) tuple.
        """
        try:
            p1 = subprocess.Popen(
                args=popenArgs,
                env=os.environ,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=dir)
            (output, errors) = p1.communicate()
        except OSError, e:
            self._logger.logger.exception(
                'EXCEPTION raised while running "' + self._commandMessage(popenArgs, dir) + '"')
            self._logger.error("Raising Runner.Failed")
            raise self.Failed()
        return output, errors
Example #28
0
 def __init__(self, effortOnly=False):
     self._effortOnly = effortOnly
     self._logger = Logger(name='support.runner.Runner', level=Logger.DEBUG)