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

Side by Side Diff: generate_au_zip.py

Issue 5686004: Switching most of the logging to debug (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Switching most of the logging to debug Created 10 years 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 | Annotate | Revision Log
« 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 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """ 7 """
8 Script to generate a zip file of delta-generator and it's dependencies. 8 Script to generate a zip file of delta-generator and it's dependencies.
9 """ 9 """
10 import logging.handlers 10 import logging.handlers
11 import optparse 11 import optparse
12 import os 12 import os
13 import re 13 import re
14 import shutil 14 import shutil
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 import tempfile 17 import tempfile
18 18
19 # GLOBALS 19 # GLOBALS
20 20
21 logging_format = '%(asctime)s - %(filename)s - %(levelname)-8s: %(message)s' 21 logging_format = '%(asctime)s - %(filename)s - %(levelname)-8s: %(message)s'
22 date_format = '%Y/%m/%d %H:%M:%S' 22 date_format = '%Y/%m/%d %H:%M:%S'
23 logging.basicConfig(level=logging.INFO, format=logging_format, 23 logging.basicConfig(level=logging.INFO, format=logging_format,
24 datefmt=date_format) 24 datefmt=date_format)
25 25
26 def CreateTempDir(): 26 def CreateTempDir():
27 """Creates a tempdir and returns the name of the tempdir.""" 27 """Creates a tempdir and returns the name of the tempdir."""
28 temp_dir = tempfile.mkdtemp(suffix='au', prefix='tmp') 28 temp_dir = tempfile.mkdtemp(suffix='au', prefix='tmp')
29 logging.info('Using tempdir = %s', temp_dir) 29 logging.debug('Using tempdir = %s', temp_dir)
30 return temp_dir 30 return temp_dir
31 31
32 32
33 def _SplitAndStrip(data): 33 def _SplitAndStrip(data):
34 """Prunes the ldd output, and return a list of needed library names 34 """Prunes the ldd output, and return a list of needed library names
35 Example of data: 35 Example of data:
36 linux-vdso.so.1 => (0x00007ffffc96a000) 36 linux-vdso.so.1 => (0x00007ffffc96a000)
37 libbz2.so.1 => /lib/libbz2.so.1 (0x00007f3ff8782000) 37 libbz2.so.1 => /lib/libbz2.so.1 (0x00007f3ff8782000)
38 libc.so.6 => /lib/libc.so.6 (0x00007f3ff83ff000) 38 libc.so.6 => /lib/libc.so.6 (0x00007f3ff83ff000)
39 /lib64/ld-linux-x86-64.so.2 (0x00007f3ff89b3000) 39 /lib64/ld-linux-x86-64.so.2 (0x00007f3ff89b3000)
(...skipping 19 matching lines...) Expand all
59 59
60 def DepsToCopy(ldd_files, black_list): 60 def DepsToCopy(ldd_files, black_list):
61 """Returns a list of deps for a given dynamic executables list. 61 """Returns a list of deps for a given dynamic executables list.
62 Args: 62 Args:
63 ldd_files: List of dynamic files that needs to have the deps evaluated 63 ldd_files: List of dynamic files that needs to have the deps evaluated
64 black_list: List of files that we should ignore 64 black_list: List of files that we should ignore
65 Returns: 65 Returns:
66 library_list: List of files that are dependencies 66 library_list: List of files that are dependencies
67 """ 67 """
68 for file_name in ldd_files: 68 for file_name in ldd_files:
69 logging.info('Running ldd on %s', file_name) 69 logging.debug('Running ldd on %s', file_name)
70 cmd = ['/usr/bin/ldd', file_name] 70 cmd = ['/usr/bin/ldd', file_name]
71 stdout_data = '' 71 stdout_data = ''
72 stderr_data = '' 72 stderr_data = ''
73 73
74 try: 74 try:
75 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, 75 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
76 stderr=subprocess.PIPE) 76 stderr=subprocess.PIPE)
77 (stdout_data, stderr_data) = proc.communicate(input=None) 77 (stdout_data, stderr_data) = proc.communicate(input=None)
78 except subprocess.CalledProcessError, e: 78 except subprocess.CalledProcessError, e:
79 logging.error('Command %s failed', cmd) 79 logging.error('Command %s failed', cmd)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 all_files = map(os.path.expanduser, all_files) 130 all_files = map(os.path.expanduser, all_files)
131 131
132 for file_name in all_files: 132 for file_name in all_files:
133 if not os.path.isfile(file_name): 133 if not os.path.isfile(file_name):
134 logging.error('file = %s does not exist', file_name) 134 logging.error('file = %s does not exist', file_name)
135 sys.exit(1) 135 sys.exit(1)
136 136
137 logging.debug('Given files that need to be copied = %s' % '' .join(all_files)) 137 logging.debug('Given files that need to be copied = %s' % '' .join(all_files))
138 all_files += DepsToCopy(ldd_files=ldd_files,black_list=black_list) 138 all_files += DepsToCopy(ldd_files=ldd_files,black_list=black_list)
139 for file_name in all_files: 139 for file_name in all_files:
140 logging.info('Copying file %s to %s', file_name, dest_files_root) 140 logging.debug('Copying file %s to %s', file_name, dest_files_root)
141 shutil.copy2(file_name, dest_files_root) 141 shutil.copy2(file_name, dest_files_root)
142 142
143 for source_dir, target_dir in recurse_dirs.iteritems(): 143 for source_dir, target_dir in recurse_dirs.iteritems():
144 logging.info('Processing directory %s', source_dir) 144 logging.debug('Processing directory %s', source_dir)
145 full_path = os.path.expanduser(source_dir) 145 full_path = os.path.expanduser(source_dir)
146 if not os.path.isdir(full_path): 146 if not os.path.isdir(full_path):
147 logging.error("Directory given for %s expanded to %s doens't exist.", 147 logging.error("Directory given for %s expanded to %s doens't exist.",
148 source_dir, full_path) 148 source_dir, full_path)
149 sys.exit(1) 149 sys.exit(1)
150 dest = os.path.join(dest_files_root, target_dir) 150 dest = os.path.join(dest_files_root, target_dir)
151 logging.info('Copying directory %s to %s.', full_path, target_dir) 151 logging.debug('Copying directory %s to %s.', full_path, target_dir)
152 shutil.copytree(full_path, dest) 152 shutil.copytree(full_path, dest)
153 153
154 def CleanUp(temp_dir): 154 def CleanUp(temp_dir):
155 """Cleans up the tempdir 155 """Cleans up the tempdir
156 Args: 156 Args:
157 temp_dir = name of the directory to cleanup 157 temp_dir = name of the directory to cleanup
158 """ 158 """
159 if os.path.exists(temp_dir): 159 if os.path.exists(temp_dir):
160 shutil.rmtree(temp_dir, ignore_errors=True) 160 shutil.rmtree(temp_dir, ignore_errors=True)
161 logging.info('Removed tempdir = %s', temp_dir) 161 logging.debug('Removed tempdir = %s', temp_dir)
162 162
163 def GenerateZipFile(base_name, root_dir): 163 def GenerateZipFile(base_name, root_dir):
164 """Returns true if able to generate zip file 164 """Returns true if able to generate zip file
165 Args: 165 Args:
166 base_name: name of the zip file 166 base_name: name of the zip file
167 root_dir: location of the directory that we should zip 167 root_dir: location of the directory that we should zip
168 Returns: 168 Returns:
169 True if successfully generates the zip file otherwise False 169 True if successfully generates the zip file otherwise False
170 """ 170 """
171 logging.info('Generating zip file %s with contents from %s', base_name, 171 logging.debug('Generating zip file %s with contents from %s', base_name,
172 root_dir) 172 root_dir)
173 current_dir = os.getcwd() 173 current_dir = os.getcwd()
174 os.chdir(root_dir) 174 os.chdir(root_dir)
175 try: 175 try:
176 subprocess.Popen(['zip', '-r', '-9', base_name, '.'], 176 subprocess.Popen(['zip', '-r', '-9', base_name, '.'],
177 stdout=subprocess.PIPE).communicate()[0] 177 stdout=subprocess.PIPE).communicate()[0]
178 except OSError, e: 178 except OSError, e:
179 logging.error('Execution failed:%s', e.strerror) 179 logging.error('Execution failed:%s', e.strerror)
180 return False 180 return False
181 finally: 181 finally:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 Returns: 216 Returns:
217 True on Success False on Failure 217 True on Success False on Failure
218 """ 218 """
219 if not os.path.isfile(zip_file_name): 219 if not os.path.isfile(zip_file_name):
220 logging.error("Zip file %s doesn't exist. Returning False", zip_file_name) 220 logging.error("Zip file %s doesn't exist. Returning False", zip_file_name)
221 return False 221 return False
222 222
223 if not os.path.isdir(output_dir): 223 if not os.path.isdir(output_dir):
224 logging.debug('Creating %s', output_dir) 224 logging.debug('Creating %s', output_dir)
225 os.makedirs(output_dir) 225 os.makedirs(output_dir)
226 logging.info('Copying %s to %s', zip_file_name, output_dir) 226 logging.debug('Copying %s to %s', zip_file_name, output_dir)
227 shutil.copy2(zip_file_name, output_dir) 227 shutil.copy2(zip_file_name, output_dir)
228 return True 228 return True
229 229
230 230
231 def main(): 231 def main():
232 """Main function to start the script""" 232 """Main function to start the script"""
233 parser = optparse.OptionParser() 233 parser = optparse.OptionParser()
234 234
235 parser.add_option( '-d', '--debug', dest='debug', action='store_true', 235 parser.add_option( '-d', '--debug', dest='debug', action='store_true',
236 default=False, help='Verbose Default: False',) 236 default=False, help='Verbose Default: False',)
(...skipping 11 matching lines...) Expand all
248 248
249 logging.debug('Options are %s ', options) 249 logging.debug('Options are %s ', options)
250 250
251 temp_dir = CreateTempDir() 251 temp_dir = CreateTempDir()
252 dest_files_root = os.path.join(temp_dir, 'au-generator') 252 dest_files_root = os.path.join(temp_dir, 'au-generator')
253 os.makedirs(dest_files_root) 253 os.makedirs(dest_files_root)
254 CopyRequiredFiles(dest_files_root=dest_files_root) 254 CopyRequiredFiles(dest_files_root=dest_files_root)
255 zip_file_name = os.path.join(temp_dir, options.zip_name) 255 zip_file_name = os.path.join(temp_dir, options.zip_name)
256 GenerateZipFile(zip_file_name, dest_files_root) 256 GenerateZipFile(zip_file_name, dest_files_root)
257 CopyZipToFinalDestination(options.output_dir, zip_file_name) 257 CopyZipToFinalDestination(options.output_dir, zip_file_name)
258 logging.info('Generated %s/%s' % (options.output_dir, options.zip_name))
258 259
259 if not options.keep_temp: 260 if not options.keep_temp:
260 CleanUp(temp_dir) 261 CleanUp(temp_dir)
261 262
262 if __name__ == '__main__': 263 if __name__ == '__main__':
263 main() 264 main()
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 408576698