Esempio n. 1
0
 def __init__(self, repo, args):
     parts = yamlutil.load_dict(args)
     self._repo = repo
     self._kinds = []
     self._names = []
     for name, kindstr in parts.items():
         kind = self._repo.get_kind(kindstr)
         self._names.append(name)
         self._kinds.append(kind)
Esempio n. 2
0
 def _read_packages(filename):
     if os.path.isfile(filename):
         with open(filename) as f:
             for item in yamlutil.load_dict(f, load_all=True):
                 if isinstance(item, list):
                     for obj in item:
                         yield obj
                 else:
                     yield item
     elif os.path.isdir(filename):
         for dirpath, dirnames, filenames in os.walk(filename):
             for filename in filenames:
                 filename = os.path.join(dirpath, filename)
                 with open(filename) as f:
                     for item in yamlutil.load_dict(f, load_all=True):
                         if isinstance(item, list):
                             for obj in item:
                                 yield obj
                         else:
                             yield item
     else:
         raise PyautoException(
             'Not a file or directory: {0}'.format(filename))
Esempio n. 3
0
 def get_value(self):
     value = None
     if self.env:
         if not self.name:
             self['name'] = self.env
         value = self.get_env()
     elif self.resource:
         value = self.get_resource()
     elif self.file:
         value = self.get_file()
     elif self.function:
         value = self.get_function()
     elif self.task is not None:
         value = self.run_task()
     elif self.map is not None:
         value = self.get_map()
     elif self.string is not None:
         value = self.string
     else:
         raise Exception('unknown variable type: {0}'.format(self))
     if value is None:
         if self.default:
             value = self.default
         elif not self.optional:
             raise Exception(
                 'unable to get a value for variable: {0}'.format(self))
     if self.parse:
         if 'json' == self.parse:
             value = json.loads(value)
         elif 'yaml' == self.parse:
             value = yamlutil.load_dict(value)
         else:
             raise Exception('unknown parse type: {0}'.format(self.parse))
     if isinstance(value, (dict, OrderedDict, config.Config)) and \
             self.select:
         value = jmespath.search(self.select, value)
     if self.name:
         return {self.name: value}
     else:
         return value
Esempio n. 4
0
import os
import json
from pyauto.util import yamlutil

dirname = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(dirname, 'pkg_.yml')) as f:
    packages = [pkg for pkg in yamlutil.load_dict(f, load_all=True)]


class Base(object):
    def __init__(self, obj):
        self.obj = obj

    def __str__(self):
        return json.dumps(self.obj.data, indent=2)

    def __repr__(self):
        return self.__str__()


class T1(Base):
    def inspect(self, **kwargs):
        print(self)


class T2(Base):
    def inspect(self, **kwargs):
        print(self.obj.e.value)


class T3(Base):
Esempio n. 5
0
 def parse_objects(self, data):
     data = yamlutil.load_dict(data, load_all=True)
     return self.load_objects(data)
Esempio n. 6
0
 def run_query(self, selector, verbose):
     q = yamlutil.load_dict(selector)
     res = self.repository.query(q, id=True)
     if verbose:
         res = [self.repository[tag].data for tag in res]
     logger.debug(yamlutil.dump_dict([o for o in res]))
Esempio n. 7
0
 def invoke_kind_task(self, kind_task, tag, args):
     args = yamlutil.load_dict(args or '{}')
     ref = api.TaskReference(kind_task)
     return self.repository.invoke_kind_task(ref.kind, tag, ref.name, args)
Esempio n. 8
0
 def invoke_task_sequence(self, targets, task, inspect=False):
     obj = yamlutil.load_dict(targets)
     return self.tasks[task].invoke(obj, inspect=inspect)
Esempio n. 9
0
 def _read_packages(self, fn):
     with open(fn) as f:
         data = yamlutil.load_dict(f)
         for item in data['packages']:
             for pkg in Packages(item):
                 yield pkg
Esempio n. 10
0
 def read_tasks(self):
     with open(self.tasks_filename) as f:
         tasks = yamlutil.load_dict(f)
     self.tasks = api.TaskSequences(self.repository, tasks)