示例#1
0
 def _existing_split_dirs_common_num_digits(clazz, dirs, prefix):
   basenames = [ path.basename(f) for f in dirs ]
   #clazz._log.log_d('basenames={}'.format(basenames))
   without_prefices = [ string_util.remove_head(f, prefix) for f in basenames ]
   #clazz._log.log_d('without_prefices={}'.format(without_prefices))
   lengths = list(set([ len(f) for f in without_prefices ]))
   if len(lengths) == 1:
     return lengths[0]
   return None
示例#2
0
 def _index_for_vm(self, vmx_filename):
   check.check_string(vmx_filename)
   
   d = self._to_dict()
   for section, values in d.items():
     if section.startswith('index'):
       if 'id' in values:
         index_id = values['id']
         if index_id == vmx_filename:
           return int(string_util.remove_head(section, 'index'))
   return None
示例#3
0
 def _indeces(self):
   d = self._to_dict()
   index_dict = {}
   for key, values in d.items():
     if key.startswith('index'):
       index = int(string_util.remove_head(key, 'index'))
       index_dict[index] = values
   result = [ None ] * len(index_dict)
   for index, values in index_dict.items():
     result[index] = values
   assert None not in result
   return result
示例#4
0
 def list_remote_branches(clazz, root, limit = None):
   check.check_string(root)
   check.check_int(limit, allow_none = True)
   
   rv = git_exe.call_git(root, [ 'branch', '--verbose', '--list', '--no-color', '--remote' ])
   lines = git_exe.parse_lines(rv.stdout)
   lines = [ line for line in lines if not ' -> ' in line ]
   lines = [ string_util.remove_head(line, 'origin/') for line in lines ]
   branches = git_branch_list([ git_branch.parse_branch(line, 'remote') for line in lines ])
   branches = clazz._branch_list_determine_authors(root, branches)
   if limit != None:
     branches = branches[0:limit]
   return branches
示例#5
0
    def parse_entry(clazz, text):
        check.check_string(text)

        parts = string_util.split_by_white_space(text, strip=True)
        if len(parts) < 3:
            raise git_error(
                'Invalid git lfs entry.  Should have 3 parts: "{}"'.format(
                    text))
        oid = parts.pop(0)
        is_pointer_flag = parts.pop(0)
        is_pointer = is_pointer_flag == '-'
        head = oid + ' ' + is_pointer_flag + ' '
        filename = string_util.remove_head(text, head)
        return git_lfs_entry(filename, oid, is_pointer)
示例#6
0
    def branches_for_ref(clazz, root_dir, ref):
        'Return a list of branches that contain the ref.'
        check.check_string(root_dir)
        check.check_string(ref)

        rv = git_exe.call_git(root_dir,
                              ['branch', '-a', '--verbose', '--contains', ref])
        lines = git_exe.parse_lines(rv.stdout)
        lines = [line for line in lines if not '(HEAD detached' in line]
        branches = [git_branch.parse_branch(line, 'local') for line in lines]
        branches = [branch.name for branch in branches]
        branches = [
            string_util.remove_head(branch, 'remotes/origin/')
            for branch in branches
        ]
        blacklist = {'HEAD'}
        branches = [branch for branch in branches if branch not in blacklist]
        return sorted(list(set(branches)))
示例#7
0
  def filename_info(clazz, pip_exe):
    'Return info about the pip exe filename'
    check.check_string(pip_exe)

    if host.is_windows():
      pip_exe_lower = pip_exe.lower()
      ext = filename_util.extension(pip_exe_lower)
      if ext in ( 'cmd', 'exe', 'bat', 'ps1' ):
        basename = filename_util.without_extension(path.basename(pip_exe_lower))
      else:
        basename = path.basename(pip_exe_lower)
    else:
      basename = path.basename(pip_exe)
    if not basename.startswith('pip'):
      return clazz._pip_filename_info(None, None)
    version = string_util.remove_head(basename, 'pip')
    version_parts = [ p for p in version.split('.') if p ]
    num_version_parts = len(version_parts)
    if num_version_parts not in ( 1, 2 ):
      version = None
    libdir = clazz._pip_exe_determine_libdir(pip_exe, version)
    return clazz._pip_filename_info(version, libdir)
示例#8
0
 def remove_head(clazz, filename, head):
     'Return filename without head.'
     head = clazz.ensure_rsep(path.normpath(head))
     result = string_util.remove_head(filename, head)
     return result
示例#9
0
 def extension(clazz, filename):
     'Return the extension for filename.'
     return string_util.remove_head(path.splitext(filename)[1], os.extsep)
示例#10
0
 def _tmp_nickname_part(clazz):
     d = tempfile.mkdtemp(prefix='tmp')
     b = path.basename(d)
     file_util.remove(d)
     return string_util.remove_head(b, 'tmp')
示例#11
0
 def _decode_key(clazz, key):
     if host.is_linux():
         key = string_util.remove_head(key, 'user.')
     return key
示例#12
0
 def test_remove_head(self):
     self.assertEqual('ar', string_util.remove_head('foobar', ['foo', 'b']))