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

Side by Side Diff: lib/naclports/binary_package.py

Issue 1012773005: Improve tracing/logging system used in lib/naclports (Closed) Base URL: https://chromium.googlesource.com/external/naclports.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 # Copyright (c) 2014 The Native Client Authors. All rights reserved. 1 # Copyright (c) 2014 The Native Client 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 import os 5 import os
6 import posixpath 6 import posixpath
7 import shutil 7 import shutil
8 import tarfile 8 import tarfile
9 9
10 from naclports import configuration, package, util, error 10 from naclports import configuration, package, util, error
11 11
12 PAYLOAD_DIR = 'payload' 12 PAYLOAD_DIR = 'payload'
13 13
14 14
15 def InstallFile(filename, old_root, new_root): 15 def InstallFile(filename, old_root, new_root):
16 """Install a single file by moving it into a new location. 16 """Install a single file by moving it into a new location.
17 17
18 Args: 18 Args:
19 filename: Relative name of file to install. 19 filename: Relative name of file to install.
20 old_root: The current location of the file. 20 old_root: The current location of the file.
21 new_root: The new desired root for the file. 21 new_root: The new desired root for the file.
22 """ 22 """
23 oldname = os.path.join(old_root, filename) 23 oldname = os.path.join(old_root, filename)
24 24
25 util.Trace('install: %s' % filename) 25 util.LogVerbose('install: %s' % filename)
26 26
27 newname = os.path.join(new_root, filename) 27 newname = os.path.join(new_root, filename)
28 dirname = os.path.dirname(newname) 28 dirname = os.path.dirname(newname)
29 if not os.path.isdir(dirname): 29 if not os.path.isdir(dirname):
30 util.Makedirs(dirname) 30 util.Makedirs(dirname)
31 os.rename(oldname, newname) 31 os.rename(oldname, newname)
32 32
33 33
34 def RelocateFile(filename, dest): 34 def RelocateFile(filename, dest):
35 """Perform in-place mutations on file contents to handle new location. 35 """Perform in-place mutations on file contents to handle new location.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 def _Install(self): 132 def _Install(self):
133 dest = util.GetInstallRoot(self.config) 133 dest = util.GetInstallRoot(self.config)
134 dest_tmp = os.path.join(dest, 'install_tmp') 134 dest_tmp = os.path.join(dest, 'install_tmp')
135 if os.path.exists(dest_tmp): 135 if os.path.exists(dest_tmp):
136 shutil.rmtree(dest_tmp) 136 shutil.rmtree(dest_tmp)
137 137
138 if self.IsAnyVersionInstalled(): 138 if self.IsAnyVersionInstalled():
139 raise error.Error('package already installed: %s' % self.InfoString()) 139 raise error.Error('package already installed: %s' % self.InfoString())
140 140
141 self.LogStatus('Installing') 141 self.LogStatus('Installing')
142 util.LogVerbose('installing from: %s' % self.filename)
142 util.Makedirs(dest_tmp) 143 util.Makedirs(dest_tmp)
143 144
144 names = [] 145 names = []
145 try: 146 try:
146 with tarfile.open(self.filename) as tar: 147 with tarfile.open(self.filename) as tar:
147 for info in tar: 148 for info in tar:
148 if info.isdir(): 149 if info.isdir():
149 continue 150 continue
150 name = posixpath.normpath(info.name) 151 name = posixpath.normpath(info.name)
151 if name == 'pkg_info': 152 if name == 'pkg_info':
(...skipping 17 matching lines...) Expand all
169 shutil.rmtree(dest_tmp) 170 shutil.rmtree(dest_tmp)
170 171
171 for name in names: 172 for name in names:
172 RelocateFile(name, dest) 173 RelocateFile(name, dest)
173 self.WriteFileList(names) 174 self.WriteFileList(names)
174 self.WriteStamp() 175 self.WriteStamp()
175 176
176 def WriteStamp(self): 177 def WriteStamp(self):
177 """Write stamp file containing pkg_info.""" 178 """Write stamp file containing pkg_info."""
178 filename = util.GetInstallStamp(self.NAME, self.config) 179 filename = util.GetInstallStamp(self.NAME, self.config)
179 util.Trace('stamp: %s' % filename) 180 util.LogVerbose('stamp: %s' % filename)
180 pkg_info = self.GetPkgInfo() 181 pkg_info = self.GetPkgInfo()
181 with open(filename, 'w') as f: 182 with open(filename, 'w') as f:
182 f.write(pkg_info) 183 f.write(pkg_info)
183 184
184 def WriteFileList(self, file_names): 185 def WriteFileList(self, file_names):
185 """Write the file list for this package.""" 186 """Write the file list for this package."""
186 filename = self.GetListFile() 187 filename = self.GetListFile()
187 dirname = os.path.dirname(filename) 188 dirname = os.path.dirname(filename)
188 if not os.path.isdir(dirname): 189 if not os.path.isdir(dirname):
189 util.Makedirs(dirname) 190 util.Makedirs(dirname)
190 with open(filename, 'w') as f: 191 with open(filename, 'w') as f:
191 for name in file_names: 192 for name in file_names:
192 f.write(name + '\n') 193 f.write(name + '\n')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698