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

Side by Side Diff: packager.py

Issue 29326127: Issue 3017 - Improve metadata file mapping precedence (Closed)
Patch Set: Created Sept. 8, 2015, 1:48 p.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 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 # Note: These are the base functions common to all packagers, the actual 7 # Note: These are the base functions common to all packagers, the actual
8 # packagers are implemented in packagerGecko and packagerChrome. 8 # packagers are implemented in packagerGecko and packagerChrome.
9 9
10 import sys, os, re, codecs, subprocess, json, zipfile 10 import sys, os, re, codecs, subprocess, json, zipfile
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return False 88 return False
89 return True 89 return True
90 90
91 def read(self, path, relpath='', skip=None): 91 def read(self, path, relpath='', skip=None):
92 if os.path.isdir(path): 92 if os.path.isdir(path):
93 for file in os.listdir(path): 93 for file in os.listdir(path):
94 name = relpath + ('/' if relpath != '' else '') + file 94 name = relpath + ('/' if relpath != '' else '') + file
95 if (skip == None or file not in skip) and self.isIncluded(name): 95 if (skip == None or file not in skip) and self.isIncluded(name):
96 self.read(os.path.join(path, file), name) 96 self.read(os.path.join(path, file), name)
97 else: 97 else:
98 file = open(path, 'rb') 98 with open(path, 'rb') as file:
99 if relpath in self: 99 if relpath in self:
100 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpath 100 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpat h
101 self[relpath] = file.read() 101 else:
102 file.close() 102 self[relpath] = file.read()
103 103
104 def readMappedFiles(self, mappings): 104 def readMappedFiles(self, mappings):
105 for item in mappings: 105 for item in mappings:
106 target, source = item 106 target, source = item
107 107
108 # Make sure the file is inside an included directory 108 # Make sure the file is inside an included directory
109 if '/' in target and not self.isIncluded(target): 109 if '/' in target and not self.isIncluded(target):
110 continue 110 continue
111 parts = source.split('/') 111 parts = source.split('/')
112 path = os.path.join(os.path.dirname(item.source), *parts) 112 path = os.path.join(os.path.dirname(item.source), *parts)
(...skipping 16 matching lines...) Expand all
129 names = self.keys() 129 names = self.keys()
130 names.sort(key=sortKey) 130 names.sort(key=sortKey)
131 for name in names: 131 for name in names:
132 zip.writestr(name, self[name]) 132 zip.writestr(name, self[name])
133 zip.close() 133 zip.close()
134 134
135 def zipToString(self, sortKey=None): 135 def zipToString(self, sortKey=None):
136 buffer = StringIO() 136 buffer = StringIO()
137 self.zip(buffer, sortKey=sortKey) 137 self.zip(buffer, sortKey=sortKey)
138 return buffer.getvalue() 138 return buffer.getvalue()
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