Ejemplo n.º 1
0
 def test_direct(self):
     plogging.setLevel(logging.DEBUG)
     self.assertEqual(plogging.getEffectiveLevel(), logging.DEBUG)
     plogging.debug("hello world -- debug")
     plogging.info("hello world -- info")
     plogging.warning("hello world -- warning")
     plogging.error("hello world -- error")
     plogging.critical("hello world -- critical")
     self.assertEqual(plogging.foundErrors(), True)
     plogging.reset()
     self.assertEqual(plogging.foundErrors(), False)
Ejemplo n.º 2
0
    def test_direct(self):

        class DullHandler(logging.NullHandler):
            level = logging.DEBUG
            def emit(self, record):
                log_entry = self.format(record)

        plogging.addHandler(DullHandler())
        plogging.setLevel(logging.DEBUG)
        self.assertEqual(plogging.getEffectiveLevel(), logging.DEBUG)
        plogging.debug("hello world -- debug")
        plogging.info("hello world -- info")
        plogging.warning("hello world -- warning")
        plogging.error("hello world -- error")
        plogging.critical("hello world -- critical")
        self.assertEqual(plogging.foundErrors(), True)
        plogging.reset()
        self.assertEqual(plogging.foundErrors(), False)
Ejemplo n.º 3
0
    def __init__(self, inbox, outbox):
        self.inbox = inbox
        self.outbox = outbox
        logging.debug('worker {}, {}'.format(self.inbox, self.outbox))

        class OutboxHandler(logging.Handler):
            def __init__(self, outbox):
                self.level = logging.INFO
                self.filters = ()
                self.lock = False
                self.formatter = False
                self.outbox = outbox

            def emit(self, record):
                log_entry = self.format(record)
                self.outbox.put(log_entry)

        plogging.addHandler(OutboxHandler(outbox))
        plogging.setLevel(logging.INFO)
Ejemplo n.º 4
0
def parse_args(args=[]):
    """
    Guesses the intention of the runner of this program

    :param args: arguments to be considered for this invocation
    :type args: a list of ``str``

    You have to run the following command to know more::

        $ python -m plumbery fittings.yaml -h

    """

    parser = argparse.ArgumentParser(
        prog='python -m plumbery',
        description='Plumbing infrastructure with Apache Libcloud.',
        epilog='example: python -m plumbery fittings.yaml build')

    parser.add_argument(
        'fittings',
        nargs=1,
        help="File that is containing fittings plan, or '-' to read stdin")

    parser.add_argument(
        'action',
        nargs=1,
        help="An action, or a polisher: 'deploy', 'refresh', dispose', "
        "'secrets', 'build', 'configure', 'start', 'prepare', "
        "'information', 'ping', 'inventory', 'ansible', "
        "'stop', 'wipe', 'destroy'")

    parser.add_argument(
        'tokens',
        nargs='*',
        help="One blueprint, or several, e.g., 'web' or 'web sql'."
        "If omitted, all blueprints will be considered. "
        "Zero or more locations, e.g., '@NA12'. "
        "If omitted, all locations will be considered.",
        default=None)

    parser.add_argument('-p',
                        '--parameters',
                        nargs='*',
                        help='Parameters for this fittings plan')

    parser.add_argument(
        '-s',
        '--safe',
        help='Safe mode, no actual change is made to the infrastructure',
        action='store_true')

    group = parser.add_mutually_exclusive_group()

    group.add_argument('-d',
                       '--debug',
                       help='Log as much information as possible',
                       action='store_true')

    group.add_argument('-q',
                       '--quiet',
                       help='Silent mode, log only warnings and errors',
                       action='store_true')

    parser.add_argument('-v',
                        '--version',
                        help='Print version of this software',
                        action='version',
                        version='plumbery ' + __version__)

    args = parser.parse_args(args)

    if args.debug:
        plogging.setLevel(logging.DEBUG)
    elif args.quiet:
        plogging.setLevel(logging.WARNING)
    else:
        plogging.setLevel(logging.INFO)

    if 'version' in args:
        print(args.version)

    args.fittings = args.fittings[0]
    plogging.debug("- loading '{}'".format(args.fittings))

    args.action = args.action[0].lower()

    args.blueprints = []
    args.facilities = []
    for token in args.tokens:
        if token[0] == '@':
            if token == '@':
                raise ValueError("Missing location after @. "
                                 "Correct example: '@AU11'")
            args.facilities.append(token[1:])
        else:
            args.blueprints.append(token)

    if len(args.blueprints) < 1:
        args.blueprints = None
    else:
        plogging.debug('blueprints: ' + ' '.join(args.blueprints))

    if len(args.facilities) < 1:
        args.facilities = None
    else:
        plogging.debug('facilities: ' + ' '.join(args.facilities))

    return args
Ejemplo n.º 5
0
def parse_args(args=[]):
    """
    Guesses the intention of the runner of this program

    :param args: arguments to be considered for this invocation
    :type args: a list of ``str``

    You have to run the following command to know more::

        $ python -m plumbery fittings.yaml -h

    """

    parser = argparse.ArgumentParser(
        prog='python -m plumbery',
        description='Plumbing infrastructure with Apache Libcloud.',
        epilog='example: python -m plumbery fittings.yaml build')

    parser.add_argument(
        'fittings',
        nargs=1,
        help="File that is containing fittings plan, or '-' to read stdin")

    parser.add_argument(
        'action',
        nargs=1,
        help="An action, or a polisher: 'deploy', 'refresh', dispose', "
             "'secrets', 'build', 'configure', 'start', 'prepare', "
             "'information', 'ping', 'inventory', 'ansible', "
             "'stop', 'wipe', 'destroy'")

    parser.add_argument(
        'tokens',
        nargs='*',
        help="One blueprint, or several, e.g., 'web' or 'web sql'."
             "If omitted, all blueprints will be considered. "
             "Zero or more locations, e.g., '@NA12'. "
             "If omitted, all locations will be considered.",
        default=None)

    parser.add_argument(
        '-p', '--parameters', nargs='*',
        help='Parameters for this fittings plan')

    parser.add_argument(
        '-s', '--safe',
        help='Safe mode, no actual change is made to the infrastructure',
        action='store_true')

    group = parser.add_mutually_exclusive_group()

    group.add_argument(
        '-d', '--debug',
        help='Log as much information as possible',
        action='store_true')

    group.add_argument(
        '-q', '--quiet',
        help='Silent mode, log only warnings and errors',
        action='store_true')

    parser.add_argument(
        '-v', '--version',
        help='Print version of this software',
        action='version',
        version='plumbery ' + __version__)

    args = parser.parse_args(args)

    if args.debug:
        plogging.setLevel(logging.DEBUG)
    elif args.quiet:
        plogging.setLevel(logging.WARNING)
    else:
        plogging.setLevel(logging.INFO)

    if 'version' in args:
        print(args.version)

    args.fittings = args.fittings[0]
    plogging.debug("- loading '{}'".format(args.fittings))

    args.action = args.action[0].lower()

    args.blueprints = []
    args.facilities = []
    for token in args.tokens:
        if token[0] == '@':
            if token == '@':
                raise ValueError("Missing location after @. "
                                 "Correct example: '@AU11'")
            args.facilities.append(token[1:])
        else:
            args.blueprints.append(token)

    if len(args.blueprints) < 1:
        args.blueprints = None
    else:
        plogging.debug('blueprints: '+' '.join(args.blueprints))

    if len(args.facilities) < 1:
        args.facilities = None
    else:
        plogging.debug('facilities: '+' '.join(args.facilities))

    return args