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

Delta Between Two Patch Sets: cms/sources.py

Issue 5488197752586240: Issue 2440 - implement Source.get_cache_dir() to be used by custom filters/globals (Closed)
Left Patch Set: Got rid of redundant CMS_CACHE_DIR variable Created April 30, 2015, 2:36 p.m.
Right Patch Set: Only consider last part of repository path Created April 30, 2015, 6:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 class MercurialSource(Source): 204 class MercurialSource(Source):
205 def __init__(self, repo): 205 def __init__(self, repo):
206 command = ["hg", "-R", repo, "archive", "-r", "default", 206 command = ["hg", "-R", repo, "archive", "-r", "default",
207 "-t", "uzip", "-p", ".", "-"] 207 "-t", "uzip", "-p", ".", "-"]
208 data = subprocess.check_output(command) 208 data = subprocess.check_output(command)
209 self._archive = zipfile.ZipFile(StringIO(data), mode="r") 209 self._archive = zipfile.ZipFile(StringIO(data), mode="r")
210 210
211 command = ["hg", "-R", repo, "id", "-n", "-r", "default"] 211 command = ["hg", "-R", repo, "id", "-n", "-r", "default"]
212 self.version = subprocess.check_output(command).strip() 212 self.version = subprocess.check_output(command).strip()
213 213
214 self._origin = urlparse.urlsplit(repo).path.strip('/') 214 self._name = os.path.basename(repo.rstrip(os.path.sep))
Wladimir Palant 2015/04/30 15:45:09 |hg archive| won't work for remote repositories, s
Sebastian Noack 2015/04/30 18:09:19 Fixed. Note that urlparse.urlsplit() did actually
215 215
216 def __enter__(self): 216 def __enter__(self):
217 return self 217 return self
218 218
219 def __exit__(self, type, value, traceback): 219 def __exit__(self, type, value, traceback):
220 self.close() 220 self.close()
221 return False 221 return False
222 222
223 def close(self): 223 def close(self):
224 self._archive.close() 224 self._archive.close()
(...skipping 12 matching lines...) Expand all
237 return result 237 return result
238 238
239 def list_files(self, subdir): 239 def list_files(self, subdir):
240 prefix = "./%s/" % subdir 240 prefix = "./%s/" % subdir
241 for filename in self._archive.namelist(): 241 for filename in self._archive.namelist():
242 if filename.startswith(prefix): 242 if filename.startswith(prefix):
243 yield filename[len(prefix):] 243 yield filename[len(prefix):]
244 244
245 if os.name == "posix": 245 if os.name == "posix":
246 def get_cache_dir(self): 246 def get_cache_dir(self):
247 return "/var/cache/" + self._origin 247 return "/var/cache/" + self._name
248 248
249 class FileSource(Source): 249 class FileSource(Source):
250 def __init__(self, dir): 250 def __init__(self, dir):
251 self._dir = dir 251 self._dir = dir
252 252
253 def __enter__(self): 253 def __enter__(self):
254 return self 254 return self
255 255
256 def __exit__(self, type, value, traceback): 256 def __exit__(self, type, value, traceback):
257 return False 257 return False
(...skipping 24 matching lines...) Expand all
282 path = os.path.join(dir, filename) 282 path = os.path.join(dir, filename)
283 if os.path.isfile(path): 283 if os.path.isfile(path):
284 result.append(relpath + filename) 284 result.append(relpath + filename)
285 elif os.path.isdir(path): 285 elif os.path.isdir(path):
286 do_list(path, relpath + filename + "/") 286 do_list(path, relpath + filename + "/")
287 do_list(self.get_path(subdir), "") 287 do_list(self.get_path(subdir), "")
288 return result 288 return result
289 289
290 def get_cache_dir(self): 290 def get_cache_dir(self):
291 return os.path.join(self._dir, "cache") 291 return os.path.join(self._dir, "cache")
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld