/usr/lib/python2.7/dist-packages/jujubundlelib/cli.py is in python-jujubundlelib 0.4.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # Copyright 2015 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.
from __future__ import (
print_function,
unicode_literals,
)
import argparse
import json
import sys
import yaml
import jujubundlelib
from jujubundlelib import (
changeset,
validation,
)
# Retrieve the application version.
version = jujubundlelib.get_version()
def get_changeset(args):
"""Dump the changeset objects as JSON, reading the provided bundle YAML.
The YAML can be provided either from stdin or by passing a file path as
first argument.
"""
# Parse the arguments.
parser = argparse.ArgumentParser(description=get_changeset.__doc__)
parser.add_argument(
'infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin,
help='path to the bundle YAML file')
parser.add_argument(
'--version', action='version', version='%(prog)s {}'.format(version))
options = parser.parse_args(args)
# Parse the provided YAML file.
try:
bundle = yaml.safe_load(options.infile)
except Exception:
return 'error: the provided bundle is not a valid YAML'
# Validate the bundle object.
errors = validation.validate(bundle)
if errors:
return '\n'.join(errors)
# Dump the changeset to stdout.
print('[')
for num, change in enumerate(changeset.parse(bundle)):
if num:
print(',')
print(json.dumps(change))
print(']')
|