Index: ensure_dependencies.py |
=================================================================== |
--- a/ensure_dependencies.py |
+++ b/ensure_dependencies.py |
@@ -25,7 +25,9 @@ |
import logging |
import subprocess |
import urlparse |
+ |
from collections import OrderedDict |
+from ConfigParser import RawConfigParser |
USAGE = """ |
A dependencies file should look like this: |
@@ -42,7 +44,18 @@ |
buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5 |
""" |
-class Mercurial(): |
+class SCM(object): |
+ def _ensure_line_exists(self, ignore_file, pattern): |
Wladimir Palant
2014/10/08 21:40:30
The parameter should be called path, not ignore_fi
|
+ with open(ignore_file, 'a+') as f: |
+ file_content = [l.strip() for l in f.readlines()] |
+ if not pattern in file_content: |
+ file_content.append(pattern) |
+ f.seek(0, os.SEEK_SET) |
+ for l in file_content: |
+ print >>f, l |
+ f.truncate() |
+ |
+class Mercurial(SCM): |
def istype(self, repodir): |
return os.path.exists(os.path.join(repodir, ".hg")) |
@@ -67,7 +80,27 @@ |
def update(self, repo, rev): |
subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--check", "--rev", rev]) |
-class Git(): |
+ def ignore(self, target, repo): |
+ |
+ if not self.istype(target): |
+ |
+ config_path = os.path.join(repo, ".hg", "hgrc") |
+ ignore_path = os.path.abspath(os.path.join(repo, ".hg", "dependencies")) |
+ |
+ config = RawConfigParser() |
+ config.read(config_path) |
+ |
+ if not config.has_section("ui"): |
+ config.add_section("ui") |
+ |
+ config.set("ui", "ignore.dependencies", ignore_path) |
+ with open(config_path, "w") as stream: |
+ config.write(stream) |
+ |
+ module = os.path.relpath(target, repo) |
+ self._ensure_line_exists(ignore_path, module) |
+ |
+class Git(SCM): |
def istype(self, repodir): |
return os.path.exists(os.path.join(repodir, ".git")) |
@@ -87,6 +120,11 @@ |
def update(self, repo, rev): |
subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) |
+ def ignore(self, target, repo): |
+ module = os.path.relpath(target, repo) |
+ exclude_file = os.path.join(repo, ".git", "info", "exclude") |
+ self._ensure_line_exists(exclude_file, module) |
+ |
repo_types = OrderedDict(( |
("hg", Mercurial()), |
("git", Git()), |
@@ -218,6 +256,9 @@ |
continue |
target = safe_join(repodir, dir) |
ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) |
+ for repo in repo_types.itervalues(): |
+ if repo.istype(repodir): |
+ repo.ignore(target, repodir) |
Wladimir Palant
2014/10/08 21:40:30
Why was this code moved again? As noted before, it
|
update_repo(target, revisions) |
resolve_deps(target, level + 1, self_update=False, overrideroots=overrideroots, skipdependencies=skipdependencies) |