コード例 #1
0
ファイル: interpreter.py プロジェクト: derdon/chef
def main(argv=None):
    def user_friendly_excepthook(exctype, value, traceback):
        'uses only a custom output if exception is ChefError'
        if ChefError in exctype.mro():
            # FIXME: show bold and red output!
            # -> relevant line bold, error message red
            print value
            print
            with open(filename) as f:
                for lineno, line in enumerate(f):
                    # print two lines before and after the affected invalid
                    # line as context (inlcuding line numbers)
                    # TODO: right-align the col num, don't use \t
                    if lineno in xrange(value.lineno - 2, value.lineno + 3):
                        print '%d\t%s' % (lineno, line),
        else:
            original_excepthook(exctype, value, traceback)
    original_excepthook = sys.excepthook
    sys.excepthook = user_friendly_excepthook
    if argv is None:
        argv = sys.argv[1:]
    args = parse_args(argv)
    filename = args.file
    if filename:
        with open(filename) as f:
            parsed_recipe = parse_recipe(f)
    else:
        parsed_recipe = parse_recipe(sys.stdin)
    if args.parse_only:
        pretty.pprint(parsed_recipe)
    else:
        interpret_recipe(parsed_recipe)
コード例 #2
0
ファイル: interpreter.py プロジェクト: derdon/chef
def interpret_file(f):
    interpret_recipe(parse_recipe(f))