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

Delta Between Two Patch Sets: packager.py

Issue 29490563: Issue 3967 - Properly handle non-existing file-mappings (Closed)
Left Patch Set: Created July 17, 2017, 12:27 p.m.
Right Patch Set: Created July 17, 2017, 4:24 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 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 # Note: These are the base functions common to all packagers, the actual 5 # Note: These are the base functions common to all packagers, the actual
6 # packagers are implemented in packagerGecko and packagerChrome. 6 # packagers are implemented in packagerGecko and packagerChrome.
7 7
8 import sys 8 import sys
9 import os 9 import os
10 import re 10 import re
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 def __setitem__(self, key, value): 88 def __setitem__(self, key, value):
89 if self.process: 89 if self.process:
90 value = self.process(key, value) 90 value = self.process(key, value)
91 dict.__setitem__(self, key, value) 91 dict.__setitem__(self, key, value)
92 92
93 def isIncluded(self, relpath): 93 def isIncluded(self, relpath):
94 return relpath.split('/')[0] in self.includedFiles 94 return relpath.split('/')[0] in self.includedFiles
95 95
96 def is_ignored(self, relpath): 96 def is_ignored(self, relpath):
97 parts = relpath.split('/') 97 parts = relpath.split('/')
98 return any([part in self.ignoredFiles for part in parts]) 98 return any(part in self.ignoredFiles for part in parts)
Sebastian Noack 2017/07/17 14:02:32 Nit: The brackets in order to generate a temporary
tlucas 2017/07/17 14:56:16 Acknowledged.
99 99
100 def read(self, path, relpath='', skip=()): 100 def read(self, path, relpath='', skip=()):
101 if os.path.isdir(path): 101 if os.path.isdir(path):
102 for file in os.listdir(path): 102 for file in os.listdir(path):
103 name = relpath + ('/' if relpath != '' else '') + file 103 name = relpath + ('/' if relpath != '' else '') + file
104 if (name not in skip 104
105 and self.isIncluded(name) and not self.is_ignored(name)) : 105 included = self.isIncluded(name) and not self.is_ignored(name)
106 if name not in skip and included:
106 self.read(os.path.join(path, file), name, skip) 107 self.read(os.path.join(path, file), name, skip)
107 else: 108 else:
108 with open(path, 'rb') as file: 109 with open(path, 'rb') as file:
109 if relpath in self: 110 if relpath in self:
110 print >>sys.stderr, 'Warning: File %s defined multiple times ' % relpath 111 print >>sys.stderr, 'Warning: File %s defined multiple times ' % relpath
111 self[relpath] = file.read() 112 self[relpath] = file.read()
112 113
113 def readMappedFiles(self, mappings): 114 def readMappedFiles(self, mappings):
114 for item in mappings: 115 for item in mappings:
115 target, source = item 116 target, source = item
(...skipping 19 matching lines...) Expand all
135 136
136 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED): 137 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED):
137 with zipfile.ZipFile(outFile, 'w', compression) as zf: 138 with zipfile.ZipFile(outFile, 'w', compression) as zf:
138 for name in sorted(self, key=sortKey): 139 for name in sorted(self, key=sortKey):
139 zf.writestr(name, self[name]) 140 zf.writestr(name, self[name])
140 141
141 def zipToString(self, sortKey=None): 142 def zipToString(self, sortKey=None):
142 buffer = StringIO() 143 buffer = StringIO()
143 self.zip(buffer, sortKey=sortKey) 144 self.zip(buffer, sortKey=sortKey)
144 return buffer.getvalue() 145 return buffer.getvalue()
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