Example #1
0
def validate_config(config):
    if not config.has_section('general'):
        die("No [general] section found.")

    twiggy.quickSetup(
        name2level(config.get('general', 'log.level')),
        config.get('general', 'log.file')
    )

    if not config.has_option('general', 'targets'):
        die("No targets= item in [general] found.")

    targets = config.get('general', 'targets')
    targets = [t.strip() for t in targets.split(",")]

    for target in targets:
        if target not in config.sections():
            die("No [%s] section found." % target)

    for option in ['bitly.api_user', 'bitly.api_key']:
        if not config.has_option('general', option):
            log.warning("URLs will not be shortened with bit.ly")

    # Validate each target one by one.
    for target in targets:
        service = config.get(target, 'service')
        if not service:
            die("No 'service' in [%s]" % target)

        if service not in SERVICES:
            die("'%s' in [%s] is not a valid service." % (service, target))

        # Call the service-specific validator
        SERVICES[service].validate_config(config, target)
Example #2
0
        def _rate_limit(*args, **kw):
            if time.time() - rate_limit.start > self.limit_period:
                rate_limit.start, rate_limit.counter = time.time(), 0

            rate_limit.counter += 1

            if rate_limit.counter == self.limit_amount - 1:
                duration = self.limit_period - \
                        (time.time() - rate_limit.start) + 1
                log.warning("Expected to exceed API rate limit. Sleeping {0}s",
                        duration)
                time.sleep(duration)

            return func(*args, **kw)