Example #1
0
 def testGoodConfig2(self):
     try:
         conf = ccpydconfparser.parse("ccpyd.conf.good.2")
         self.assertEqual(len(conf), 2)
         self.assertEqual(conf['ccpyConfig'], '/etc/ccpy.conf')
         self.assertEqual(conf['logging'], False)
     except BaseException as e:
         print(("Error. %s. %s. %s" % (type(e), str(e), util.formatTb())))
         self.assertTrue(False)
Example #2
0
 def testGoodConfig1(self):
     try:
         conf = ccpydconfparser.parse("ccpyd.conf.good.1")
         self.assertEqual(len(conf), 4)
         self.assertEqual(conf['ccpyConfig'], '/etc/ccpy.conf.1')
         self.assertEqual(conf['logging'], True)
         self.assertEqual(conf['logFile'], '/var/log/ccpyd.log')
         self.assertEqual(conf['logLevel'], 'DEBUG')
     except BaseException as e:
         print(("Error. %s. %s. %s" % (type(e), str(e), util.formatTb())))
         self.assertTrue(False)
Example #3
0
def main(argv):
    if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1] < 5):
        sys.stderr.write("Python 2.5 or higher is required for the program to run.")
        return -1

    try:
        if run_in_fg(argv):
            print("Starting in foreground")
        else:
            print("Starting in background")
            util.daemonize()

        myCcPydConf = ccpydconfparser.parse()
        if not myCcPydConf['logging']:
            myCcPydConf['logFile'] = '/dev/null'
        Logger = util.initLogger(
            common.LoggerName,
            myCcPydConf['logFile'],
            common.ProductName +
            ' v.' +
            common.ProductVersion,
            myCcPydConf['logLevel'])
    except Exception as e:
        sys.stderr.write("%s. %s. %s" % (type(e), str(e), util.formatTb()))
        return -1

    try:
        mySysSingleton = util.SysSingleton(common.DaemonName)
        myCcPyConf = myCcPydConf['ccpyConfig']
        execTasks(myCcPyConf)
        util.closeLogger(Logger)
        return 0
    except BaseException as e:
        Logger.error("%s: %s. %s" % (type(e), str(e), util.formatTb()))
        util.closeLogger(Logger)
        return -1
    except:
        Logger.error("Unexpected error")
        util.closeLogger(Logger)
        return -2

    Logger.error("We should never get here.")
    return -3