def get_package_root_url(directory_or_url): if "://" in directory_or_url or is_subversion(directory_or_url): return svn.get_package_root_url(directory_or_url) elif is_git_svn(directory_or_url): return git.get_package_root_url(directory_or_url) raise NotAScm, directory_or_url
def guess_url(self, package, prompt=False, required=False): """ Tries to guess the url of a package. If it's not able to guess, it asks or returns None, dependening on *prompt* """ # first, we check if we already know the name if self.has_package(package): return self.get(package) # we will search some places, make a list of possible hint-directories hint_dirs = [] # the parent directory may contain the package or other packages with the same # namespace (e.g. src-directory) hint_dirs.append(os.path.abspath("..")) # the gitsvn-cache directory contains several packages, the required package or # a package with the same namespace? hint_dirs.append(os.path.abspath(git.get_gitsvn_cache_path())) # now we try to find the package in the hint_dirs for dir in hint_dirs: path = os.path.join(dir, package) if os.path.isdir(path) and is_scm(path): try: url = get_package_root_url(path) except NotAScm: pass else: self.set(package, url) return url # now lets guess it with the namespace... # first we check the packages we alreay know the path: namespace = package.split(".")[0] for pkg, url in self._packages.items(): if pkg.startswith("%s." % namespace): try: dir_url = "/".join(url.split("/")[:-1]) if package + "/" in svn.listdir(dir_url): url = os.path.join(dir_url, package) self.set(package, url) return url except NotAScm: pass # could not find any? we may need to ask the user... if prompt: def input_validator(v): if not required and not v: return True if not v or not svn.isdir(v.strip()): return "Invalid SVN-URL" return True colorized_package = output.colorize(package, output.BOLD_WARNING) msg = output.colorize("I'm having trouble to guess the SVN-URL for the package", output.WARNING) msg += " " + colorized_package print msg msg = "SVN-URL of %s" % colorized_package if not required: msg += output.colorize(" or nothing", output.WARNING) url_input = input.prompt(msg, input_validator) if url_input: url = svn.get_package_root_url(url_input) self.set(package, url) return url return None