Exemple #1
0
    def Link(self, name):
        """Update the repo metadata to use a different manifest.
    """
        self.Override(name)

        # Old versions of repo would generate symlinks we need to clean up.
        if os.path.lexists(self.manifestFile):
            platform_utils.remove(self.manifestFile)
        # This file is interpreted as if it existed inside the manifest repo.
        # That allows us to use <include> with the relative file name.
        with open(self.manifestFile, 'w') as fp:
            fp.write("""<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT THIS FILE!  It is generated by repo and changes will be discarded.
If you want to use a different manifest, use `repo init -m <file>` instead.

If you want to customize your checkout by overriding manifest settings, use
the local_manifests/ directory instead.

For more information on repo manifests, check out:
https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
-->
<manifest>
  <include name="%s" />
</manifest>
""" % (name, ))
Exemple #2
0
 def _ReadJson(self):
   try:
     if os.path.getmtime(self._json) <= os.path.getmtime(self.file):
       platform_utils.remove(self._json)
       return None
   except OSError:
     return None
   try:
     Trace(': parsing %s', self.file)
     with open(self._json) as fd:
       return json.load(fd)
   except (IOError, ValueError):
     platform_utils.remove(self._json)
     return None
Exemple #3
0
    def EditString(cls, data):
        """Opens an editor to edit the given content.

    Args:
      data: The text to edit.

    Returns:
      New value of edited text.

    Raises:
      EditorError: The editor failed to run.
    """
        editor = cls._GetEditor()
        if editor == ':':
            return data

        fd, path = tempfile.mkstemp()
        try:
            os.write(fd, data.encode('utf-8'))
            os.close(fd)
            fd = None

            if platform_utils.isWindows():
                # Split on spaces, respecting quoted strings
                import shlex
                args = shlex.split(editor)
                shell = False
            elif re.compile("^.*[$ \t'].*$").match(editor):
                args = [editor + ' "$@"', 'sh']
                shell = True
            else:
                args = [editor]
                shell = False
            args.append(path)

            try:
                rc = subprocess.Popen(args, shell=shell).wait()
            except OSError as e:
                raise EditorError('editor failed, %s: %s %s' %
                                  (str(e), editor, path))
            if rc != 0:
                raise EditorError('editor failed with exit status %d: %s %s' %
                                  (rc, editor, path))

            with open(path, mode='rb') as fd2:
                return fd2.read().decode('utf-8')
        finally:
            if fd:
                os.close(fd)
            platform_utils.remove(path)