Index: ensure_dependencies.py |
=================================================================== |
--- a/ensure_dependencies.py |
+++ b/ensure_dependencies.py |
@@ -14,6 +14,7 @@ |
import logging |
import subprocess |
import urlparse |
+import argparse |
from collections import OrderedDict |
from ConfigParser import RawConfigParser |
@@ -78,6 +79,9 @@ |
module = os.path.relpath(target, repo) |
_ensure_line_exists(ignore_path, module) |
+ def postprocess_url(self, url): |
+ return url |
+ |
class Git(): |
def istype(self, repodir): |
return os.path.exists(os.path.join(repodir, ".git")) |
@@ -103,6 +107,12 @@ |
exclude_file = os.path.join(repo, ".git", "info", "exclude") |
_ensure_line_exists(exclude_file, module) |
+ def postprocess_url(self, url): |
+ # Handle alternative syntax of SSH URLS |
+ if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme: |
+ return "ssh://" + url.replace(":", "/", 1) |
+ return url |
+ |
repo_types = OrderedDict(( |
("hg", Mercurial()), |
("git", Git()), |
@@ -186,7 +196,15 @@ |
if type is None: |
raise Exception("No valid source found to create %s" % target) |
- url = urlparse.urljoin(roots[type], sourcename) |
+ postprocess_url = repo_types[type].postprocess_url |
+ root = postprocess_url(roots[type]) |
+ sourcename = postprocess_url(sourcename) |
+ |
+ if os.path.exists(root): |
+ url = os.path.join(root, sourcename) |
+ else: |
+ url = urlparse.urljoin(root, sourcename) |
+ |
logging.info("Cloning repository %s into %s" % (url, target)) |
repo_types[type].clone(url, target) |
@@ -278,8 +296,17 @@ |
if __name__ == "__main__": |
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) |
- repos = sys.argv[1:] |
+ |
+ parser = argparse.ArgumentParser(description="Verify dependencies for a set of repositories, by default the repository of this script.") |
+ parser.add_argument("repos", metavar="repository", type=str, nargs="*", help="Repository path") |
+ parser.add_argument("-q", "--quiet", action="store_true", help="Suppress informational output") |
+ args = parser.parse_args() |
+ |
+ if args.quiet: |
+ logging.disable(logging.INFO) |
+ |
+ repos = args.repos |
if not len(repos): |
- repos = [os.getcwd()] |
+ repos = [os.path.dirname(__file__)] |
for repo in repos: |
resolve_deps(repo) |