def _RunForPath(self, path, expected): result_components = [] for p in osutils.IteratePathParents(path): result_components.append(os.path.basename(p)) result_components.reverse() if expected is not None: self.assertEquals(expected, result_components)
def DetermineCheckout(cwd): """Gather information on the checkout we are in. Returns: A CheckoutInfo object with these attributes: type: The type of checkout. Valid values are CHECKOUT_TYPE_*. root: The root of the checkout. chrome_src_dir: If the checkout is a Chrome checkout, the path to the Chrome src/ directory. """ checkout_type = CHECKOUT_TYPE_UNKNOWN root, path = None, None for path in osutils.IteratePathParents(cwd): repo_dir = os.path.join(path, '.repo') if os.path.isdir(repo_dir): checkout_type = CHECKOUT_TYPE_REPO break gclient_file = os.path.join(path, '.gclient') if os.path.exists(gclient_file): checkout_type = CHECKOUT_TYPE_GCLIENT break submodule_git = os.path.join(path, '.git') if (os.path.isdir(submodule_git) and git.IsSubmoduleCheckoutRoot( cwd, 'origin', constants.CHROMIUM_GOB_URL)): checkout_type = CHECKOUT_TYPE_SUBMODULE break if checkout_type != CHECKOUT_TYPE_UNKNOWN: root = path # Determine the chrome src directory. chrome_src_dir = None if checkout_type == CHECKOUT_TYPE_GCLIENT: chrome_src_dir = os.path.join(root, 'src') elif checkout_type == CHECKOUT_TYPE_SUBMODULE: chrome_src_dir = root return CheckoutInfo(checkout_type, root, chrome_src_dir)
def DetermineCheckout(cwd=None): """Gather information on the checkout we are in. There are several checkout types, as defined by CHECKOUT_TYPE_XXX variables. This function determines what checkout type |cwd| is in, for example, if |cwd| belongs to a `repo` checkout. Returns: A CheckoutInfo object with these attributes: type: The type of checkout. Valid values are CHECKOUT_TYPE_*. root: The root of the checkout. chrome_src_dir: If the checkout is a Chrome checkout, the path to the Chrome src/ directory. """ checkout_type = CHECKOUT_TYPE_UNKNOWN root, path = None, None cwd = cwd or os.getcwd() for path in osutils.IteratePathParents(cwd): gclient_file = os.path.join(path, '.gclient') if os.path.exists(gclient_file): checkout_type = CHECKOUT_TYPE_GCLIENT break repo_dir = os.path.join(path, '.repo') if os.path.isdir(repo_dir): checkout_type = CHECKOUT_TYPE_REPO break if checkout_type != CHECKOUT_TYPE_UNKNOWN: root = path # Determine the chrome src directory. chrome_src_dir = None if checkout_type == CHECKOUT_TYPE_GCLIENT: chrome_src_dir = os.path.join(root, 'src') return CheckoutInfo(checkout_type, root, chrome_src_dir)