File: issue73compareOrderedDict.py

package info (click to toggle)
python-hiyapyco 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 2,012; makefile: 237
file content (58 lines) | stat: -rwxr-xr-x 1,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env python

import sys
import os
import logging
import argparse

basepath = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.dirname(basepath))

import hiyapyco

class LoggingAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        # print '%r %r %r' % (namespace, values, option_string)
        logger = logging.getLogger()
        logger.setLevel(values)
        setattr(namespace, self.dest, values)

logger = logging.getLogger()
logging.basicConfig(
    level=logging.WARN,
    format='%(levelname)s\t[%(name)s] %(funcName)s: %(message)s'
    )

parser = argparse.ArgumentParser()
parser.add_argument(
    '-l', '--loglevel',
    help='set loglevel',
    type=str,
    choices=[k for k in logging._nameToLevel.keys() if isinstance(k, str)],
    action=LoggingAction
    )
parser.add_argument('-f', '--file', type=str, nargs='+', required=True, help='yaml file(s) to parse')
args = parser.parse_args()

if args.loglevel is None:
    logging.disable(logging.INFO)

# FIXME: in fact this should be the job of argparse
if args.file is None or len(args.file) == 0:
    raise Exception('please provide at least one yaml file!')

for  usedefaultyamlloader in [True, False]:
    print('='*10, 'usedefaultyamlloader=', usedefaultyamlloader, '='*10)
    conf = hiyapyco.load(
        *args.file,
        method=hiyapyco.METHOD_MERGE,
        interpolate=True,
        failonmissingfiles=True,
        usedefaultyamlloader=usedefaultyamlloader
        )
    print(conf)
    print('-'*10, 'YAML', '-'*10)
    print(hiyapyco.dump(conf, default_flow_style=False))

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 smartindent nu