Exemplo n.º 1
0
        self.statusWidget.config(background="yellow")

    def kill(self):
        try:
            # self.process.kill() # exit subprocess if GUI is closed (zombie!)
            os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)
            self.logger.debug('killing')
        except AttributeError:
            self.logger.error('tried killing')
            pass
        self.running.set('Idle: %s' % self.name)
        self.status.set('NOT RUNNING (YET)')
        self.statusWidget.config(background="yellow")


SafeConstructor.add_constructor(u'tag:yaml.org,2002:bool', add_bool)

parser = argparse.ArgumentParser()
parser.add_argument(
    '-log',
    '--loglevel',
    default='info',
    help='Provide logging level. Example --loglevel debug, default=info')

args = parser.parse_args()

logging.basicConfig(level=args.loglevel.upper(), format=LOGFORMAT)
loggerRoot = logging.getLogger('Python')
loggerRoot.info('Launching GUI')
loggerRoot.debug('Rootpath %s' % ROOTPATH)
Exemplo n.º 2
0
REQUIRED_KEYS = [
    "cli_version",
    "globals",
    "rules",
    "providers",
    "backend",
    "engine_version",
]


def add_bool(self, node):
    """Allows bools to be set as strings."""
    return self.construct_scalar(node)


SafeConstructor.add_constructor("tag:yaml.org,2002:bool", add_bool)


class ConfigParser:
    """Parses and validates reflex yaml config file."""

    def __init__(self, config_file):
        self.config_file = config_file
        self.raw_coniguration = {}
        self.rule_list = []

    def parse_valid_config(self):
        """Entrypoint to generate and validate config"""
        self.raw_configuration = (  # pylint: disable=attribute-defined-outside-init
            self.parse_yaml_config()
        )
Exemplo n.º 3
0
        value = self.construct_object(value_node, deep=deep)
        mapping[key] = value
    
    return mapping

BaseConstructor.construct_mapping = construct_ordered_mapping


def construct_yaml_map_with_ordered_dict(self, node):
    data = OrderedDict()
    yield data
    value = self.construct_mapping(node)
    data.update(value)

for t in [u'tag:yaml.org,2002:map', u'tag:yaml.org,2002:omap']:
    SafeConstructor.add_constructor( t, construct_yaml_map_with_ordered_dict )
    Constructor.add_constructor( t, construct_yaml_map_with_ordered_dict )
    yaml.add_constructor( t, construct_yaml_map_with_ordered_dict )


def represent_ordered_mapping(self, tag, mapping, flow_style=None):
    value = []
    node = yaml.MappingNode(tag, value, flow_style=flow_style)
    best_style = True
    
    if self.alias_key is not None:
        self.represented_objects[self.alias_key] = node
    
    if hasattr(mapping, 'items'):
        mapping = list(mapping.items())
    
Exemplo n.º 4
0
    def parse(self, content, **kwargs):
        """ Parses the given YAML content to create stringset and template

        Steps are:
            1. Load yaml content using our custom loader TxYamlLoader that
               in addition to the value for each key notes the `start` and
               `end` index of each node in the file and some metadata.
            2. Flattens the output of the loader to be a list of the form:
               ```
               [{
                   'key': 'string_key1',
                   'value': 'string1',
                   'end': <end_index_of_node>,
                   'start': <start_index_value>,
                   'style': '|, >, ...'
                },
                ...
               ]
               ```
            3. Iterates over the flattened list and for each entry creates an
               OpenString object, appends it to stringset and replace its value
               with the template_replacement in the template.
            4. Returns the (template, stringset) tuple.
        """
        template = []
        stringset = []
        # The first argument of the add_constructor method is the tag you want
        # to handle. If you provide None as an argument, all the unknown tags
        # will be handled by the constructor specified in the second argument.
        # We need this in order parse all unknown custom-tagged values as
        # strings.
        SafeConstructor.add_constructor(None,
                                        SafeConstructor.construct_yaml_str)
        yaml_data = self._load_yaml(content, loader=TxYamlLoader)
        yaml_data = self._get_yaml_data_to_parse(yaml_data)
        # Helper to store the processed data while parsing the file
        self._parsed_data = []
        self._parse_yaml_data(yaml_data, '', '')
        self._parsed_data = sorted(self._parsed_data,
                                   key=lambda node: node.get('start'))

        end = 0
        order = 0
        for node in self._parsed_data:
            start = node.get('start')
            end_ = node.get('end')
            key = node.get('key')
            tag = node.get('tag')
            value = node.get('value')
            style = node.get('style')
            if not value:
                continue
            if isinstance(value, dict) and not all(six.itervalues(value)):
                continue
            string_object = OpenString(
                key, value, context=tag or '', flags=style, order=order,
            )
            stringset.append(string_object)
            order += 1
            template.append(u"{}{}".format(content[end:start],
                                           string_object.template_replacement))
            comment = self._find_comment(content, end, start)
            string_object.developer_comment = comment
            end = end_

        template.append(content[end:])
        template = u''.join(template)
        return template, stringset
Exemplo n.º 5
0
    return mapping


BaseConstructor.construct_mapping = construct_ordered_mapping


def construct_yaml_map_with_ordered_dict(self, node):
    data = OrderedDict()
    yield data
    value = self.construct_mapping(node)
    data.update(value)


for t in [u'tag:yaml.org,2002:map', u'tag:yaml.org,2002:omap']:
    SafeConstructor.add_constructor(t, construct_yaml_map_with_ordered_dict)
    Constructor.add_constructor(t, construct_yaml_map_with_ordered_dict)
    yaml.add_constructor(t, construct_yaml_map_with_ordered_dict)


def represent_ordered_mapping(self, tag, mapping, flow_style=None):
    value = []
    node = yaml.MappingNode(tag, value, flow_style=flow_style)
    best_style = True

    if self.alias_key is not None:
        self.represented_objects[self.alias_key] = node

    if hasattr(mapping, 'items'):
        mapping = list(mapping.items())
Exemplo n.º 6
0
    def parse(self, content, **kwargs):
        """ Parses the given YAML content to create stringset and template

        Steps are:
            1. Load yaml content using our custom loader TxYamlLoader that
               in addition to the value for each key notes the `start` and
               `end` index of each node in the file and some metadata.
            2. Flattens the output of the loader to be a list of the form:
               ```
               [{
                   'key': 'string_key1',
                   'value': 'string1',
                   'end': <end_index_of_node>,
                   'start': <start_index_value>,
                   'style': '|, >, ...'
                },
                ...
               ]
               ```
            3. Iterates over the flattened list and for each entry creates an
               OpenString object, appends it to stringset and replace its value
               with the template_replacement in the template.
            4. Returns the (template, stringset) tuple.
        """
        template = []
        stringset = []
        # The first argument of the add_constructor method is the tag you want
        # to handle. If you provide None as an argument, all the unknown tags
        # will be handled by the constructor specified in the second argument.
        # We need this in order parse all unknown custom-tagged values as
        # strings.
        SafeConstructor.add_constructor(None,
                                        SafeConstructor.construct_yaml_str)
        yaml_data = self._load_yaml(content, loader=TxYamlLoader)
        yaml_data = self._get_yaml_data_to_parse(yaml_data)
        # Helper to store the processed data while parsing the file
        self._parsed_data = []
        self._parse_yaml_data(yaml_data, '', '')
        self._parsed_data = sorted(self._parsed_data,
                                   key=lambda node: node.get('start'))

        end = 0
        order = 0
        for node in self._parsed_data:
            start = node.get('start')
            end_ = node.get('end')
            key = node.get('key')
            tag = node.get('tag')
            value = node.get('value')
            style = node.get('style')
            if not value:
                continue
            if isinstance(value, dict) and not all(six.itervalues(value)):
                continue
            string_object = OpenString(
                key,
                value,
                context=tag or '',
                flags=style,
                order=order,
            )
            stringset.append(string_object)
            order += 1
            template.append(u"{}{}".format(content[end:start],
                                           string_object.template_replacement))
            comment = self._find_comment(content, end, start)
            string_object.developer_comment = comment
            end = end_

        template.append(content[end:])
        template = u''.join(template)
        return template, stringset