Пример #1
0
 def gen_ini(self):
     yield '\n[{0}]\n'.format(self.name)
     sections_dict = OrderedDict()
     for name, value in self.iteritems():
         if com_regx.match(name):
             yield '{0}\n'.format(value)
         elif isinstance(value, _Section):
             sections_dict.update({name: value})
         else:
             yield '{0} {1} {2}\n'.format(name, self.sep, value)
     for name, value in sections_dict.iteritems():
         for line in value.gen_ini():
             yield line
Пример #2
0
 def gen_ini(self):
     yield '\n[{0}]\n'.format(self.name)
     sections_dict = OrderedDict()
     for name, value in self.iteritems():
         if com_regx.match(name):
             yield '{0}\n'.format(value)
         elif isinstance(value, _Section):
             sections_dict.update({name: value})
         else:
             yield '{0} {1} {2}\n'.format(name, self.sep, value)
     for name, value in sections_dict.iteritems():
         for line in value.gen_ini():
             yield line
Пример #3
0
class StateRegistry(object):
    """
    The StateRegistry holds all of the states that have been created.
    """
    def __init__(self):
        self.empty()

    def empty(self):
        self.states = OrderedDict()
        self.requisites = []

    def salt_data(self):
        states = OrderedDict([
            (id_, state())
            for id_, state in self.states.iteritems()
        ])

        self.empty()

        return states

    def add(self, id_, state):
        if id_ in self.states:
            raise DuplicateState("A state with id '%s' already exists" % id_)

        # if we have requisites in our stack then add them to the state
        if len(self.requisites) > 0:
            for req in self.requisites:
                if req.requisite not in state.kwargs:
                    state.kwargs[req.requisite] = []
                state.kwargs[req.requisite].append(req())

        self.states[id_] = state

    def push_requisite(self, requisite):
        self.requisites.append(requisite)

    def pop_requisite(self):
        del self.requisites[-1]
Пример #4
0
 def _uncomment_if_commented(self, opt_key):
     # should be called only if opt_key is not already present
     # will uncomment the key if commented and create a place holder
     # for the key where the correct value can be update later
     # used to preserve the ordering of comments and commented options
     # and to make sure options without sectons go above any section
     options_backup = OrderedDict()
     comment_index = None
     for key, value in self.iteritems():
         if comment_index is not None:
             options_backup.update({key: value})
             continue
         if '#comment' not in key:
             continue
         opt_match = opt_regx.match(value.lstrip('#'))
         if opt_match and opt_match.group(2) == opt_key:
             comment_index = key
     for key in options_backup:
         self.pop(key)
     self.pop(comment_index, None)
     super(_Section, self).update({opt_key: None})
     for key, value in options_backup.iteritems():
         super(_Section, self).update({key: value})
Пример #5
0
 def _uncomment_if_commented(self, opt_key):
     # should be called only if opt_key is not already present
     # will uncomment the key if commented and create a place holder
     # for the key where the correct value can be update later
     # used to preserve the ordering of comments and commented options
     # and to make sure options without sectons go above any section
     options_backup = OrderedDict()
     comment_index = None
     for key, value in self.iteritems():
         if comment_index is not None:
             options_backup.update({key: value})
             continue
         if '#comment' not in key:
             continue
         opt_match = opt_regx.match(value.lstrip('#'))
         if opt_match and opt_match.group(2) == opt_key:
             comment_index = key
     for key in options_backup:
         self.pop(key)
     self.pop(comment_index, None)
     super(_Section, self).update({opt_key: None})
     for key, value in options_backup.iteritems():
         super(_Section, self).update({key: value})
Пример #6
0
class StateRegistry(object):
    """
    The StateRegistry holds all of the states that have been created.
    """
    def __init__(self):
        self.empty()

    def empty(self):
        self.states = OrderedDict()
        self.requisites = []

    def salt_data(self):
        states = OrderedDict([(id_, state())
                              for id_, state in self.states.iteritems()])

        self.empty()

        return states

    def add(self, id_, state):
        if id_ in self.states:
            raise DuplicateState("A state with id '%s' already exists" % id_)

        # if we have requisites in our stack then add them to the state
        if len(self.requisites) > 0:
            for req in self.requisites:
                if req.requisite not in state.kwargs:
                    state.kwargs[req.requisite] = []
                state.kwargs[req.requisite].append(req())

        self.states[id_] = state

    def push_requisite(self, requisite):
        self.requisites.append(requisite)

    def pop_requisite(self):
        del self.requisites[-1]
Пример #7
0
class StateRegistry(object):
    '''
    The StateRegistry holds all of the states that have been created.
    '''
    def __init__(self):
        self.empty()

    def empty(self):
        self.states = OrderedDict()
        self.requisites = []
        self.includes = []
        self.extends = OrderedDict()

    def include(self, *args):
        self.includes += args

    def salt_data(self):
        states = OrderedDict([(id_, state())
                              for id_, state in self.states.iteritems()])

        if self.includes:
            states['include'] = self.includes

        if self.extends:
            states['extend'] = OrderedDict([
                (id_, state()) for id_, state in self.extends.iteritems()
            ])

        self.empty()

        return states

    def add(self, id_, state, extend=False):
        if extend:
            attr = self.extends
        else:
            attr = self.states

        if id_ in attr:
            raise DuplicateState("A state with id '%s' already exists" % id_)

        # if we have requisites in our stack then add them to the state
        if len(self.requisites) > 0:
            for req in self.requisites:
                if req.requisite not in state.kwargs:
                    state.kwargs[req.requisite] = []
                state.kwargs[req.requisite].append(req())

        attr[id_] = state

    def extend(self, id_, state):
        self.add(id_, state, extend=True)

    def make_extend(self, name):
        return StateExtend(name)

    def push_requisite(self, requisite):
        self.requisites.append(requisite)

    def pop_requisite(self):
        del self.requisites[-1]
Пример #8
0
# -*- coding: utf-8 -*-
'''
The daemons package is used to store implimentations of the Salt Master and
Minion enabling different transports.
'''

# Import Python Libs
from collections import namedtuple

# Import Salt Libs
from salt.utils.odict import OrderedDict

# Python equivalent of an enum
APPL_KINDS = OrderedDict([('master', 0), ('minion', 1), ('syndic', 2),
                          ('call', 3)])
APPL_KIND_NAMES = OrderedDict(
    (v, k) for k, v in APPL_KINDS.iteritems())  # inverse map
ApplKind = namedtuple('ApplKind', APPL_KINDS.keys())
applKinds = ApplKind(**APPL_KINDS)
Пример #9
0
class StateRegistry(object):
    '''
    The StateRegistry holds all of the states that have been created.
    '''
    def __init__(self):
        self.empty()

    def empty(self):
        self.states = OrderedDict()
        self.requisites = []
        self.includes = []
        self.extends = OrderedDict()

    def include(self, *args):
        self.includes += args

    def salt_data(self):
        states = OrderedDict([
            (id_, state())
            for id_, state in self.states.iteritems()
        ])

        if self.includes:
            states['include'] = self.includes

        if self.extends:
            states['extend'] = OrderedDict([
                (id_, state())
                for id_, state in self.extends.iteritems()
            ])

        self.empty()

        return states

    def add(self, id_, state, extend=False):
        if extend:
            attr = self.extends
        else:
            attr = self.states

        if id_ in attr:
            raise DuplicateState("A state with id '%s' already exists" % id_)

        # if we have requisites in our stack then add them to the state
        if len(self.requisites) > 0:
            for req in self.requisites:
                if req.requisite not in state.kwargs:
                    state.kwargs[req.requisite] = []
                state.kwargs[req.requisite].append(req())

        attr[id_] = state

    def extend(self, id_, state):
        self.add(id_, state, extend=True)

    def make_extend(self, name):
        return StateExtend(name)

    def push_requisite(self, requisite):
        self.requisites.append(requisite)

    def pop_requisite(self):
        del self.requisites[-1]