Mercurial > hg > truffle
comparison mxtool/mx.py @ 15087:f3e74d317e83
mx: added exportlibs command
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 14 Apr 2014 15:38:19 +0200 |
parents | 858d2b91c1f8 |
children | 3a1f48125f53 |
comparison
equal
deleted
inserted
replaced
15086:22acaa9fb7f8 | 15087:f3e74d317e83 |
---|---|
34 """ | 34 """ |
35 | 35 |
36 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch | 36 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch |
37 import textwrap | 37 import textwrap |
38 import socket | 38 import socket |
39 import tarfile | |
39 import hashlib | 40 import hashlib |
40 import xml.parsers.expat | 41 import xml.parsers.expat |
41 import shutil, re, xml.dom.minidom | 42 import shutil, re, xml.dom.minidom |
42 import pipes | 43 import pipes |
43 import difflib | 44 import difflib |
4268 return [items[i] for i in indexes] | 4269 return [items[i] for i in indexes] |
4269 if len(indexes) == 1: | 4270 if len(indexes) == 1: |
4270 return items[indexes[0]] | 4271 return items[indexes[0]] |
4271 return None | 4272 return None |
4272 | 4273 |
4274 def exportlibs(args): | |
4275 """export libraries to an archive file""" | |
4276 | |
4277 parser = ArgumentParser(prog='exportlibs') | |
4278 parser.add_argument('-b', '--base', action='store', help='base name of archive (default: libs)', default='libs', metavar='<path>') | |
4279 parser.add_argument('--arc', action='store', choices=['tgz', 'tbz2', 'tar', 'zip'], default='tgz', help='the type of the archive to create') | |
4280 parser.add_argument('--no-sha1', action='store_false', dest='sha1', help='do not create SHA1 signature of archive') | |
4281 parser.add_argument('--no-md5', action='store_false', dest='md5', help='do not create MD5 signature of archive') | |
4282 parser.add_argument('--include-system-libs', action='store_true', help='include system libraries (i.e., those not downloaded from URLs)') | |
4283 parser.add_argument('extras', nargs=REMAINDER, help='extra files and directories to add to archive', metavar='files...') | |
4284 args = parser.parse_args(args) | |
4285 | |
4286 def createArchive(addMethod): | |
4287 entries = {} | |
4288 def add(path, arcname): | |
4289 apath = os.path.abspath(path) | |
4290 if not entries.has_key(arcname): | |
4291 entries[arcname] = apath | |
4292 logv('[adding ' + path + ']') | |
4293 addMethod(path, arcname=arcname) | |
4294 elif entries[arcname] != apath: | |
4295 logv('[warning: ' + apath + ' collides with ' + entries[arcname] + ' as ' + arcname + ']') | |
4296 else: | |
4297 logv('[already added ' + path + ']') | |
4298 | |
4299 for lib in _libs.itervalues(): | |
4300 if len(lib.urls) != 0 or args.include_system_libs: | |
4301 add(lib.get_path(resolve=True), lib.path) | |
4302 if args.extras: | |
4303 for e in args.extras: | |
4304 if os.path.isdir(e): | |
4305 for root, _, filenames in os.walk(e): | |
4306 for name in filenames: | |
4307 f = join(root, name) | |
4308 add(f, f) | |
4309 else: | |
4310 add(e, e) | |
4311 | |
4312 if args.arc == 'zip': | |
4313 path = args.base + '.zip' | |
4314 with zipfile.ZipFile(path, 'w') as zf: | |
4315 createArchive(zf.write) | |
4316 else: | |
4317 path = args.base + '.tar' | |
4318 mode = 'w' | |
4319 if args.arc != 'tar': | |
4320 sfx = args.arc[1:] | |
4321 mode = mode + ':' + sfx | |
4322 path = path + '.' + sfx | |
4323 with tarfile.open(path, mode) as tar: | |
4324 createArchive(tar.add) | |
4325 log('created ' + path) | |
4326 | |
4327 def digest(enabled, path, factory, suffix): | |
4328 if enabled: | |
4329 d = factory() | |
4330 with open(path, 'rb') as f: | |
4331 while True: | |
4332 buf = f.read(4096) | |
4333 if not buf: | |
4334 break | |
4335 d.update(buf) | |
4336 with open(path + '.' + suffix, 'w') as fp: | |
4337 fp.write(d.hexdigest()) | |
4338 log('created ' + path + '.' + suffix) | |
4339 | |
4340 digest(args.sha1, path, hashlib.sha1, 'sha1') | |
4341 digest(args.md5, path, hashlib.md5, 'md5') | |
4342 | |
4273 def javap(args): | 4343 def javap(args): |
4274 """disassemble classes matching given pattern with javap""" | 4344 """disassemble classes matching given pattern with javap""" |
4275 | 4345 |
4276 javapExe = java().javap | 4346 javapExe = java().javap |
4277 if not exists(javapExe): | 4347 if not exists(javapExe): |
4336 'checkstyle': [checkstyle, ''], | 4406 'checkstyle': [checkstyle, ''], |
4337 'canonicalizeprojects': [canonicalizeprojects, ''], | 4407 'canonicalizeprojects': [canonicalizeprojects, ''], |
4338 'clean': [clean, ''], | 4408 'clean': [clean, ''], |
4339 'eclipseinit': [eclipseinit, ''], | 4409 'eclipseinit': [eclipseinit, ''], |
4340 'eclipseformat': [eclipseformat, ''], | 4410 'eclipseformat': [eclipseformat, ''], |
4411 'exportlibs': [exportlibs, ''], | |
4341 'findclass': [findclass, ''], | 4412 'findclass': [findclass, ''], |
4342 'fsckprojects': [fsckprojects, ''], | 4413 'fsckprojects': [fsckprojects, ''], |
4343 'help': [help_, '[command]'], | 4414 'help': [help_, '[command]'], |
4344 'ideclean': [ideclean, ''], | 4415 'ideclean': [ideclean, ''], |
4345 'ideinit': [ideinit, ''], | 4416 'ideinit': [ideinit, ''], |