def FindRepoDir(path): """Returns the nearest higher-level repo dir from the specified path. Args: path: The path to use. Defaults to cwd. """ return osutils.FindInPathParents('.repo', path, test_func=os.path.isdir)
def FindGitSubmoduleCheckoutRoot(path, remote, url): """Get the root of your git submodule checkout, looking up from |path|. This function goes up the tree starting from |path| and looks for a .git/ dir configured with a |remote| pointing at |url|. Arguments: path: The path to start searching from. remote: The remote to compare the |url| with. url: The exact URL the |remote| needs to be pointed at. """ def test_config(path): if os.path.isdir(path): remote_url = cros_build_lib.RunCommand( ['git', '--git-dir', path, 'config', 'remote.%s.url' % remote], redirect_stdout=True, debug_level=logging.DEBUG).output.strip() if remote_url == url: return True return False root_dir = osutils.FindInPathParents('.git', path, test_func=test_config) if root_dir: return os.path.dirname(root_dir) return None
def FindGclientFile(path): """Returns the nearest higher-level gclient file from the specified path. Args: path: The path to use. Defaults to cwd. """ return osutils.FindInPathParents( '.gclient', path, test_func=os.path.isfile)
def GetAffectedPackagesForOverlayChange(change, manifest, overlays): """Get the set of packages affected by the overlay |change|. Args: change: The GerritPatch instance that modifies an overlay. manifest: A ManifestCheckout instance representing our build directory. overlays: List of overlay paths. Returns: The set of packages affected by the specified |change|. E.g. {'chromeos-base/chromite-0.0.1-r1258'}. If the change affects something other than packages, return None. """ checkout = change.GetCheckout(manifest, strict=False) if checkout: git_repo = checkout.GetPath(absolute=True) packages = set() for path in change.GetDiffStatus(git_repo): # Determine if path is in a package directory by walking up # directories and see if there is an ebuild in the directory. start_path = os.path.join(git_repo, path) ebuild_path = osutils.FindInPathParents('*.ebuild', start_path, test_func=glob.glob, end_path=git_repo) if ebuild_path: # Convert git_repo/../*.ebuild to the real ebuild path. ebuild_path = glob.glob(ebuild_path)[0] # Double check that the ebuild is two-levels deep in an overlay # directory. if os.path.sep.join(ebuild_path.split( os.path.sep)[:-3]) in overlays: category, pkg_name, _ = portage_util.SplitEbuildPath( ebuild_path) packages.add('%s/%s' % (category, pkg_name)) continue # If |change| affects anything other than packages, return None. return None return packages
def testNotFound(self): """Target is not found.""" found = osutils.FindInPathParents( 'does.not/exist', os.path.join(self.tempdir, self.START_PATH)) self.assertEquals(found, None)
def testFound(self): """Target is found.""" found = osutils.FindInPathParents( '.repo', os.path.join(self.tempdir, self.START_PATH)) self.assertEquals(found, os.path.join(self.tempdir, 'a', '.repo'))