Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 8585:aaf3988bd1b4
made 'mx archive' clean up temporary files upon failure during archive file creation
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 29 Mar 2013 12:22:27 +0100 |
parents | 67f19ede4891 |
children | c7672a325faf |
comparison
equal
deleted
inserted
replaced
8572:c324983e5d28 | 8585:aaf3988bd1b4 |
---|---|
1657 if name.startswith('@'): | 1657 if name.startswith('@'): |
1658 dname = name[1:] | 1658 dname = name[1:] |
1659 d = distribution(dname) | 1659 d = distribution(dname) |
1660 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) | 1660 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) |
1661 services = tempfile.mkdtemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) | 1661 services = tempfile.mkdtemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) |
1662 zf = zipfile.ZipFile(tmp, 'w') | 1662 try: |
1663 for p in sorted_deps(d.deps): | 1663 zf = zipfile.ZipFile(tmp, 'w') |
1664 outputDir = p.output_dir() | 1664 for p in sorted_deps(d.deps): |
1665 for root, _, files in os.walk(outputDir): | 1665 outputDir = p.output_dir() |
1666 relpath = root[len(outputDir) + 1:] | 1666 for root, _, files in os.walk(outputDir): |
1667 if relpath == join('META-INF', 'services'): | 1667 relpath = root[len(outputDir) + 1:] |
1668 for f in files: | 1668 if relpath == join('META-INF', 'services'): |
1669 with open(join(services, f), 'a') as outfile: | 1669 for f in files: |
1670 with open(join(root, f), 'r') as infile: | 1670 with open(join(services, f), 'a') as outfile: |
1671 for line in infile: | 1671 with open(join(root, f), 'r') as infile: |
1672 outfile.write(line) | 1672 for line in infile: |
1673 else: | 1673 outfile.write(line) |
1674 for f in files: | 1674 else: |
1675 arcname = join(relpath, f).replace(os.sep, '/') | 1675 for f in files: |
1676 zf.write(join(root, f), arcname) | 1676 arcname = join(relpath, f).replace(os.sep, '/') |
1677 for f in os.listdir(services): | 1677 zf.write(join(root, f), arcname) |
1678 arcname = join('META-INF', 'services', f).replace(os.sep, '/') | 1678 for f in os.listdir(services): |
1679 zf.write(join(services, f), arcname) | 1679 arcname = join('META-INF', 'services', f).replace(os.sep, '/') |
1680 zf.close() | 1680 zf.write(join(services, f), arcname) |
1681 os.close(fd) | 1681 zf.close() |
1682 shutil.rmtree(services) | 1682 os.close(fd) |
1683 # Atomic on Unix | 1683 shutil.rmtree(services) |
1684 shutil.move(tmp, d.path) | 1684 # Atomic on Unix |
1685 #print time.time(), 'move:', tmp, '->', d.path | 1685 shutil.move(tmp, d.path) |
1686 d.notify_updated() | 1686 #print time.time(), 'move:', tmp, '->', d.path |
1687 d.notify_updated() | |
1688 finally: | |
1689 if exists(tmp): | |
1690 os.remove(tmp) | |
1691 if exists(services): | |
1692 shutil.rmtree(services) | |
1687 | 1693 |
1688 else: | 1694 else: |
1689 p = project(name) | 1695 p = project(name) |
1690 outputDir = p.output_dir() | 1696 outputDir = p.output_dir() |
1691 fd, tmp = tempfile.mkstemp(suffix='', prefix=p.name, dir=p.dir) | 1697 fd, tmp = tempfile.mkstemp(suffix='', prefix=p.name, dir=p.dir) |
1692 zf = zipfile.ZipFile(tmp, 'w') | 1698 try: |
1693 for root, _, files in os.walk(outputDir): | 1699 zf = zipfile.ZipFile(tmp, 'w') |
1694 for f in files: | 1700 for root, _, files in os.walk(outputDir): |
1695 relpath = root[len(outputDir) + 1:] | 1701 for f in files: |
1696 arcname = join(relpath, f).replace(os.sep, '/') | 1702 relpath = root[len(outputDir) + 1:] |
1697 zf.write(join(root, f), arcname) | 1703 arcname = join(relpath, f).replace(os.sep, '/') |
1698 zf.close() | 1704 zf.write(join(root, f), arcname) |
1699 os.close(fd) | 1705 zf.close() |
1700 # Atomic on Unix | 1706 os.close(fd) |
1701 shutil.move(tmp, join(p.dir, p.name + '.jar')) | 1707 # Atomic on Unix |
1708 shutil.move(tmp, join(p.dir, p.name + '.jar')) | |
1709 finally: | |
1710 if exists(tmp): | |
1711 os.remove(tmp) | |
1702 | 1712 |
1703 def canonicalizeprojects(args): | 1713 def canonicalizeprojects(args): |
1704 """process all project files to canonicalize the dependencies | 1714 """process all project files to canonicalize the dependencies |
1705 | 1715 |
1706 The exit code of this command reflects how many files were updated.""" | 1716 The exit code of this command reflects how many files were updated.""" |