Пример #1
0
    def parse_show_ref_output(clazz,
                              s,
                              sort_type=None,
                              reverse=False,
                              limit=None,
                              prefix=None):
        check.check_string(s)
        sort_type = git_tag_sort_type.check_sort_type(sort_type)
        check.check_bool(reverse)
        check.check_int(limit, allow_none=True)
        check.check_string(prefix, allow_none=True)

        lines = text_line_parser.parse_lines(s,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        if not lines:
            return git_tag_list()
        parsed_tags = [clazz._parse_show_ref_one_line(line) for line in lines]
        tags = git_tag_list(parsed_tags)
        if sort_type == 'lexical':
            tags.sort_lexical(reverse=reverse)
        elif sort_type == 'version':
            tags.sort_version(reverse=reverse)
        if prefix:
            tags = tags.filter_by_prefix(prefix)
        if limit != None:
            tags = tags[0:limit]
        return tags
Пример #2
0
 def read_file(clazz, filename):
     filename = path.abspath(filename)
     if not path.isfile(filename):
         raise IOError('not a file: %s' % (filename))
     text = file_util.read(filename, codec='utf-8')
     patterns = text_line_parser.parse_lines(text).to_list()
     return file_ignore_item(path.dirname(filename), patterns)
Пример #3
0
 def list_processes(clazz):
   'List all processes.'
   rv = execute.execute('ps aux')
   lines = text_line_parser.parse_lines(rv.stdout, strip_comments = False, strip_text = True, remove_empties = True)
   result = []
   for i, line in enumerate(lines):
     if i == 0:
       continue
     parts = ps_output_parser.parse_ps_output_line(line, 11)
     user = parts[0]
     pid = parts[1]
     cpu = parts[2]
     mem = parts[3]
     vsz = parts[4]
     rss = parts[5]
     tty = parts[6]
     if tty.startswith('?'):
       tty = None
     else:
       tty = '/dev/tty' + tty
     command = parts[-1]
     other = {
       'vsz': vsz,
       'rss': rss,
       'tty': tty,
     }
     info = process_info(user, pid, cpu, mem, command, other)
     result.append(info)
   return result
Пример #4
0
    def parse(clazz, text):
        check.check_string(text)

        lines = text_line_parser.parse_lines(text,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        return git_status_list([git_status.parse_line(line) for line in lines])
Пример #5
0
    def parse_show_ref_output(clazz, text):
        check.check_string(text)

        lines = text_line_parser.parse_lines(text,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        items = [clazz._parse_line(line) for line in lines]
        head_item = next(
            iter([
                item for item in items
                if item.full_name.startswith('refs/heads')
            ]), None)
        remote_item = next(
            iter([
                item for item in items
                if item.full_name.startswith('refs/remotes')
            ]), None)
        tag_item = next(
            iter([
                item for item in items
                if item.full_name.startswith('refs/tags')
            ]), None)

        clazz.log.log_d('       text: {}'.format(text))
        clazz.log.log_d('      lines: {}'.format(lines))
        clazz.log.log_d('  head_item: {}'.format(head_item))
        clazz.log.log_d('remote_item: {}'.format(remote_item))
        clazz.log.log_d('   tag_item: {}'.format(tag_item))

        if tag_item and (head_item or remote_item):
            raise git_error(
                'Ref that is both a branch and tag is not supported: {}'.
                format(tag_item.full_name))

        if tag_item:
            ref_type = clazz.REF_TYPE_TAG
            commit = tag_item.commit
            full_name = tag_item.full_name
            has_remote = False
        else:
            ref_type = clazz.REF_TYPE_BRANCH
            if head_item:
                commit = head_item.commit
                full_name = head_item.full_name
                has_remote = remote_item != None
            elif remote_item:
                commit = remote_item.commit
                full_name = remote_item.full_name
                has_remote = True
            else:
                raise git_error(
                    'Failed to determine ref type: {}'.format(text))

        name = full_name.split('/')[-1]
        commit_short = git_commit_hash.shorten(commit)
        return git_ref_info(name, full_name, ref_type, commit, commit_short,
                            has_remote)
Пример #6
0
 def test_parse_lines(self):
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('foo\nbar\n') )
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('foo\nbar') )
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('\nfoo\nbar') )
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('\n foo\nbar') )
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('\n foo\nbar ') )
   self.assertEqual( [ 'foo', 'bar' ], text_line_parser.parse_lines('\n foo\nbar \n') )
   self.assertEqual( [], text_line_parser.parse_lines('\n\n\n') )
Пример #7
0
 def parse_lines(clazz, s, sort = False, unique = False):
   result = text_line_parser.parse_lines(s,
                                         strip_comments = False,
                                         strip_text = True,
                                         remove_empties = True)
   if sort:
     result = sorted(result)
   if unique:
     result = algorithm.unique(result)
   return result
Пример #8
0
 def _parse_text(clazz, text, filename, delimiter):
     check.check_string(text)
     lines = text_line_parser.parse_lines(text,
                                          strip_comments=True,
                                          strip_text=True,
                                          remove_empties=True)
     result = {}
     for line in lines:
         kv = key_value.parse(line, delimiter=delimiter)
         result[kv.key] = string_util.unquote(kv.value)
     return result
Пример #9
0
 def parse_branch_status(clazz, s):
   lines = text_line_parser.parse_lines(s, strip_comments = False, strip_text = True, remove_empties = True)
   if not lines:
     return git_branch_status(0, 0)
   ahead = re.findall(r'.*\[ahead\s+(\d+).*', lines[0])
   if ahead:
     ahead = int(ahead[0])
   behind = re.findall(r'.*behind\s+(\d+)\].*', lines[0])
   if behind:
     behind = int(behind[0])
   return git_branch_status(ahead or 0, behind or 0)
Пример #10
0
    def read_tag_list_file(clazz, filename):
        'Read a list of tags from a file.  Each line should be one tag'
        check.check_string(filename)

        text = file_util.read(filename)
        lines = text_line_parser.parse_lines(text, remove_empties=True)
        result = []
        for i, line in enumerate(lines):
            if line:
                result.append(line)
        return sorted(result)
Пример #11
0
  def parse_text(clazz, text):
    check.check_string(text)

    lines = text_line_parser.parse_lines(text, strip_text = True, remove_empties = True)
    values = {}
    for line in lines:
      key, delimiter, value = line.partition(':')
      key = key.strip()
      value = value.strip()
      values[key] = clazz._parse_value(key, value)
    return cpu_info(values)
Пример #12
0
    def parse_head_info(clazz, root_dir, text):
        check.check_string(root_dir, allow_none=True)
        check.check_string(text)

        clazz.log.log_d('parse_head_info: text={}'.format(text))

        if text == '':
            return git_head_info(clazz.STATE_NOTHING, None, None, None, None,
                                 None)

        lines = text_line_parser.parse_lines(text,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        clazz.log.log_d('parse_head_info: lines={}'.format(lines))
        active_line = clazz._find_active_branch_entry(lines)
        if not active_line:
            raise git_error('Failed to get head info')
        detached_info = clazz._parse_detached_head_line(active_line)
        clazz.log.log_d(
            'parse_head_info: detached_info={}'.format(detached_info))

        if detached_info:
            if root_dir:
                ref_branches = git_ref.branches_for_ref(
                    root_dir, detached_info.commit)
            else:
                ref_branches = None
            if detached_info.ref != detached_info.commit:
                state = clazz.STATE_TAG
                ref = detached_info.ref
            else:
                state = clazz.STATE_DETACHED_COMMIT
                ref = None
            return git_head_info(state, None, ref, detached_info.commit,
                                 detached_info.message, ref_branches)
        info = clazz._parse_active_branch_entry(active_line)
        if not info:
            raise git_error(
                'Failed to parse head info: "{}"'.format(active_line))
        branch = info[0].strip()
        assert branch
        commit_hash = info[1]
        assert commit_hash
        commit_message = info[2]
        assert commit_message
        return git_head_info(clazz.STATE_BRANCH, branch, None, commit_hash,
                             commit_message, None)
Пример #13
0
    def _download_available_index(clazz):
        'Download and parse the available python version index.'

        response = url_util.get('https://www.python.org/ftp/python/')
        content = response.content.decode('utf-8')
        lines = text_line_parser.parse_lines(content,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        result = python_version_list()
        for line in lines:
            f = re.findall(r'^.*href=\"(\d+\.\d+.*)\/\".*$', line)
            if len(f) == 1:
                v = python_version(f[0])
                if v.is_full_version():
                    result.append(v)
        return result
Пример #14
0
  def vm_snapshots(self, vmx_filename, tree = False):
    check.check_string(vmx_filename)
    check.check_bool(tree)

    vmware_vmx_file.check_vmx_file(vmx_filename)
    self._log.log_method_d()
    args = [
      'listSnapshots',
      vmx_filename,
    ]
    rv = self.run(args,
                  raise_error = True,
                  error_message = 'Failed to list snapshots for {}'.format(vmx_filename))
    lines = text_line_parser.parse_lines(rv.output,
                                         strip_comments = False,
                                         strip_text = True,
                                         remove_empties = True)
    return lines[1:]
Пример #15
0
    def _parse_ssh_keyscan_output(clazz, s, include_comment=True):
        'Parse the output of ssh-keyscan'

        lines = text_line_parser.parse_lines(s,
                                             strip_comments=False,
                                             strip_text=True,
                                             remove_empties=True)
        if len(lines) != 2:
            raise ssh_config_error(
                'Invalid ssh-keyscan output.  Should be 2 lines:\n{}'.format(
                    s))
        comment = lines[0] if include_comment else None
        parts = string_util.split_by_white_space(lines[1], strip=True)
        if len(parts) != 3:
            raise ssh_config_error(
                'Invalid ssh-keyscan parts.  Should be 3 parts: "{}"'.format(
                    lines[1]))
        hostname, key_type, key = parts
        return ssh_known_host([hostname], key_type, key, comment)
Пример #16
0
 def _parse_lines(self, text):
   return text_line_parser.parse_lines(text,
                                       strip_comments = False,
                                       strip_text = True,
                                       remove_empties = True)
Пример #17
0
 def parse_lines(clazz, s):
     return text_line_parser.parse_lines(s,
                                         strip_comments=False,
                                         strip_text=True,
                                         remove_empties=True)
Пример #18
0
 def read_patterns(clazz, filename):
     'Return a list of members that match any pattern in patterns.'
     text = file_util.read(filename, codec='utf8')
     return text_line_parser.parse_lines(text).to_list()