Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ensure_dependencies.py

Issue 5986495445860352: 1377-Blacklist_dependencies (Closed)
Patch Set: Created Sept. 29, 2014, 11:41 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Makefile ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ensure_dependencies.py
diff --git a/ensure_dependencies.py b/ensure_dependencies.py
index 586d737b87c81d6c4c1fb6dc146eabd3f9b46127..ddd02692c7df2bdd7ec68ce438096aa950f39e3a 100755
--- a/ensure_dependencies.py
+++ b/ensure_dependencies.py
@@ -25,7 +25,9 @@ import errno
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,20 @@ A dependencies file should look like this:
buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5
"""
-class Mercurial():
+class SCM(object):
+ def _ignore(self, target, file_name):
+ with open(file_name, 'a+') as f:
+ file_content = [l.strip() for l in f.readlines()]
+ if not target in file_content:
+ if len(file_content):
+ f.seek(-1, os.SEEK_CUR)
+ last_character = f.read(1)
+ if not last_character in "\r\n":
+ f.write(os.linesep)
+ f.write(target)
+ f.write(os.linesep)
+
+class Mercurial(SCM):
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".hg"))
@@ -67,7 +82,30 @@ class Mercurial():
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.join(".", ".hg", "dependencies")
+
+ config = RawConfigParser()
+ config.read(config_path)
+
+ if not config.has_section("ui"):
+ config.add_section("ui")
+
+ if not config.has_option("ui", "ignore.dependencies"):
+ config.set("ui", "ignore.dependencies", ignore_path)
+ with open(config_path, "w") as stream:
+ config.write(stream)
+ else:
+ ignore_path = config.get("ui", "ignore.dependencies")
+
+ module = os.path.relpath(target, repo)
+ self._ignore(module, ignore_path)
+
+class Git(SCM):
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".git"))
@@ -87,6 +125,11 @@ class Git():
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._ignore(module, exclude_file)
+
repo_types = {
"hg": Mercurial(),
"git": Git(),
@@ -161,7 +204,6 @@ def get_repo_type(repo):
def ensure_repo(parentrepo, target, roots, sourcename):
if os.path.exists(target):
return
-
parenttype = get_repo_type(parentrepo)
type = None
for key in roots:
@@ -174,6 +216,10 @@ def ensure_repo(parentrepo, target, roots, sourcename):
logging.info("Cloning repository %s into %s" % (url, target))
repo_types[type].clone(url, target)
+ for repo in repo_types.itervalues():
+ if repo.istype(parentrepo):
+ repo.ignore(target, parentrepo)
+
def update_repo(target, revisions):
type = get_repo_type(target)
if type is None:
« no previous file with comments | « Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld