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

Side by Side Diff: ensure_dependencies.py

Issue 5934936779390976: 1377 - Blacklist dependencies from SCM tracking (Closed)
Patch Set: Created Sept. 23, 2014, 9:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This file is part of the Adblock Plus build tools, 4 # This file is part of the Adblock Plus build tools,
5 # Copyright (C) 2006-2014 Eyeo GmbH 5 # Copyright (C) 2006-2014 Eyeo GmbH
6 # 6 #
7 # Adblock Plus is free software: you can redistribute it and/or modify 7 # Adblock Plus is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 3 as 8 # it under the terms of the GNU General Public License version 3 as
9 # published by the Free Software Foundation. 9 # published by the Free Software Foundation.
10 # 10 #
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 # should simply return an empty string. 60 # should simply return an empty string.
61 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0] 61 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0]
62 return result.strip() 62 return result.strip()
63 63
64 def pull(self, repo): 64 def pull(self, repo):
65 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"]) 65 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"])
66 66
67 def update(self, repo, rev): 67 def update(self, repo, rev):
68 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev]) 68 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev])
69 69
70 def ignore(self, target):
71 if not self.istype(target):
72 logging.warning("Mercurial won't ignore dependency %s by default. You shou ld do it manually." % (target))
Wladimir Palant 2014/09/23 15:04:13 Quite the opposite actually - Mercurial will autom
mathias 2014/09/23 16:20:05 Mercurial does not ignore Git submodules (just ver
Wladimir Palant 2014/09/25 19:52:20 You are right, so a local hgignore file should be
mathias 2014/09/26 05:06:39 Thank you for the "local" keyword! I've been searc
mathias 2014/09/28 00:24:25 Done.
73
70 class Git(): 74 class Git():
71 def istype(self, repodir): 75 def istype(self, repodir):
72 return os.path.exists(os.path.join(repodir, ".git")) 76 return os.path.exists(os.path.join(repodir, ".git"))
73 77
74 def clone(self, source, target): 78 def clone(self, source, target):
75 source = source.rstrip("/") 79 source = source.rstrip("/")
76 if not source.endswith(".git"): 80 if not source.endswith(".git"):
77 source += ".git" 81 source += ".git"
78 subprocess.check_call(["git", "clone", "--quiet", source, target]) 82 subprocess.check_call(["git", "clone", "--quiet", source, target])
79 83
80 def get_revision_id(self, repo, rev="HEAD"): 84 def get_revision_id(self, repo, rev="HEAD"):
81 command = ["git", "rev-parse", "--revs-only", rev] 85 command = ["git", "rev-parse", "--revs-only", rev]
82 return subprocess.check_output(command, cwd=repo).strip() 86 return subprocess.check_output(command, cwd=repo).strip()
83 87
84 def pull(self, repo): 88 def pull(self, repo):
85 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 89 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
86 90
87 def update(self, repo, rev): 91 def update(self, repo, rev):
88 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 92 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
89 93
94 def ignore(self, target):
95 module = str(target).replace(os.getcwd(),'')[1:]
Wladimir Palant 2014/09/23 15:04:13 There is a reason why this script never relies on
mathias 2014/09/23 16:20:05 Agreed, will be addressed in the next patch-set.
mathias 2014/09/28 00:24:25 Done.
96 exclude_file = '.git/info/exclude'
97 if os.path.exists(exclude_file):
Wladimir Palant 2014/09/23 15:04:13 1) Please don't use relative file paths (see above
mathias 2014/09/23 16:20:05 Agreed, will be addressed in the next patch-set.
mathias 2014/09/28 00:24:25 Done.
98 with open(exclude_file, 'r') as f:
99 exclude_file_content = f.read().splitlines()
Wladimir Palant 2014/09/23 15:04:13 I'd rather do [l.strip() for l in f.readlines()] h
mathias 2014/09/23 16:20:05 Agreed, will be addressed in the next patch-set.
mathias 2014/09/28 00:24:25 Done.
100 if not module in exclude_file_content:
101 logging.warning("Adding dependency %s to %s" % (module, exclude_file) )
Wladimir Palant 2014/09/23 15:04:13 1) Why is this a warning? Nothing is wrong, a comp
mathias 2014/09/23 16:20:05 Agreed, we just remove the line entirely.
mathias 2014/09/28 00:24:25 Done.
102 exclude_file_content = open(exclude_file, 'a')
Wladimir Palant 2014/09/23 15:04:13 This will fail on Windows - you are opening a file
mathias 2014/09/23 16:20:05 Agreed, will be addressed in the next patch-set.
mathias 2014/09/28 00:24:25 Done.
103 exclude_file_content.write("\n"+module)
Wladimir Palant 2014/09/23 15:04:13 What if there is already a line break at the end o
mathias 2014/09/23 16:20:05 Agreed, will be addressed in the next patch-set.
mathias 2014/09/28 00:24:25 Done.
104 exclude_file_content.close()
Wladimir Palant 2014/09/23 15:04:13 If your code throws an exception that file will ne
mathias 2014/09/23 16:20:05 Agreed, will be addressed as well.
mathias 2014/09/28 00:24:25 Done.
105
90 repo_types = { 106 repo_types = {
91 "hg": Mercurial(), 107 "hg": Mercurial(),
92 "git": Git(), 108 "git": Git(),
93 } 109 }
94 110
95 def parse_spec(path, line): 111 def parse_spec(path, line):
96 if "=" not in line: 112 if "=" not in line:
97 logging.warning("Invalid line in file %s: %s" % (path, line)) 113 logging.warning("Invalid line in file %s: %s" % (path, line))
98 return None, None 114 return None, None
99 115
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if overrideroots is not None: 229 if overrideroots is not None:
214 config["_root"] = overrideroots 230 config["_root"] = overrideroots
215 231
216 for dir, revisions in config.iteritems(): 232 for dir, revisions in config.iteritems():
217 if dir.startswith("_") or revisions["_source"] in skipdependencies: 233 if dir.startswith("_") or revisions["_source"] in skipdependencies:
218 continue 234 continue
219 target = safe_join(repodir, dir) 235 target = safe_join(repodir, dir)
220 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) 236 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"])
221 update_repo(target, revisions) 237 update_repo(target, revisions)
222 resolve_deps(target, level + 1, self_update=False, overrideroots=overrideroo ts, skipdependencies=skipdependencies) 238 resolve_deps(target, level + 1, self_update=False, overrideroots=overrideroo ts, skipdependencies=skipdependencies)
239 for repo in repo_types.itervalues():
240 if repo.istype(repodir):
241 repo.ignore(target)
Wladimir Palant 2014/09/23 15:04:13 IMHO, this should be part of ensure_repo(): 1) Th
mathias 2014/09/23 16:20:05 Valid point, we move it to `ensure_repo()`. Note,
mathias 2014/09/28 00:24:25 Done.
223 242
224 if self_update and "_self" in config and "*" in config["_self"]: 243 if self_update and "_self" in config and "*" in config["_self"]:
225 source = safe_join(repodir, config["_self"]["*"]) 244 source = safe_join(repodir, config["_self"]["*"])
226 try: 245 try:
227 with io.open(source, "rb") as handle: 246 with io.open(source, "rb") as handle:
228 sourcedata = handle.read() 247 sourcedata = handle.read()
229 except IOError, e: 248 except IOError, e:
230 if e.errno != errno.ENOENT: 249 if e.errno != errno.ENOENT:
231 raise 250 raise
232 logging.warning("File %s doesn't exist, skipping self-update" % source) 251 logging.warning("File %s doesn't exist, skipping self-update" % source)
(...skipping 13 matching lines...) Expand all
246 else: 265 else:
247 logging.warning("Cannot restart %s automatically, please rerun" % target ) 266 logging.warning("Cannot restart %s automatically, please rerun" % target )
248 267
249 if __name__ == "__main__": 268 if __name__ == "__main__":
250 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) 269 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
251 repos = sys.argv[1:] 270 repos = sys.argv[1:]
252 if not len(repos): 271 if not len(repos):
253 repos = [os.getcwd()] 272 repos = [os.getcwd()]
254 for repo in repos: 273 for repo in repos:
255 resolve_deps(repo) 274 resolve_deps(repo)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld