def setUp(self):
   self.root = os.path.join(self.tempdir, 'root')
   self.repo_dir = os.path.join(self.root, '.repo')
   self.subdir = os.path.join(self.root, 'sub', 'dir')
   os.makedirs(self.repo_dir)
   os.makedirs(self.subdir)
   self.repo = repo_util.Repository(self.root)
Esempio n. 2
0
    def PreLoad(self, source_repo=None):
        """Preinitialize new .repo directory for faster initial sync.

    This is a hint that the new .repo directory can be copied from
    source_repo/.repo to avoid network sync operations. It does nothing if the
    .repo already exists, or source is invalid. source_repo defaults to the repo
    of the current checkout for the script.

    This should be done before the target is cleaned, to avoid corruption, since
    the source is in an unknown state.

    Args:
      source_repo: Directory path to use as a template for new repo checkout.
    """
        if not source_repo:
            source_repo = constants.SOURCE_ROOT

        # If target already exist, or source is invalid, don't copy.
        if IsARepoRoot(self.directory) or not IsARepoRoot(source_repo):
            return

        osutils.SafeMakedirs(self.directory)

        logging.info("Preloading '%s' from '%s'.", self.directory, source_repo)
        repo_util.Repository(source_repo).Copy(self.directory)
        logging.info('Preload Finsihed.')
Esempio n. 3
0
    def SyncFile(self, path):
        """Sync to the given manifest file.

    Args:
      path: Path to the manifest file.
    """
        logging.notice('Syncing checkout %s to manifest %s.', self.root, path)
        # SyncFile uses repo sync instead of repo_sync_manifest because
        # repo_sync_manifest sometimes corrupts .repo/manifest.xml when
        # syncing to a file. See crbug.com/973106.
        cmd = ['repo', 'sync', '--manifest-name', os.path.abspath(path)]
        cros_build_lib.run(cmd, cwd=self.root, print_cmd=True)
        self.manifest = repo_util.Repository(self.root).Manifest()
Esempio n. 4
0
    def _Sync(self, manifest_args):
        """Run repo_sync_manifest command.

    Args:
      manifest_args: List of args for manifest group of repo_sync_manifest.
    """
        cmd = [
            os.path.join(constants.CHROMITE_DIR, 'scripts/repo_sync_manifest'),
            '--repo-root', self.root
        ] + manifest_args
        if self.repo_url:
            cmd += ['--repo-url', self.repo_url]
        if self.manifest_url:
            cmd += ['--manifest-url', self.manifest_url]
        if self.groups:
            cmd += ['--groups', self.groups]

        cros_build_lib.run(cmd, print_cmd=True)
        self.manifest = repo_util.Repository(self.root).Manifest()
Esempio n. 5
0
    def __init__(self,
                 root,
                 manifest=None,
                 manifest_url=None,
                 repo_url=None,
                 groups=None):
        """Read the checkout manifest.

    Args:
      root: The repo root.
      manifest: The checkout manifest. Read from `repo manifest` if None.
      manifest_url: Manifest repository URL. repo_sync_manifest sets default.
      repo_url: Repo repository URL. repo_sync_manifest sets default.
      groups: Repo groups to sync.
    """
        self.root = root
        self.manifest = manifest or repo_util.Repository(root).Manifest()
        self.manifest_url = manifest_url
        self.repo_url = repo_url
        self.groups = groups
 def testInitNoRepoDir(self):
   """Test Repository.__init__ fails if not in repo."""
   with self.assertRaises(repo_util.NotInRepoError):
     repo_util.Repository(self.empty_root)
 def testInit(self):
   """Test Repository.__init__."""
   repo = repo_util.Repository(self.repo_root)
   self.assertTrue(os.path.samefile(repo.root, self.repo_root))