Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 14626:4f8268dee8aa
mx: eclipseformat now prints all the changes that were found to the console.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 20 Mar 2014 00:15:49 +0100 |
parents | 6fb61ad67962 |
children | 65b005b58825 |
comparison
equal
deleted
inserted
replaced
14619:ed3bfe43d772 | 14626:4f8268dee8aa |
---|---|
38 import socket | 38 import socket |
39 import hashlib | 39 import hashlib |
40 import xml.parsers.expat | 40 import xml.parsers.expat |
41 import shutil, re, xml.dom.minidom | 41 import shutil, re, xml.dom.minidom |
42 import pipes | 42 import pipes |
43 import difflib | |
43 from collections import Callable | 44 from collections import Callable |
44 from threading import Thread | 45 from threading import Thread |
45 from argparse import ArgumentParser, REMAINDER | 46 from argparse import ArgumentParser, REMAINDER |
46 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile | 47 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile |
47 | 48 |
1928 | 1929 |
1929 def update(self): | 1930 def update(self): |
1930 with open(self.path) as fp: | 1931 with open(self.path) as fp: |
1931 content = fp.read() | 1932 content = fp.read() |
1932 if self.content != content: | 1933 if self.content != content: |
1934 self.diff = difflib.unified_diff(self.content.splitlines(1), content.splitlines(1)) | |
1933 self.content = content | 1935 self.content = content |
1934 return True | 1936 return True |
1935 os.utime(self.path, self.times) | 1937 os.utime(self.path, self.times) |
1936 | 1938 |
1937 modified = list() | 1939 modified = list() |
1965 for fi in batch.javafiles: | 1967 for fi in batch.javafiles: |
1966 if fi.update(): | 1968 if fi.update(): |
1967 modified.append(fi) | 1969 modified.append(fi) |
1968 | 1970 |
1969 log('{0} files were modified'.format(len(modified))) | 1971 log('{0} files were modified'.format(len(modified))) |
1972 | |
1970 if len(modified) != 0: | 1973 if len(modified) != 0: |
1971 arcbase = _primary_suite.dir | 1974 arcbase = _primary_suite.dir |
1972 if args.backup: | 1975 if args.backup: |
1973 backup = os.path.abspath('eclipseformat.backup.zip') | 1976 backup = os.path.abspath('eclipseformat.backup.zip') |
1974 zf = zipfile.ZipFile(backup, 'w', zipfile.ZIP_DEFLATED) | 1977 zf = zipfile.ZipFile(backup, 'w', zipfile.ZIP_DEFLATED) |
1975 for fi in modified: | 1978 for fi in modified: |
1976 name = os.path.relpath(fi.path, arcbase) | 1979 name = os.path.relpath(fi.path, arcbase) |
1977 log(' - {0}'.format(name)) | 1980 log(' - {0}'.format(name)) |
1981 log('Changes:') | |
1982 log(''.join(fi.diff)) | |
1978 if args.backup: | 1983 if args.backup: |
1979 arcname = name.replace(os.sep, '/') | 1984 arcname = name.replace(os.sep, '/') |
1980 zf.writestr(arcname, fi.content) | 1985 zf.writestr(arcname, fi.content) |
1981 if args.backup: | 1986 if args.backup: |
1982 zf.close() | 1987 zf.close() |