Exemplo n.º 1
0
  def Execute(self, opt, args):
    if not args or len(args) > 2:
      self.Usage()

    self.out = _Coloring(self.manifest.globalConfig)
    self.printText = self.out.nofmt_printer('text')
    if opt.color:
      self.printProject = self.out.nofmt_printer('project', attr = 'bold')
      self.printAdded = self.out.nofmt_printer('green', fg = 'green', attr = 'bold')
      self.printRemoved = self.out.nofmt_printer('red', fg = 'red', attr = 'bold')
      self.printRevision = self.out.nofmt_printer('revision', fg = 'yellow')
    else:
      self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText

    manifest1 = XmlManifest(self.manifest.repodir)
    manifest1.Override(args[0])
    if len(args) == 1:
      manifest2 = self.manifest
    else:
      manifest2 = XmlManifest(self.manifest.repodir)
      manifest2.Override(args[1])

    diff = manifest1.projectsDiff(manifest2)
    if opt.raw:
      self._printRawDiff(diff)
    else:
      self._printDiff(diff, color=opt.color)
Exemplo n.º 2
0
    def Execute(self, opt, args):
        if not args or len(args) > 2:
            self.Usage()

        self.out = _Coloring(self.manifest.globalConfig)
        self.printText = self.out.nofmt_printer('text')
        if opt.color:
            self.printProject = self.out.nofmt_printer('project', attr='bold')
            self.printAdded = self.out.nofmt_printer('green',
                                                     fg='green',
                                                     attr='bold')
            self.printRemoved = self.out.nofmt_printer('red',
                                                       fg='red',
                                                       attr='bold')
            self.printRevision = self.out.nofmt_printer('revision',
                                                        fg='yellow')
        else:
            self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText

        manifest1 = XmlManifest(self.manifest.repodir)
        manifest1.Override(args[0])
        if len(args) == 1:
            manifest2 = self.manifest
        else:
            manifest2 = XmlManifest(self.manifest.repodir)
            manifest2.Override(args[1])

        diff = manifest1.projectsDiff(manifest2)
        if opt.raw:
            self._printRawDiff(diff)
        else:
            self._printDiff(diff, color=opt.color)
Exemplo n.º 3
0
    def Execute(self, opt, args):
        self.out = _Coloring(self.manifest.globalConfig)
        self.printText = self.out.nofmt_printer("text")
        if opt.color:
            self.printProject = self.out.nofmt_printer("project", attr="bold")
            self.printAdded = self.out.nofmt_printer("green",
                                                     fg="green",
                                                     attr="bold")
            self.printRemoved = self.out.nofmt_printer("red",
                                                       fg="red",
                                                       attr="bold")
            self.printRevision = self.out.nofmt_printer("revision",
                                                        fg="yellow")
        else:
            self.printProject = (
                self.printAdded
            ) = self.printRemoved = self.printRevision = self.printText

        manifest1 = XmlManifest(self.manifest.repodir)
        manifest1.Override(args[0], load_local_manifests=False)
        if len(args) == 1:
            manifest2 = self.manifest
        else:
            manifest2 = XmlManifest(self.manifest.repodir)
            manifest2.Override(args[1], load_local_manifests=False)

        diff = manifest1.projectsDiff(manifest2)
        if opt.raw:
            self._printRawDiff(diff, pretty_format=opt.pretty_format)
        else:
            self._printDiff(diff,
                            color=opt.color,
                            pretty_format=opt.pretty_format)
Exemplo n.º 4
0
    def Execute(self, opt, args):
        self.out = _Coloring(self.manifest.globalConfig)
        self.printText = self.out.nofmt_printer('text')
        if opt.color:
            self.printProject = self.out.nofmt_printer('project', attr='bold')
            self.printAdded = self.out.nofmt_printer('green',
                                                     fg='green',
                                                     attr='bold')
            self.printRemoved = self.out.nofmt_printer('red',
                                                       fg='red',
                                                       attr='bold')
            self.printRevision = self.out.nofmt_printer('revision',
                                                        fg='yellow')
        else:
            self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText

        manifest1 = XmlManifest(self.manifest.repodir)
        manifest1.Override(args[0], load_local_manifests=False)
        if len(args) == 1:
            manifest2 = self.manifest
        else:
            manifest2 = XmlManifest(self.manifest.repodir)
            manifest2.Override(args[1], load_local_manifests=False)

        diff = manifest1.projectsDiff(manifest2)
        if opt.raw:
            self._printRawDiff(diff, pretty_format=opt.pretty_format)
        else:
            self._printDiff(diff,
                            color=opt.color,
                            pretty_format=opt.pretty_format)
Exemplo n.º 5
0
    def _Config(self, argv):
        name = None
        glob = []

        for i in range(len(argv)):
            if not argv[i].startswith('-'):
                name = argv[i]
                if i > 0:
                    glob = argv[:i]
                argv = argv[i + 1:]
                break
        if not name:
            glob = argv
            name = 'help'
            argv = []

        gopts, _gargs = global_options.parse_args(glob)

        if gopts.trace:
            SetTrace()
        if gopts.show_version:
            if name == 'help':
                name = 'version'
            else:
                print('fatal: invalid usage of --version', file=sys.stderr)
                return 1

        try:
            cmd = self.commands[name]
        except KeyError:
            print("repo: '%s' is not a repo command.  See 'repo help'." % name,
                  file=sys.stderr)
            return 1

        cmd.repodir = self.repodir
        cmd.manifest = XmlManifest(cmd.repodir)
        Editor.globalConfig = cmd.manifest.globalConfig

        if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
            print("fatal: '%s' requires a working directory" % name,
                  file=sys.stderr)
            return 1

        copts, cargs = cmd.OptionParser.parse_args(argv)
        copts = cmd.ReadEnvironmentOptions(copts)

        self.config = name, cmd, gopts, _gargs, copts, cargs, argv
        return 0
Exemplo n.º 6
0
  def _Run(self, argv):
    result = 0
    name = None
    glob = []

    for i in range(len(argv)):
      if not argv[i].startswith('-'):
        name = argv[i]
        if i > 0:
          glob = argv[:i]
        argv = argv[i + 1:]
        break
    if not name:
      glob = argv
      name = 'help'
      argv = []
    gopts, _gargs = global_options.parse_args(glob)

    if gopts.trace:
      SetTrace()
    if gopts.show_version:
      if name == 'help':
        name = 'version'
      else:
        print('fatal: invalid usage of --version', file=sys.stderr)
        return 1

    SetDefaultColoring(gopts.color)

    try:
      cmd = self.commands[name]
    except KeyError:
      print("repo: '%s' is not a repo command.  See 'repo help'." % name,
            file=sys.stderr)
      return 1

    cmd.repodir = self.repodir
    cmd.manifest = XmlManifest(cmd.repodir)
    cmd.gitc_manifest = None
    gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
    if gitc_client_name:
      cmd.gitc_manifest = GitcManifest(cmd.repodir, gitc_client_name)
      cmd.manifest.isGitcClient = True

    Editor.globalConfig = cmd.manifest.globalConfig

    if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
      print("fatal: '%s' requires a working directory" % name,
            file=sys.stderr)
      return 1

    if isinstance(cmd, GitcAvailableCommand) and not gitc_utils.get_gitc_manifest_dir():
      print("fatal: '%s' requires GITC to be available" % name,
            file=sys.stderr)
      return 1

    if isinstance(cmd, GitcClientCommand) and not gitc_client_name:
      print("fatal: '%s' requires a GITC client" % name,
            file=sys.stderr)
      return 1

    try:
      copts, cargs = cmd.OptionParser.parse_args(argv)
      copts = cmd.ReadEnvironmentOptions(copts)
    except NoManifestException as e:
      print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
        file=sys.stderr)
      print('error: manifest missing or unreadable -- please run init',
            file=sys.stderr)
      return 1

    if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
      config = cmd.manifest.globalConfig
      if gopts.pager:
        use_pager = True
      else:
        use_pager = config.GetBoolean('pager.%s' % name)
        if use_pager is None:
          use_pager = cmd.WantPager(copts)
      if use_pager:
        RunPager(config)

    start = time.time()
    try:
      result = cmd.Execute(copts, cargs)
    except (DownloadError, ManifestInvalidRevisionError,
        NoManifestException) as e:
      print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
        file=sys.stderr)
      if isinstance(e, NoManifestException):
        print('error: manifest missing or unreadable -- please run init',
              file=sys.stderr)
      result = 1
    except NoSuchProjectError as e:
      if e.name:
        print('error: project %s not found' % e.name, file=sys.stderr)
      else:
        print('error: no project in current directory', file=sys.stderr)
      result = 1
    except InvalidProjectGroupsError as e:
      if e.name:
        print('error: project group must be enabled for project %s' % e.name, file=sys.stderr)
      else:
        print('error: project group must be enabled for the project in the current directory', file=sys.stderr)
      result = 1
    finally:
      elapsed = time.time() - start
      hours, remainder = divmod(elapsed, 3600)
      minutes, seconds = divmod(remainder, 60)
      if gopts.time:
        if hours == 0:
          print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr)
        else:
          print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
                file=sys.stderr)

    return result
Exemplo n.º 7
0
  def _Run(self, argv):
    name = None
    glob = []

    for i in xrange(0, len(argv)):
      if not argv[i].startswith('-'):
        name = argv[i]
        if i > 0:
          glob = argv[:i]
        argv = argv[i + 1:]
        break
    if not name:
      glob = argv
      name = 'help'
      argv = []
    gopts, gargs = global_options.parse_args(glob)

    if gopts.trace:
      SetTrace()
    if gopts.show_version:
      if name == 'help':
        name = 'version'
      else:
        print >>sys.stderr, 'fatal: invalid usage of --version'
        sys.exit(1)

    try:
      cmd = self.commands[name]
    except KeyError:
      print >>sys.stderr,\
            "repo: '%s' is not a repo command.  See 'repo help'."\
            % name
      sys.exit(1)

    cmd.repodir = self.repodir
    cmd.manifest = XmlManifest(cmd.repodir)
    Editor.globalConfig = cmd.manifest.globalConfig

    if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
      print >>sys.stderr, \
            "fatal: '%s' requires a working directory"\
            % name
      sys.exit(1)

    copts, cargs = cmd.OptionParser.parse_args(argv)

    if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
      config = cmd.manifest.globalConfig
      if gopts.pager:
        use_pager = True
      else:
        use_pager = config.GetBoolean('pager.%s' % name)
        if use_pager is None:
          use_pager = cmd.WantPager(copts)
      if use_pager:
        RunPager(config)

    try:
      cmd.Execute(copts, cargs)
    except ManifestInvalidRevisionError, e:
      print >>sys.stderr, 'error: %s' % str(e)
      sys.exit(1)
Exemplo n.º 8
0
def ParseManifest(repodir, type=None):
    if type:
        return type(repodir)
    if SubmoduleManifest.Is(repodir):
        return SubmoduleManifest(repodir)
    return XmlManifest(repodir)
Exemplo n.º 9
0
    def _Run(self, argv):
        result = 0
        name = None
        glob = []

        for i in range(len(argv)):
            if not argv[i].startswith('-'):
                name = argv[i]
                if i > 0:
                    glob = argv[:i]
                argv = argv[i + 1:]
                break
        if not name:
            glob = argv
            name = 'help'
            argv = []
        gopts, _gargs = global_options.parse_args(glob)

        if gopts.trace:
            SetTrace()
        if gopts.show_version:
            if name == 'help':
                name = 'version'
            else:
                print('fatal: invalid usage of --version', file=sys.stderr)
                return 1

        try:
            cmd = self.commands[name]
        except KeyError:
            print("repo: '%s' is not a repo command.  See 'repo help'." % name,
                  file=sys.stderr)
            return 1

        cmd.repodir = self.repodir
        cmd.manifest = XmlManifest(cmd.repodir)
        Editor.globalConfig = cmd.manifest.globalConfig

        if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
            print("fatal: '%s' requires a working directory" % name,
                  file=sys.stderr)
            return 1

        copts, cargs = cmd.OptionParser.parse_args(argv)
        copts = cmd.ReadEnvironmentOptions(copts)

        if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
            config = cmd.manifest.globalConfig
            if gopts.pager:
                use_pager = True
            else:
                use_pager = config.GetBoolean('pager.%s' % name)
                if use_pager is None:
                    use_pager = cmd.WantPager(copts)
            if use_pager:
                RunPager(config)

        start = time.time()
        try:
            result = cmd.Execute(copts, cargs)
        except DownloadError as e:
            print('error: %s' % str(e), file=sys.stderr)
            result = 1
        except ManifestInvalidRevisionError as e:
            print('error: %s' % str(e), file=sys.stderr)
            result = 1
        except NoManifestException as e:
            print(
                'error: manifest required for this command -- please run init',
                file=sys.stderr)
            result = 1
        except NoSuchProjectError as e:
            if e.name:
                print('error: project %s not found' % e.name, file=sys.stderr)
            else:
                print('error: no project in current directory',
                      file=sys.stderr)
            result = 1
        finally:
            elapsed = time.time() - start
            hours, remainder = divmod(elapsed, 3600)
            minutes, seconds = divmod(remainder, 60)
            if gopts.time:
                if hours == 0:
                    print('real\t%dm%.3fs' % (minutes, seconds),
                          file=sys.stderr)
                else:
                    print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
                          file=sys.stderr)

        return result
Exemplo n.º 10
0
    def _Run(self, argv):
        name = None
        glob = []

        for i in xrange(0, len(argv)):
            if not argv[i].startswith('-'):
                name = argv[i]
                if i > 0:
                    glob = argv[:i]
                argv = argv[i + 1:]
                break
        if not name:
            glob = argv
            name = 'help'
            argv = []
        gopts, gargs = global_options.parse_args(glob)

        if gopts.trace:
            SetTrace()
        if gopts.show_version:
            if name == 'help':
                name = 'version'
            else:
                print >> sys.stderr, 'fatal: invalid usage of --version'
                sys.exit(1)

        try:
            cmd = self.commands[name]
        except KeyError:
            print >>sys.stderr,\
                  "xrepo: '%s' is not a xrepo command.  See 'xrepo help'."\
                  % name
            sys.exit(1)

        cmd.repodir = self.repodir
        cmd.manifest = XmlManifest(cmd.repodir)
        Editor.globalConfig = cmd.manifest.globalConfig

        if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
            print >>sys.stderr, \
                  "fatal: '%s' requires a working directory"\
                  % name
            sys.exit(1)

        copts, cargs = cmd.OptionParser.parse_args(argv)

        if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
            config = cmd.manifest.globalConfig
            if gopts.pager:
                use_pager = True
            else:
                use_pager = config.GetBoolean('pager.%s' % name)
                if use_pager is None:
                    use_pager = cmd.WantPager(copts)
            if use_pager:
                RunPager(config)

        try:
            start = time.time()
            try:
                cmd.Execute(copts, cargs)
            finally:
                elapsed = time.time() - start
                hours, remainder = divmod(elapsed, 3600)
                minutes, seconds = divmod(remainder, 60)
                if gopts.time:
                    if hours == 0:
                        print >>sys.stderr, 'real\t%dm%.3fs' \
                          % (minutes, seconds)
                    else:
                        print >>sys.stderr, 'real\t%dh%dm%.3fs' \
                          % (hours, minutes, seconds)
        except DownloadError, e:
            print >> sys.stderr, 'error: %s' % str(e)
            sys.exit(1)
Exemplo n.º 11
0
    def _Run(self, name, gopts, argv):
        """Execute the requested subcommand."""
        result = 0

        if gopts.trace:
            SetTrace()
        if gopts.show_version:
            if name == 'help':
                name = 'version'
            else:
                print('fatal: invalid usage of --version', file=sys.stderr)
                return 1

        SetDefaultColoring(gopts.color)

        try:
            cmd = self.commands[name]
        except KeyError:
            print("repo: '%s' is not a repo command.  See 'repo help'." % name,
                  file=sys.stderr)
            return 1

        cmd.repodir = self.repodir
        cmd.manifest = XmlManifest(cmd.repodir)
        cmd.gitc_manifest = None
        gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
        if gitc_client_name:
            cmd.gitc_manifest = GitcManifest(cmd.repodir, gitc_client_name)
            cmd.manifest.isGitcClient = True

        Editor.globalConfig = cmd.manifest.globalConfig

        if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
            print("fatal: '%s' requires a working directory" % name,
                  file=sys.stderr)
            return 1

        if isinstance(cmd, GitcAvailableCommand
                      ) and not gitc_utils.get_gitc_manifest_dir():
            print("fatal: '%s' requires GITC to be available" % name,
                  file=sys.stderr)
            return 1

        if isinstance(cmd, GitcClientCommand) and not gitc_client_name:
            print("fatal: '%s' requires a GITC client" % name, file=sys.stderr)
            return 1

        try:
            copts, cargs = cmd.OptionParser.parse_args(argv)
            copts = cmd.ReadEnvironmentOptions(copts)
        except NoManifestException as e:
            print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
                  file=sys.stderr)
            print('error: manifest missing or unreadable -- please run init',
                  file=sys.stderr)
            return 1

        if gopts.pager is not False and not isinstance(cmd,
                                                       InteractiveCommand):
            config = cmd.manifest.globalConfig
            if gopts.pager:
                use_pager = True
            else:
                use_pager = config.GetBoolean('pager.%s' % name)
                if use_pager is None:
                    use_pager = cmd.WantPager(copts)
            if use_pager:
                RunPager(config)

        start = time.time()
        cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start)
        cmd.event_log.SetParent(cmd_event)
        try:
            cmd.ValidateOptions(copts, cargs)
            result = cmd.Execute(copts, cargs)
        except (DownloadError, ManifestInvalidRevisionError,
                NoManifestException) as e:
            print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
                  file=sys.stderr)
            if isinstance(e, NoManifestException):
                print(
                    'error: manifest missing or unreadable -- please run init',
                    file=sys.stderr)
            result = 1
        except NoSuchProjectError as e:
            if e.name:
                print('error: project %s not found' % e.name, file=sys.stderr)
            else:
                print('error: no project in current directory',
                      file=sys.stderr)
            result = 1
        except InvalidProjectGroupsError as e:
            if e.name:
                print('error: project group must be enabled for project %s' %
                      e.name,
                      file=sys.stderr)
            else:
                print(
                    'error: project group must be enabled for the project in the current directory',
                    file=sys.stderr)
            result = 1
        except SystemExit as e:
            if e.code:
                result = e.code
            raise
        finally:
            finish = time.time()
            elapsed = finish - start
            hours, remainder = divmod(elapsed, 3600)
            minutes, seconds = divmod(remainder, 60)
            if gopts.time:
                if hours == 0:
                    print('real\t%dm%.3fs' % (minutes, seconds),
                          file=sys.stderr)
                else:
                    print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
                          file=sys.stderr)

            cmd.event_log.FinishEvent(cmd_event, finish, result is None
                                      or result == 0)
            if gopts.event_log:
                cmd.event_log.Write(
                    os.path.abspath(os.path.expanduser(gopts.event_log)))

        return result
Exemplo n.º 12
0
import os, sys, shutil

cwd = os.path.abspath(os.path.dirname(__file__))
repodir = os.path.join(cwd, '.repo')
S_repo = 'repo'
TRASHDIR = 'old_work_tree'

if not os.path.exists(os.path.join(repodir, S_repo)):
    print >> sys.stderr, "Must run under repo work_dir root."
    sys.exit(1)

sys.path.insert(0, os.path.join(repodir, S_repo))
from manifest_xml import XmlManifest

manifest = XmlManifest(repodir)

if manifest.IsMirror:
    print >> sys.stderr, "Already mirror, exit."
    sys.exit(1)

trash = os.path.join(cwd, TRASHDIR)

for project in manifest.projects.itervalues():
    # 移动旧的版本库路径到镜像模式下新的版本库路径
    newgitdir = os.path.join(cwd, '%s.git' % project.name)
    if os.path.exists(project.gitdir) and project.gitdir != newgitdir:
        if not os.path.exists(os.path.dirname(newgitdir)):
            os.makedirs(os.path.dirname(newgitdir))
        print "Rename %s to %s." % (project.gitdir, newgitdir)
        os.rename(project.gitdir, newgitdir)
Exemplo n.º 13
0
   if not argv[i].startswith('-'): name = argv[i]
     if i > 0: glob = argv[:i]
     argv = argv[i + 1:]
     break
 if not name: glob = argv
   name = 'help'
   argv = []
 gopts, _gargs = global_options.parse_args(glob)
 if gopts.trace: SetTrace()
 if gopts.show_version:
   if name == 'help': name = 'version'
   else: print('fatal: invalid usage of --version', file=sys.stderr) return 1
 SetDefaultColoring(gopts.color)
 try: cmd = self.commands[name] except KeyError: print("re po: '%s' is not a re po command.  See 're po help'." % name, file=sys.stderr) return 1
 cmd.repodir = self.repodir
 cmd.manifest = XmlManifest(cmd.repodir)
 cmd.gitc_manifest = None
 gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
 if gitc_client_name: cmd.gitc_manifest = GitcManifest(cmd.repodir, gitc_client_name)
   cmd.manifest.isGitcClient = True
 Editor.globalConfig = cmd.manifest.globalConfig
 if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: print("fatal: '%s' requires a working directory" % name, file=sys.stderr)
   return 1
 if isinstance(cmd, RequiresGitcCommand) and not gitc_utils.get_gitc_manifest_dir(): print("fatal: '%s' requires GITC to be available" % name, file=sys.stderr)
   return 1
 try:
   copts, cargs = cmd.OptionParser.parse_args(argv)
   copts = cmd.ReadEnvironmentOptions(copts) except NoManifestException as e: print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)), file=sys.stderr) print('error: manifest missing or unreadable -- please run init', file=sys.stderr) return 1
 if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
   config = cmd.manifest.globalConfig
   if gopts.pager:
Exemplo n.º 14
0
#!/usr/bin/env python2

import os
import sys
import hashlib
import urlparse

# script my be executed only in initnialized repo
assert (os.path.exists('./.repo/repo'))
sys.path.insert(0, './.repo/repo')

from manifest_xml import XmlManifest
manifest = XmlManifest("./.repo/")
manifest._Load()

MIRRORDIR = os.path.expanduser(os.environ["REPO_MIRROR_LOCATION"])
for name, projects in manifest._projects.items():
    for project in projects:
        remoteUrl = project.remote.url

        moduleDir = MIRRORDIR + "/.repo/projects/" + project.relpath + ".git"

        if not os.path.exists(moduleDir + "/config"):
            if not os.path.exists(moduleDir):
                os.makedirs(moduleDir)
            # TODO: use subprocess
            cmd = "cd %s && git init --bare" % moduleDir
            ret = os.system(cmd)
            assert (ret == 0)

        md5su = hashlib.new("md5")