Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 # Takes in a Ubuntu Precise dpkg admin directory (typically /var/lib/dpkg) and | |
| 7 # outputs a dpkg admin directory appropriate for use with dpkg-shlibdeps on | |
| 8 # Ubuntu Trusty. | |
| 9 # | |
| 10 # Example usage: | |
| 11 # generate_precise_dpkg_admin_dir.py --arch i386 \ | |
| 12 # /path/to/precise_32-bit_chroot/var/lib/dpkg /path/to/dest_dir | |
| 13 | |
| 14 import optparse | |
| 15 import os | |
| 16 import shutil | |
| 17 import string | |
| 18 import sys | |
| 19 | |
| 20 | |
| 21 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 22 PACKAGES = [ | |
|
Paweł Hajdan Jr.
2014/12/08 10:12:15
Can we de-duplicate the list of packages between t
| |
| 23 "libasound2", | |
| 24 "libc6", | |
| 25 "libcairo2", | |
| 26 "libcups2", | |
| 27 "libdbus-1-3", | |
| 28 "libexpat1", | |
| 29 "libfontconfig1", | |
| 30 "libfreetype6", | |
| 31 "libgconf-2-4", | |
| 32 "libgdk-pixbuf2.0-0", | |
| 33 "libglib2.0-0", | |
| 34 "libgtk2.0-0", | |
| 35 "libnspr4", | |
| 36 "libnss3", | |
| 37 "libpango-1.0-0", | |
| 38 "libpangocairo-1.0-0", | |
| 39 "libstdc++6", | |
| 40 "libx11-6", | |
| 41 "libxcomposite1", | |
| 42 "libxcursor1", | |
| 43 "libxdamage1", | |
| 44 "libxext6", | |
| 45 "libxfixes3", | |
| 46 "libxi6", | |
| 47 "libxrandr2", | |
| 48 "libxrender1", | |
| 49 "libxss1", | |
| 50 "libxtst6", | |
| 51 ] | |
| 52 | |
| 53 | |
| 54 def ParseStatusFile(status_file): | |
| 55 package_map = {} | |
| 56 lines = open(status_file).readlines() | |
| 57 current_package_name = '' | |
| 58 current_package_data = '' | |
| 59 for line in lines: | |
| 60 if (not line or | |
| 61 line[0] not in string.ascii_uppercase or | |
| 62 line.startswith('Homepage: ') or | |
| 63 line.startswith('Original-Maintainer: ')): | |
| 64 continue | |
| 65 if line.startswith('Package: '): | |
| 66 if current_package_name: | |
| 67 package_map[current_package_name] = current_package_data | |
| 68 current_package_name = line[len('Package: '):].strip() | |
| 69 current_package_data = '' | |
| 70 # Hack for libpango1.0-0 vs libpango-1.0-0 | |
|
Paweł Hajdan Jr.
2014/12/08 10:12:15
Could you explain more why we need this hack? If p
| |
| 71 if current_package_name == 'libpango1.0-0': | |
| 72 current_package_name = 'libpango-1.0-0' | |
| 73 else: | |
| 74 current_package_data += line | |
| 75 | |
| 76 # Hack for libpangocairo-1.0-0 | |
|
Paweł Hajdan Jr.
2014/12/08 10:12:15
Same here, I'm really surprised we'd need this.
C
| |
| 77 if 'libpango-1.0-0' in package_map: | |
| 78 assert('libpangocairo-1.0-0' not in package_map) | |
| 79 package_map['libpangocairo-1.0-0'] = package_map['libpango-1.0-0'] | |
| 80 return package_map | |
| 81 | |
| 82 | |
| 83 def main(): | |
| 84 if options.arch not in ['amd64', 'i386']: | |
|
Paweł Hajdan Jr.
2014/12/08 10:12:15
At least argparse has built-in ways to validate th
| |
| 85 print 'Unknown architecture: %s' % options.arch | |
| 86 return 1 | |
| 87 | |
| 88 if len(args) != 2: | |
| 89 print 'Wrong number of arguments.' | |
| 90 return 1 | |
| 91 | |
| 92 src_dir = args[0] | |
| 93 dest_dir = args[1] | |
| 94 | |
| 95 src_status_file = os.path.join(src_dir, 'status') | |
| 96 src_info_dir = os.path.join(src_dir, 'info') | |
| 97 src_info_format_file = os.path.join(src_info_dir, 'format') | |
| 98 src_triggers_dir = os.path.join(src_dir, 'triggers') | |
| 99 src_updates_dir = os.path.join(src_dir, 'updates') | |
| 100 if not os.path.isfile(src_status_file): | |
| 101 print 'status file not found. (%s)' % src_status_file | |
| 102 return 1 | |
| 103 if not os.path.isdir(src_info_dir): | |
| 104 print 'info dir not found. (%s)' % src_info_dir | |
| 105 return 1 | |
| 106 if not os.path.isfile(src_info_format_file): | |
| 107 print 'info format file not found. (%s)' % src_info_format_file | |
| 108 return 1 | |
| 109 if not os.path.isdir(src_triggers_dir): | |
| 110 print 'triggers dir not found. (%s)' % src_triggers_dir | |
| 111 return 1 | |
| 112 if not os.path.isdir(src_updates_dir): | |
| 113 print 'updates dir not found. (%s)' % src_updates_dir | |
| 114 return 1 | |
| 115 | |
| 116 package_map = ParseStatusFile(src_status_file) | |
| 117 missing_packages = [] | |
| 118 for package in PACKAGES: | |
| 119 if package not in package_map: | |
| 120 missing_packages.append(package) | |
| 121 if missing_packages: | |
| 122 print 'Missing packages: %s' % ','.join(missing_packages) | |
| 123 return 1 | |
| 124 | |
| 125 dest_status_file = os.path.join(dest_dir, 'status') | |
| 126 dest_info_dir = os.path.join(dest_dir, 'info') | |
| 127 dest_info_format_file = os.path.join(dest_info_dir, 'format') | |
| 128 dest_triggers_dir = os.path.join(dest_dir, 'triggers') | |
| 129 dest_updates_dir = os.path.join(dest_dir, 'updates') | |
| 130 | |
| 131 os.makedirs(dest_info_dir) | |
| 132 shutil.copy(src_info_format_file, dest_info_format_file) | |
| 133 shutil.copytree(src_triggers_dir, dest_triggers_dir, | |
| 134 ignore=shutil.ignore_patterns('Lock')) | |
| 135 shutil.copytree(src_updates_dir, dest_updates_dir) | |
| 136 | |
| 137 dest_status_file_handle = open(dest_status_file, 'w') | |
| 138 for package in PACKAGES: | |
| 139 dest_status_file_handle.write('Package: %s\n' % package) | |
| 140 dest_status_file_handle.write(package_map[package]) | |
| 141 dest_status_file_handle.write('\n') | |
| 142 dest_status_file_handle.close() | |
|
Paweł Hajdan Jr.
2014/12/08 10:12:15
nit: Why not just "with open(...) as ..."?
| |
| 143 | |
| 144 for package in PACKAGES: | |
| 145 for extension in ('shlibs', 'symbols'): | |
| 146 dest_filename = '%s:%s.%s' % (package, options.arch, extension) | |
| 147 # Hack for libpango | |
| 148 if (package == 'libpango-1.0-0' or package == 'libpangocairo-1.0-0'): | |
| 149 src_filename = 'libpango1.0-0:%s.%s' % (options.arch, extension) | |
| 150 else: | |
| 151 src_filename = dest_filename | |
| 152 src_file = os.path.join(src_info_dir, src_filename) | |
| 153 dest_file = os.path.join(dest_info_dir, dest_filename) | |
| 154 if not os.path.isfile(src_file): | |
| 155 continue | |
| 156 shutil.copy(src_file, dest_file) | |
| 157 | |
| 158 return 0 | |
| 159 | |
| 160 | |
| 161 if __name__ == '__main__': | |
| 162 parser = optparse.OptionParser('usage: %prog --arch ARCH SRC DEST') | |
| 163 parser.add_option('--arch', help='Sysroot architecture: i386 or amd64') | |
| 164 options, args = parser.parse_args() | |
| 165 sys.exit(main()) | |
| OLD | NEW |