Exemplo n.º 1
0
    def _parse_task(self, section):
        check.check_simple_config_section(section)

        values = section.to_dict(resolve_env_vars=True)

        system = values.pop('system', None)
        self._log.log_d('_parse_task: system={} host.SYSTEM={}'.format(
            system, host.SYSTEM))
        if system and system != host.SYSTEM:
            self._log.log_d('system {} does not match us {}'.format(
                system, host.SYSTEM))
            return None
        task_class_name = values.pop('class', None)
        if not task_class_name:
            raise computer_setup_error(
                'class missing for task "{}" - {}'.format(
                    section.header_.name, section.header_.origin))
        task_class = computer_setup_task_registry.get(task_class_name)
        if not task_class:
            origin = section.get_value_origin('class')
            raise computer_setup_error('unknown task class "{}" - {}'.format(
                task_class_name, origin, section.header_.origin))

        task_values = key_value_list()
        for next_values in section.get_all_values('value'):
            task_values.extend(key_value_list.parse(next_values))
        task = task_class()
        values = task_values.to_dict()
        return task, values
Exemplo n.º 2
0
    def update(self, config_filename, values):
        check.check_string(config_filename)
        check.check_string_seq(values)

        parsed_values = key_value_list.parse(' '.join(values))

        self._csm.add_tasks_from_config(config_filename)
        self._csm.run(parsed_values.to_dict())

        return 0
Exemplo n.º 3
0
    def test___str__(self):
        item = git_attributes_item(
            '*.png',
            key_value_list.parse('filter=lfs diff=lfs merge=lfs') +
            [key_value('text', False)])
        self.assertEqual('*.png filter=lfs diff=lfs merge=lfs -text',
                         str(item))

        item = git_attributes_item('*.txt',
                                   key_value_list([key_value('text', True)]))
        self.assertEqual('*.txt text', str(item))
Exemplo n.º 4
0
def _parse_args_env(env):
    if not env:
        return {}
    env = env[:]
    for i, e in enumerate(env):
        if not '=' in e:
            assert ' ' not in e
            env[i] = env[i] + '=1'
    kv = key_value_list.parse(' '.join(env),
                              empty_value='',
                              log_tag='bes_test')
    return kv.to_dict()
Exemplo n.º 5
0
  def set_values(self, values, hints = None):
    check.check_dict(hints, allow_none = True)

    if check.is_string(values):
      kv_values = key_value_list.parse(values)
    elif check.is_key_value_list(values):
      kv_values = values
    elif check.is_dict(values):
      kv_values = key_value_list.from_dict(values)
    else:
      raise TypeError('Unknown type for values: "{}" - "{}"'.format(type(values), values))
    
    for kv in kv_values:
      self.set_value(kv.key, kv.value, hints = hints)
Exemplo n.º 6
0
    def request(self, endpoint, args):
        check.check_string(endpoint)

        # Deal with situation where spacing around args is not consistent
        flat_args = text_replace.replace(' '.join(args), {
            ' =': '=',
            ' = ': '=',
            '= ': '='
        },
                                         word_boundary=False)
        params = key_value_list.parse(flat_args).to_dict()
        data = self._client.request(endpoint, params or None)
        print(pprint.pformat(data))
        return 0
Exemplo n.º 7
0
  def test_non_existent_file(self):
    tmp_file = self.make_temp_file()
    file_util.remove(tmp_file)
    c = ssh_config_file(tmp_file)

    self.assert_string_equal( '', str(c), strip = True, multi_line = True, native_line_breaks = True )
    c.update_host('orange', key_value_list.parse('User=sally IdentityFile=~/.ssh/sally_id_rsa'))

    expected = '''
Host orange
  User sally
  IdentityFile ~/.ssh/sally_id_rsa
'''
    self.assert_text_file_equal( expected, tmp_file, codec = 'utf-8', strip = True, native_line_breaks = True )
Exemplo n.º 8
0
  def parse(clazz, text):
    check.check_string(text)

    parsed = [ p for p in string_list_parser.parse(text, options = string_lexer_options.KEEP_QUOTES) ]
    if not parsed:
      raise ValueError('Invalid git attribute item.  Missing pattern: "{}"'.format(text))
    pattern = parsed.pop(0)
    attributes = key_value_list()
    for p in parsed:
      if '=' in p:
        attributes.extend(key_value_list.parse(p, string_lexer_options.KEEP_QUOTES))
      else:
        attributes.append(clazz._parse_bool_attribute(p))
    return git_attributes_item(pattern, attributes)
Exemplo n.º 9
0
  def test_update_host_new_hostname(self):
    content = '''
Host kiwi
  User fred
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes

Host lemon
  User fred
  IdentityFile ~/.ssh/id_rsa

Host apple
  User fred
  IdentityFile ~/.ssh/id_rsa
  Hostname 172.16.1.1
  Port 666

Host *
  IPQoS=throughput
'''
    tmp_file = self.make_temp_file(content = content)
    c = ssh_config_file(tmp_file)
    c.update_host('orange', key_value_list.parse('User=sally IdentityFile=~/.ssh/sally_id_rsa'))

    expected = '''
Host kiwi
  User fred
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes

Host lemon
  User fred
  IdentityFile ~/.ssh/id_rsa

Host apple
  User fred
  IdentityFile ~/.ssh/id_rsa
  Hostname 172.16.1.1
  Port 666

Host *
  IPQoS=throughput

Host orange
  User sally
  IdentityFile ~/.ssh/sally_id_rsa
'''
    
    self.assert_text_file_equal( expected, tmp_file, codec = 'utf-8', strip = True, native_line_breaks = True )
Exemplo n.º 10
0
    def test_parse(self):
        text = '''\
*.png filter=lfs diff=lfs merge=lfs -text
*.txt text
'''
        expected = git_attributes([
            git_attributes_item(
                '*.png',
                key_value_list.parse('filter=lfs diff=lfs merge=lfs') +
                [key_value('text', False)]),
            git_attributes_item('*.txt',
                                key_value_list([key_value('text', True)])),
        ])

        self.assertEqual(expected, git_attributes.parse(text))
Exemplo n.º 11
0
    def test___str__(self):
        l = git_attributes([
            git_attributes_item(
                '*.png',
                key_value_list.parse('filter=lfs diff=lfs merge=lfs') +
                [key_value('text', False)]),
            git_attributes_item('*.txt',
                                key_value_list([key_value('text', True)])),
        ])
        self.assert_string_equal('''\
*.png filter=lfs diff=lfs merge=lfs -text
*.txt text
''',
                                 str(l),
                                 native_line_breaks=True)
Exemplo n.º 12
0
    def system_info(clazz, guest_os, guest_os_detailed_data):
        check.check_string(guest_os)
        check.check_string(guest_os_detailed_data)

        if guest_os_detailed_data:
            details = key_value_list.parse(guest_os_detailed_data).to_dict()
        else:
            details = {}
        clazz._log.log_d('system_info: guest_os="{}" details="{}"'.format(
            guest_os, details))
        if details:
            family_name = details.get('familyName', None)
            if not family_name:
                raise vmware_error(
                    'Family name not found for guest os: "{}" - "{}"'.format(
                        guest_os, details))
            return clazz._system_info_with_details(family_name, details)
        else:
            return clazz._system_info_without_details(guest_os)
Exemplo n.º 13
0
 def _command_fs_set_attributes(self, config, remote_filename, params):
     values = key_value_list.parse(' '.join(params))
     return vfs_cli_command.set_attributes(config, remote_filename, values)