Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: scripts/common/archive_utils.py

Issue 2402423002: Enable saving the same file in multiple archives (Closed)
Patch Set: Remove accidental commit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | scripts/common/archive_utils_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Set of common operations/utilities for build archiving.""" 5 """Set of common operations/utilities for build archiving."""
6 6
7 import glob 7 import glob
8 import os 8 import os
9 import platform 9 import platform
10 import re 10 import re
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 symbol_staging_url = 'http://clients2.google.com/cr/staging_symbol' 71 symbol_staging_url = 'http://clients2.google.com/cr/staging_symbol'
72 72
73 73
74 class FilesCfgParser(object): 74 class FilesCfgParser(object):
75 """Class to process a FILES.cfg style listing of build files.""" 75 """Class to process a FILES.cfg style listing of build files."""
76 76
77 def __init__(self, files_file, buildtype, arch): 77 def __init__(self, files_file, buildtype, arch):
78 self._buildtype = buildtype 78 self._buildtype = buildtype
79 self._arch = arch 79 self._arch = arch
80 self._files_cfg = self._ParseFilesCfg(files_file) 80 self._files_cfg = self._ParseFilesCfg(files_file)
81 self.files_dict = self._FilterFilesCfg() 81 self._files_list = self._FilterFilesCfg()
82 82
83 def _SetArch(self, value): 83 def _SetArch(self, value):
84 """Set build arch and reset files_dict to reflect new build criteria.""" 84 """Set build arch and reset files_list to reflect new build criteria."""
85 self._arch = value 85 self._arch = value
86 self.files_dict.clear() 86 del self._files_list[:]
87 self.files_dict.update(self._FilterFilesCfg()) 87 self._files_list.extend(self._FilterFilesCfg())
88 88
89 arch = property(fset=_SetArch) 89 arch = property(fset=_SetArch)
90 90
91 def _SetBuildType(self, value): 91 def _SetBuildType(self, value):
92 """Set build type and reset files_dict to reflect new build criteria.""" 92 """Set build type and reset files_list to reflect new build criteria."""
93 self._buildtype = value 93 self._buildtype = value
94 self.files_dict.clear() 94 del self._files_list[:]
95 self.files_dict.update(self._FilterFilesCfg()) 95 self._files_list.extend(self._FilterFilesCfg())
96 96
97 buildtype = property(fset=_SetBuildType) 97 buildtype = property(fset=_SetBuildType)
98 98
99 def _FilterFilesCfg(self): 99 def _FilterFilesCfg(self):
100 """Return a dict of file items that match the current build criteria.""" 100 """Return a list of file items that match the current build criteria."""
101 files_dict = {} 101 files_list = []
102 for fileobj in self._files_cfg: 102 for fileobj in self._files_cfg:
103 if self._buildtype not in fileobj['buildtype']: 103 if self._buildtype not in fileobj['buildtype']:
104 continue 104 continue
105 if not fileobj.get('arch') or self._arch in fileobj['arch']: 105 if not fileobj.get('arch') or self._arch in fileobj['arch']:
106 files_dict[fileobj['filename']] = fileobj 106 files_list.append(fileobj)
107 return files_dict 107 return files_list
108 108
109 @staticmethod 109 @staticmethod
110 def _ParseFilesCfg(files_file): 110 def _ParseFilesCfg(files_file):
111 """Return the dictionary of archive file info read from the given file.""" 111 """Return the dictionary of archive file info read from the given file."""
112 if not os.path.exists(files_file): 112 if not os.path.exists(files_file):
113 raise StagingError('Files list does not exist (%s).' % files_file) 113 raise StagingError('Files list does not exist (%s).' % files_file)
114 exec_globals = {'__builtins__': None} 114 exec_globals = {'__builtins__': None}
115 115
116 execfile(files_file, exec_globals) 116 execfile(files_file, exec_globals)
117 return exec_globals['FILES'] 117 return exec_globals['FILES']
118 118
119 @classmethod 119 @classmethod
120 def IsDirectArchive(cls, archive_list): 120 def IsDirectArchive(cls, archive_list):
121 """Determine if the given archive list should be archived as-is. 121 """Determine if the given archive list should be archived as-is.
122 122
123 An archive list (from ParseArchiveLists) is archived as-is (not added to 123 An archive list (from ParseArchiveLists) is archived as-is (not added to
124 another archive file) iff: 124 another archive file) iff:
125 - There list contains a single file, and 125 - There list contains a single file, and
126 - That file has the 'direct_archive' flag or its 'archive' name matches 126 - That file has the 'direct_archive' flag or its 'archive' name matches
127 its 'filename' (an implied 'direct_archive'). 127 its 'filename' (an implied 'direct_archive').
128 """ 128 """
129 fileobj = archive_list[0] 129 fileobj = archive_list[0]
130 return (len(archive_list) == 1 and 130 return (len(archive_list) == 1 and
131 (fileobj['filename'] == fileobj['archive'] or 131 (fileobj['filename'] == fileobj['archive'] or
132 fileobj.get('direct_archive'))) 132 fileobj.get('direct_archive')))
133 133
134 def IsOptional(self, filename): 134 def IsOptional(self, filename):
135 """Determine if the given filename is marked optional for this config.""" 135 """Determine if the given filename is marked optional for this config."""
136 return (self.files_dict.get(filename) and self._buildtype in 136 has_file = False
137 self.files_dict[filename].get('optional', [])) 137 for fileobj in self._files_list:
138 if fileobj['filename'] == filename:
139 has_file = True
140 if self._buildtype not in fileobj['optional']:
141 return False
142 return has_file
Michael Moss 2016/10/11 18:23:32 Maybe simplify slightly by getting rid of the 'has
Michael Moss 2016/10/11 18:47:06 Ugh, my logic was backwards, ignore. We want it to
138 143
139 def ParseGroup(self, filegroup): 144 def ParseGroup(self, filegroup):
140 """Return the list of filenames in the given group (e.g. "symbols").""" 145 """Return the list of filenames in the given group (e.g. "symbols")."""
141 return [fileobj['filename'] for fileobj in self.files_dict.itervalues() 146 return [fileobj['filename'] for fileobj in self._files_list
142 if (fileobj.get('filegroup') and filegroup in fileobj.get('filegroup')) 147 if (fileobj.get('filegroup') and filegroup in fileobj.get('filegroup'))
143 ] 148 ]
144 149
145 def ParseArchiveLists(self): 150 def ParseArchiveLists(self):
146 """Generate a dict of all the file items in all archives.""" 151 """Generate a dict of all the file items in all archives."""
147 archive_lists = {} 152 archive_lists = {}
148 for fileobj in self.files_dict.itervalues(): 153 for fileobj in self._files_list:
149 if fileobj.get('archive'): 154 if fileobj.get('archive'):
150 archive_lists.setdefault(fileobj['archive'], []).append(fileobj) 155 archive_lists.setdefault(fileobj['archive'], []).append(fileobj)
151 return archive_lists 156 return archive_lists
152 157
153 def ParseLegacyList(self): 158 def ParseLegacyList(self):
154 """Return the list of 'default' filenames. 159 """Return the list of 'default' filenames.
155 160
156 Default files are either tagged as "default" filegroup or they have no 161 Default files are either tagged as "default" filegroup or they have no
157 filegroup (i.e. legacy entries from before the filegroup field was added.) 162 filegroup (i.e. legacy entries from before the filegroup field was added.)
158 """ 163 """
159 files_list = [ 164 files_list = [
160 fileobj['filename'] for fileobj in self.files_dict.itervalues() 165 fileobj['filename'] for fileobj in self._files_list
161 if (not fileobj.get('archive') and 166 if (not fileobj.get('archive') and
162 (not fileobj.get('filegroup') or 'default' in 167 (not fileobj.get('filegroup') or 'default' in
163 fileobj.get('filegroup'))) 168 fileobj.get('filegroup')))
164 ] 169 ]
165 return files_list 170 return files_list
166 171
167
Michael Moss 2016/10/11 18:23:32 Nit: Keep 2 lines before top-level functions/class
chenwilliam 2016/10/11 19:08:15 Done.
168 def ParseFilesList(files_file, buildtype, arch): 172 def ParseFilesList(files_file, buildtype, arch):
169 """DEPRECATED: Determine the list of archive files for a given release. 173 """DEPRECATED: Determine the list of archive files for a given release.
170 174
171 NOTE: This can be removed after 20.x goes stable (or after scripts/common/ 175 NOTE: This can be removed after 20.x goes stable (or after scripts/common/
172 gets versioned on the official builders like site_config is). 176 gets versioned on the official builders like site_config is).
173 """ 177 """
174 fparser = FilesCfgParser(files_file, buildtype, arch) 178 fparser = FilesCfgParser(files_file, buildtype, arch)
175 return fparser.ParseLegacyList() 179 return fparser.ParseLegacyList()
176 180
177 181
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 raise_error=not allow_missing) 324 raise_error=not allow_missing)
321 if not os.path.exists(zip_file): 325 if not os.path.exists(zip_file):
322 raise StagingError('Failed to make zip package %s' % zip_file) 326 raise StagingError('Failed to make zip package %s' % zip_file)
323 327
324 if os.path.basename(zip_file) != archive_name: 328 if os.path.basename(zip_file) != archive_name:
325 orig_zip = zip_file 329 orig_zip = zip_file
326 zip_file = os.path.join(os.path.dirname(orig_zip), archive_name) 330 zip_file = os.path.join(os.path.dirname(orig_zip), archive_name)
327 print 'Renaming archive: "%s" -> "%s"' % (orig_zip, zip_file) 331 print 'Renaming archive: "%s" -> "%s"' % (orig_zip, zip_file)
328 chromium_utils.MoveFile(orig_zip, zip_file) 332 chromium_utils.MoveFile(orig_zip, zip_file)
329 return (zip_dir, zip_file) 333 return (zip_dir, zip_file)
OLDNEW
« no previous file with comments | « no previous file | scripts/common/archive_utils_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698