コード例 #1
0
 def _parse_item(clazz, s):
   parts = string_util.split_by_white_space(s, strip = True)
   assert len(parts) == 3
   name = parts[0]
   mtime = float(parts[1])
   checksum = parts[2]
   return E(name, mtime, checksum)
コード例 #2
0
ファイル: recipe_parser.py プロジェクト: reconstruir/rebuild
 def _parse_package_header(self, node):
     parts = string_util.split_by_white_space(node.data.text, strip=True)
     num_parts = len(parts)
     if num_parts not in [3, 4]:
         self._error(
             'package section should begin with \"package $name $ver $rev\" instead of \"%s\"'
             % (node.data.text), node)
     if parts[0] != 'package':
         self._error(
             'package section should begin with \"package $name $ver $rev\" instead of \"%s\"'
             % (node.data.text), node)
     if num_parts == 3:
         name = parts[1].strip()
         version = build_version.parse(parts[2])
         return name, version
     elif num_parts == 4:
         name = parts[1].strip()
         version = build_version.parse(parts[2])
         if version.revision != 0:
             self._error(
                 'revision given multiple times: %s' % (node.data.text),
                 node)
         revision = parts[3].strip()
         return name, build_version(version.upstream_version, revision,
                                    version.epoch)
コード例 #3
0
 def _parse_metadata(self, node):
     parts = string_util.split_by_white_space(node.data.text, strip=True)
     assert parts[0] == 'fake_package'
     parts.pop(0)
     if len(parts) != len(artifact_descriptor._fields):
         self._error(
             'invalid metadata for fake_package: \"%s\"' %
             (' '.join(parts)), node)
     return artifact_descriptor(*parts)
コード例 #4
0
 def installed_packages(clazz):
     'Return a list of installed pacakge.'
     cmd = 'dpkg -l'
     rv = clazz._call_dpkg(cmd)
     if rv.exit_code != 0:
         raise RuntimeError('Failed to execute: %s' % (cmd))
     lines = rv.stdout.strip().split('\n')
     lines = [l for l in lines if l.startswith('ii')]
     lines = [string_util.split_by_white_space(l)[1] for l in lines]
     return sorted(lines)
コード例 #5
0
ファイル: sample_web_server.py プロジェクト: reconstruir/bes
 def _command_loop(self):
   try:
     cmd = string_util.split_by_white_space(input('CMD> '), strip = True)
     if cmd:
       return self._handle_command(cmd)
   except KeyboardInterrupt as ex:
     return False
   except EOFError as ex:
     return False
   return True
コード例 #6
0
 def __parse_ldd_line(clazz, line):
     line = line.strip()
     if not line:
         return None
     parts = string_util.split_by_white_space(line, strip=True)
     if len(parts) >= 2 and parts[1] == '=>' and path.exists(parts[2]):
         return parts[2]
     elif path.exists(parts[0]):
         return parts[0]
     else:
         return None
コード例 #7
0
ファイル: lipo.py プロジェクト: reconstruir/rebuild
 def archs(clazz, archive, lipo_exe=None):
     rv = clazz.__call_lipo_info(archive, lipo_exe=lipo_exe)
     ex = re.findall(clazz.FAT_EXPRESSION, rv.stdout)
     if ex:
         archs = string_util.split_by_white_space(ex[0])
     else:
         ex = re.findall(clazz.THIN_EXPRESSION, rv.stdout)
         if len(ex) != 1:
             raise RuntimeError('Invalid archive for lipo: %s' % (archive))
         archs = ex
     return sorted([arch.strip() for arch in archs])
コード例 #8
0
 def parse(clazz, origin, text, node):
     if origin:
         check.check_value_origin(origin)
     check.check_node(node)
     parts = string_util.split_by_white_space(text)
     if len(parts) < 1:
         raise ValueError('%s: expected filename instead of: %s' %
                          (origin, text))
     where = parts[0]
     rest = string_util.replace(text, {where: ''})
     properties = clazz.parse_properties(rest)
     return clazz(origin=origin, where=where, properties=properties)
コード例 #9
0
 def parse(clazz, text, line_number):
     if not text:
         return None
     parts = string_util.split_by_white_space(text, strip=True)
     if len(parts) < 2:
         raise RuntimeError('invalid arg spec: "%s"' % (text))
     name = parts[0]
     class_name = parts[1].lower()
     default = None
     if len(parts) > 2:
         default = ' '.join(parts[2:])
     return clazz(name, class_name, default, line_number)
コード例 #10
0
ファイル: test_string_util.py プロジェクト: reconstruir/bes
 def test_split_by_white_space(self):
   self.assertEqual( [ 'a', 'b', 'c' ], SU.split_by_white_space('a b c') )
   self.assertEqual( [ 'a', 'b', 'c' ], SU.split_by_white_space(' a b c') )
   self.assertEqual( [ 'a', 'b', 'c' ], SU.split_by_white_space(' a b c ') )
   self.assertEqual( [ 'a', 'b', 'c' ], SU.split_by_white_space(' a b  c ') )
   self.assertEqual( [], SU.split_by_white_space('') )
   self.assertEqual( ['a'], SU.split_by_white_space('a') )
コード例 #11
0
ファイル: address.py プロジェクト: reconstruir/bes
 def parse_city_and_state(clazz, s):
   '''
   Parse text in the form off "City, ST" "City ST" "ST, City" "ST City" for city and state
   or None if the state or format cannot be determined.
   '''
   if ',' in s:
     parts = s.split(',')
   else:
     parts = string_util.split_by_white_space(s)
   state_index = clazz._find_state_index(parts)
   if state_index < 0:
     return None
   state = parts[state_index].strip()
   parts[state_index] = ''
   city = ' '.join(parts).strip()
   return clazz._city_state(city, state)
コード例 #12
0
 def parse(clazz, origin, text, node):
     if origin:
         check.check_value_origin(origin)
     check.check_node(node)
     parts = string_util.split_by_white_space(text)
     if len(parts) < 2:
         raise ValueError(
             '%s: expected filename and dst_filename instead of: %s' %
             (origin, text))
     filename = parts[0]
     dst_filename = parts[1]
     rest = text.replace(filename, '')
     rest = rest.replace(dst_filename, '')
     properties = clazz.parse_properties(rest)
     return clazz(origin=origin,
                  filename=filename,
                  dst_filename=dst_filename,
                  properties=properties)
コード例 #13
0
    def _tokenize(clazz, text):
        num_colon = text.count(':')
        if num_colon > 1:
            raise ValueError('Invalid text - only one colon is allowed: %s' %
                             (text))
        elif num_colon == 0:
            global_mask = None
            req_text = text
        else:
            assert num_colon == 1
            left, _, right = text.partition(':')
            global_mask = left.strip()
            req_text = right.strip()

        last_token = None
        for word in string_util.split_by_white_space(req_text):
            if last_token:
                if clazz._word_is_operator(word):
                    token = clazz._token(clazz._TOKEN_OPERATOR, word,
                                         global_mask)
                elif clazz._word_is_hardness(word):
                    token = clazz._token(clazz._TOKEN_HARDNESS, word,
                                         global_mask)
                elif last_token.type == clazz._TOKEN_OPERATOR:
                    token = clazz._token(clazz._TOKEN_VERSION, word,
                                         global_mask)
                else:
                    token = clazz._make_name_token(word, global_mask)
            else:
                if clazz._word_is_hardness(word):
                    token = clazz._token(clazz._TOKEN_HARDNESS, word,
                                         global_mask)
                else:
                    token = clazz._make_name_token(word, global_mask)
            yield token
            last_token = token
        yield clazz._token(clazz._TOKEN_END, None, None)
コード例 #14
0
ファイル: config_data.py プロジェクト: reconstruir/bes
 def parse(clazz, text, filename = '<unknown>'):
   name = None
   unixpath = None
   pythonpath = None
   requires = None
   for line in text_line_parser(text):
     text = line.text_no_comments.strip()
     if text:
       key, sep, value = text.partition(':')
       if sep != ':':
         raise ValueError('Invalid config line \"%s\" at %s:%s' % (line.text, filename, line.line_number))
       key = key.strip()
       value = value.strip()
       if key == 'name':
         name = value
       elif key in [ 'unixpath' ]:
         unixpath = value.split(':')
       elif key in [ 'pythonpath' ]:
         pythonpath = value.split(':')
       elif key == 'requires':
         requires = set(string_util.split_by_white_space(value))
       else:
         raise ValueError('Invalid config value \"%s\" at %s:%s' % (line.text, filename, line.line_number))
   return clazz(name, unixpath, pythonpath, requires)
コード例 #15
0
ファイル: config_file.py プロジェクト: reconstruir/rebuild
 def __parse_list(clazz, s, variables):
     result = string_util.split_by_white_space(s, strip=True)
     return [variable.substitute(x, variables) for x in result]
コード例 #16
0
ファイル: pkg_config.py プロジェクト: reconstruir/rebuild
 def _parse_flags(clazz, s):
     flags = string_util.split_by_white_space(s)
     return algorithm.unique([flag.strip() for flag in flags])
コード例 #17
0
 def __parse_packages(clazz, s):
     s = comments.strip_line(s, strip_head=True, strip_tail=True)
     return [token.strip() for token in string_util.split_by_white_space(s)]
コード例 #18
0
 def _parse_list_all_output(clazz, stdout):
     lines = stdout.strip().split('\n')
     return [
         string_util.split_by_white_space(line, strip=True)[0]
         for line in lines
     ]
コード例 #19
0
 def __unduplicate_flags(clazz, flags):
     'Unduplicate flags.'
     v = string_util.split_by_white_space(flags)
     unique_v = algorithm.unique(v)
     return ' '.join(unique_v)
コード例 #20
0
ファイル: status.py プロジェクト: reconstruir/bes
 def parse_line(clazz, s):
   v = string_util.split_by_white_space(s)
   action = v[0]
   filename = v[1]
   args = tuple(v[2:0]) or ()
   return clazz(action, filename, *args)
コード例 #21
0
ファイル: make_platform_db.py プロジェクト: reconstruir/bes
def parse_line(s):
  fields = string_util.split_by_white_space(s, strip = True)
  archs = fields[2].split(',')
  fields[2] = tuple(fields[2].split(','))
  return host_info(*fields)