コード例 #1
0
ファイル: gcl.py プロジェクト: neurobcn/plexnet
    def Load(changename, local_root, fail_on_not_found, update_status):
        """Gets information about a changelist.

    Args:
      fail_on_not_found: if True, this function will quit the program if the
        changelist doesn't exist.
      update_status: if True, the svn status will be updated for all the files
        and unchanged files will be removed.

    Returns: a ChangeInfo object.
    """
        info_file = GetChangelistInfoFile(changename)
        if not os.path.exists(info_file):
            if fail_on_not_found:
                ErrorExit("Changelist " + changename + " not found.")
            return ChangeInfo(changename,
                              0,
                              0,
                              '',
                              None,
                              local_root,
                              needs_upload=False)
        split_data = ReadFile(info_file).split(ChangeInfo._SEPARATOR, 2)
        if len(split_data) != 3:
            ErrorExit("Changelist file %s is corrupt" % info_file)
        items = split_data[0].split(', ')
        issue = 0
        patchset = 0
        needs_upload = False
        if items[0]:
            issue = int(items[0])
        if len(items) > 1:
            patchset = int(items[1])
        if len(items) > 2:
            needs_upload = (items[2] == "dirty")
        files = []
        for line in split_data[1].splitlines():
            status = line[:7]
            filename = line[7:]
            files.append((status, filename))
        description = split_data[2]
        save = False
        if update_status:
            for item in files:
                filename = os.path.join(local_root, item[1])
                status_result = SVN.CaptureStatus(filename)
                if not status_result or not status_result[0][0]:
                    # File has been reverted.
                    save = True
                    files.remove(item)
                    continue
                status = status_result[0][0]
                if status != item[0]:
                    save = True
                    files[files.index(item)] = (status, item[1])
        change_info = ChangeInfo(changename, issue, patchset, description,
                                 files, local_root, needs_upload)
        if save:
            change_info.Save()
        return change_info
コード例 #2
0
ファイル: gcl.py プロジェクト: neurobcn/plexnet
def UnknownFiles(extra_args):
    """Runs svn status and returns unknown files.

  Any args in |extra_args| are passed to the tool to support giving alternate
  code locations.
  """
    return [
        item[1] for item in SVN.CaptureStatus(extra_args) if item[0][0] == '?'
    ]
コード例 #3
0
ファイル: gcl.py プロジェクト: miaosf/depot_tools
  def Load(changename, local_root, fail_on_not_found, update_status):
    """Gets information about a changelist.

    Args:
      fail_on_not_found: if True, this function will quit the program if the
        changelist doesn't exist.
      update_status: if True, the svn status will be updated for all the files
        and unchanged files will be removed.

    Returns: a ChangeInfo object.
    """
    info_file = GetChangelistInfoFile(changename)
    if not os.path.exists(info_file):
      if fail_on_not_found:
        ErrorExit("Changelist " + changename + " not found.")
      return ChangeInfo(changename, 0, 0, '', None, local_root, None, False)
    content = gclient_utils.FileRead(info_file)
    save = False
    try:
      values = ChangeInfo._LoadNewFormat(content)
    except ValueError:
      try:
        values = ChangeInfo._LoadOldFormat(content)
        save = True
      except ValueError:
        ErrorExit(
            ('Changelist file %s is corrupt.\n'
            'Either run "gcl delete %s" or manually edit the file') % (
                info_file, changename))
    files = values['files']
    if update_status:
      for item in files[:]:
        status_result = SVN.CaptureStatus(item[1], local_root)
        if not status_result or not status_result[0][0]:
          # File has been reverted.
          save = True
          files.remove(item)
          continue
        status = status_result[0][0]
        if status != item[0]:
          save = True
          files[files.index(item)] = (status, item[1])
    change_info = ChangeInfo(
        changename,
        values['issue'],
        values['patchset'],
        values['description'],
        files,
        local_root,
        values.get('rietveld'),
        values['needs_upload'])
    if save:
      change_info.Save()
    return change_info
コード例 #4
0
ファイル: gcl.py プロジェクト: neurobcn/plexnet
def GetModifiedFiles():
    """Returns a set that maps from changelist name to (status,filename) tuples.

  Files not in a changelist have an empty changelist name.  Filenames are in
  relation to the top level directory of the current repository.  Note that
  only the current directory and subdirectories are scanned, in order to
  improve performance while still being flexible.
  """
    files = {}

    # Since the files are normalized to the root folder of the repositary, figure
    # out what we need to add to the paths.
    dir_prefix = os.getcwd()[len(GetRepositoryRoot()):].strip(os.sep)

    # Get a list of all files in changelists.
    files_in_cl = {}
    for cl in GetCLs():
        change_info = ChangeInfo.Load(cl,
                                      GetRepositoryRoot(),
                                      fail_on_not_found=True,
                                      update_status=False)
        for status, filename in change_info.GetFiles():
            files_in_cl[filename] = change_info.name

    # Get all the modified files.
    status_result = SVN.CaptureStatus(None)
    for line in status_result:
        status = line[0]
        filename = line[1]
        if status[0] == "?":
            continue
        if dir_prefix:
            filename = os.path.join(dir_prefix, filename)
        change_list_name = ""
        if filename in files_in_cl:
            change_list_name = files_in_cl[filename]
        files.setdefault(change_list_name, []).append((status, filename))

    return files
コード例 #5
0
ファイル: gcl.py プロジェクト: neurobcn/plexnet
def GetCachedFile(filename, max_age=60 * 60 * 24 * 3, use_root=False):
    """Retrieves a file from the repository and caches it in GetCacheDir() for
  max_age seconds.

  use_root: If False, look up the arborescence for the first match, otherwise go
            directory to the root repository.

  Note: The cache will be inconsistent if the same file is retrieved with both
        use_root=True and use_root=False. Don't be stupid.
  """
    global FILES_CACHE
    if filename not in FILES_CACHE:
        # Don't try to look up twice.
        FILES_CACHE[filename] = None
        # First we check if we have a cached version.
        try:
            cached_file = os.path.join(GetCacheDir(), filename)
        except gclient_utils.Error:
            return None
        if (not os.path.exists(cached_file)
                or os.stat(cached_file).st_mtime > max_age):
            local_dir = os.path.dirname(os.path.abspath(filename))
            local_base = os.path.basename(filename)
            dir_info = SVN.CaptureInfo(".")
            repo_root = dir_info["Repository Root"]
            if use_root:
                url_path = repo_root
            else:
                url_path = dir_info["URL"]
            content = ""
            while True:
                # First, look for a locally modified version of the file if we can.
                r = ""
                if not use_root:
                    local_path = os.path.join(local_dir, local_base)
                    r = SVN.CaptureStatus((local_path, ))
                rc = -1
                if r:
                    status = r[0][0]
                    rc = 0
                if not rc and status[0] in ('A', 'M'):
                    content = ReadFile(local_path)
                    rc = 0
                else:
                    # Look in the repository if we didn't find something local.
                    svn_path = url_path + "/" + filename
                    content, rc = RunShellWithReturnCode(
                        ["svn", "cat", svn_path])

                if not rc:
                    # Exit the loop if the file was found. Override content.
                    break
                # Make sure to mark settings as empty if not found.
                content = ""
                if url_path == repo_root:
                    # Reached the root. Abandoning search.
                    break
                # Go up one level to try again.
                url_path = os.path.dirname(url_path)
                local_dir = os.path.dirname(local_dir)
            # Write a cached version even if there isn't a file, so we don't try to
            # fetch it each time.
            WriteFile(cached_file, content)
        else:
            content = ReadFile(cached_file)
        # Keep the content cached in memory.
        FILES_CACHE[filename] = content
    return FILES_CACHE[filename]
コード例 #6
0
ファイル: gcl.py プロジェクト: BGCX067/fajr-git
def UnknownFiles():
  """Runs svn status and returns unknown files."""
  return [item[1] for item in SVN.CaptureStatus([]) if item[0][0] == '?']