Beispiel #1
0
def main():
    
    install_exc_handler(default_handler)
    ver = 'APEL client %s.%s.%s' % __version__
    opt_parser = OptionParser(version=ver, description=__doc__)
    
    opt_parser.add_option('-c', '--config',
                          help='main configuration file for APEL',
                          default='/etc/apel/client.cfg')
    
    opt_parser.add_option('-s', '--ssm_config', 
                          help='location of SSM config file',
                          default='/etc/apel/sender.cfg')
    
    opt_parser.add_option('-l', '--log_config', 
                          help='location of logging config file (optional)',
                          default='/etc/apel/logging.cfg')
    
    options, unused_args = opt_parser.parse_args()
    cp = ConfigParser.ConfigParser()
    cp.read(options.config)

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'), 
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
        log = logging.getLogger('client')
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
Beispiel #2
0
def get_config(config_file):
    """Using the config file location, get a config object."""
    # Read configuration from file
    cp = ConfigParser.ConfigParser()
    cp.read(config_file)

    c = Configuration()

    try:
        c.gocdb_url = cp.get('auth', 'gocdb_url')
    except ConfigParser.NoOptionError:
        c.gocdb_url = None

    try:
        extra_dns = cp.get('auth', 'extra-dns')
        c.extra_dns = os.path.normpath(os.path.expandvars(extra_dns))
    except ConfigParser.NoOptionError:
        c.extra_dns = None

    try:
        banned_dns = cp.get('auth', 'banned-dns')
        c.banned_dns = os.path.normpath(os.path.expandvars(banned_dns))
    except ConfigParser.NoOptionError:
        c.banned_dns = None

    try:
        dn_file = cp.get('auth', 'allowed-dns')
        c.dn_file = os.path.normpath(os.path.expandvars(dn_file))
    except ConfigParser.NoOptionError:
        c.dn_file = None

    try:
        proxy = cp.get('auth', 'proxy')
        c.proxy = proxy
    except ConfigParser.NoOptionError:
        c.proxy = None

    try:
        c.expire_hours = cp.getint('auth', 'expire_hours')
    except ConfigParser.NoOptionError:
        c.expire_hours = 0

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'),
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
Beispiel #3
0
def get_config(config_file):
    """Using the config file location, get a config object."""
    # Read configuration from file
    cp = ConfigParser.ConfigParser()
    cp.read(config_file)
    
    c = Configuration()
    
    try:
        c.gocdb_url = cp.get('auth', 'gocdb_url')
    except ConfigParser.NoOptionError:
        c.gocdb_url = None
        
    try:
        extra_dns = cp.get('auth', 'extra-dns')
        c.extra_dns = os.path.normpath(os.path.expandvars(extra_dns))
    except ConfigParser.NoOptionError:
        c.extra_dns = None
    
    try:
        banned_dns = cp.get('auth', 'banned-dns')
        c.banned_dns = os.path.normpath(os.path.expandvars(banned_dns))
    except ConfigParser.NoOptionError:
        c.banned_dns = None
    
    try:
        dn_file = cp.get('auth', 'allowed-dns')
        c.dn_file = os.path.normpath(os.path.expandvars(dn_file))
    except ConfigParser.NoOptionError:
        c.dn_file = None
        
    try:
        proxy = cp.get('auth', 'proxy')
        c.proxy = proxy
    except ConfigParser.NoOptionError:
        c.proxy = None

    try:
        c.expire_hours = cp.getint('auth', 'expire_hours')
    except ConfigParser.NoOptionError:
        c.expire_hours = 0

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'), 
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
Beispiel #4
0
def main():
    '''
    Parse command line arguments, set up logging and begin the client
    workflow.
    '''
    install_exc_handler(default_handler)
    ver = 'APEL client %s.%s.%s' % __version__
    opt_parser = OptionParser(version=ver, description=__doc__)

    opt_parser.add_option('-c',
                          '--config',
                          help='main configuration file for APEL',
                          default='/etc/apel/client.cfg')

    opt_parser.add_option('-s',
                          '--ssm_config',
                          help='location of SSM config file',
                          default='/etc/apel/sender.cfg')

    opt_parser.add_option('-l',
                          '--log_config',
                          help='location of logging config file (optional)',
                          default='/etc/apel/logging.cfg')

    options, unused_args = opt_parser.parse_args()
    ccp = ConfigParser.ConfigParser()
    ccp.read(options.config)

    scp = ConfigParser.ConfigParser()
    scp.read(options.ssm_config)

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(ccp.get('logging', 'logfile'),
                           ccp.get('logging', 'level'),
                           ccp.getboolean('logging', 'console'))
        log = logging.getLogger(LOGGER_ID)
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
Beispiel #5
0
    def test_stdout_logging(self):
        """
        Check that logging to stdout and file works, ignoring timestamp.

        These are tested together as otherwise the logger setup conflicts.
        """
        set_up_logging(self.path, 'INFO', True)
        log = logging.getLogger('test_logging')
        log.info('out')

        # Retrieve output from StringIO object.
        output = sys.stdout.getvalue()
        # Shutdown logging to release log file for later deletion.
        logging.shutdown()

        # Only check bit after timestamp as that doesn't change.
        self.assertEqual(output[23:], " - test_logging - INFO - out\n")
        f = open(self.path)
        self.assertEqual(f.readline()[23:], " - test_logging - INFO - out\n")
        f.close()
Beispiel #6
0
def main():
    """
    Parse command line arguments, set up logging and begin the client 
    workflow.
    """
    install_exc_handler(default_handler)
    ver = "APEL client %s.%s.%s" % __version__
    opt_parser = OptionParser(version=ver, description=__doc__)

    opt_parser.add_option("-c", "--config", help="main configuration file for APEL", default="/etc/apel/client.cfg")

    opt_parser.add_option("-s", "--ssm_config", help="location of SSM config file", default="/etc/apel/sender.cfg")

    opt_parser.add_option(
        "-l", "--log_config", help="location of logging config file (optional)", default="/etc/apel/logging.cfg"
    )

    options, unused_args = opt_parser.parse_args()
    ccp = ConfigParser.ConfigParser()
    ccp.read(options.config)

    scp = ConfigParser.ConfigParser()
    scp.read(options.ssm_config)

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(
                ccp.get("logging", "logfile"), ccp.get("logging", "level"), ccp.getboolean("logging", "console")
            )
        log = logging.getLogger(LOGGER_ID)
    except (ConfigParser.Error, ValueError, IOError), err:
        print "Error configuring logging: %s" % str(err)
        print "The system will exit."
        sys.exit(1)
Beispiel #7
0
def runprocess(db_config_file, config_file, log_config_file):
    '''Parse the configuration file and start the loader.'''
    
    # Read configuration from file 
    cp = ConfigParser.ConfigParser()
    cp.read(config_file)

    dbcp = ConfigParser.ConfigParser()
    dbcp.read(db_config_file)
    
    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'), 
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
        global log
        log = logging.getLogger('dbloader')
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
Beispiel #8
0
def runprocess(db_config_file, config_file, log_config_file):
    '''Parse the configuration file and start the loader.'''

    # Read configuration from file
    cp = ConfigParser.ConfigParser()
    cp.read(config_file)

    dbcp = ConfigParser.ConfigParser()
    dbcp.read(db_config_file)

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'),
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
        global log
        log = logging.getLogger('dbloader')
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)
        print 'Error in configuration file %s: %s' % (config_file, str(err))
        print 'The system will exit.'
        sys.exit(1)

    try:
        db_type = dbcp.get('db', 'type')
    except ConfigParser.Error:
        db_type = 'cpu'

    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'),
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
        log = logging.getLogger('summariser')
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)

    log.info('Starting apel summariser version %s.%s.%s', *__version__)

    # Log into the database
    try:

        log.info('Connecting to the database ... ')
        db = ApelDb(db_backend, db_hostname, db_port, db_username, db_password,
                    db_name)
Beispiel #10
0
    # Read configuration from file 
    try:
        cp = ConfigParser.ConfigParser()
        cp.read(options.config) 
    except Exception, e:
        sys.stderr.write(str(e))
        sys.stderr.write('\n')
        sys.exit(1)
    
    # set up logging
    try:
        if os.path.exists(options.log_config):
            logging.config.fileConfig(options.log_config)
        else:
            set_up_logging(cp.get('logging', 'logfile'), 
                           cp.get('logging', 'level'),
                           cp.getboolean('logging', 'console'))
    except (ConfigParser.Error, ValueError, IOError), err:
        print 'Error configuring logging: %s' % str(err)
        print 'The system will exit.'
        sys.exit(1)

    global log
    log = logging.getLogger('parser')
    log.info('=====================================')
    log.info('Starting apel parser version %s.%s.%s' % __version__)

    # database connection
    try:
        apel_db = ApelDb(DB_BACKEND,
                         cp.get('db', 'hostname'),
Beispiel #11
0
 def test_boring_logging(self):
     """Check that logging without handlers at least runs without errors."""
     set_up_logging(None, 'INFO', False)