diff options
author | Guido van Rossum <guido@python.org> | 1998-08-25 14:06:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-08-25 14:06:55 (GMT) |
commit | baf0603493f6f1eee073a479497291785b067f61 (patch) | |
tree | 7b9b04abcd5d890d1d76d6cd81984b1a0f55ee11 /Tools/freeze/bkfile.py | |
parent | 6c74fea07d42ac6bc3bc078fb13f903f6cdbbcb9 (diff) | |
download | cpython-baf0603493f6f1eee073a479497291785b067f61.zip cpython-baf0603493f6f1eee073a479497291785b067f61.tar.gz cpython-baf0603493f6f1eee073a479497291785b067f61.tar.bz2 |
New version, with contributions from Sjoerd Mullender and Mark Hammond.
Sjoerd writes:
This version of freeze creates one file per Python module, instead of
one humongous file for all Python modules.
bkfile: new module to used to write files with backups. No new file
is produced if the new contents is identical to the old.
New option "-x excluded-module" for modulefinder test program.
New option "-i filename" for freeze main program to include a list of
options in place of the -i option.
Diffstat (limited to 'Tools/freeze/bkfile.py')
-rw-r--r-- | Tools/freeze/bkfile.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Tools/freeze/bkfile.py b/Tools/freeze/bkfile.py new file mode 100644 index 0000000..6d0ccde --- /dev/null +++ b/Tools/freeze/bkfile.py @@ -0,0 +1,50 @@ +_orig_open = open + +class _BkFile: + def __init__(self, file, mode, bufsize): + import os + self.__filename = file + self.__backup = file + '~' + try: + os.unlink(self.__backup) + except os.error: + pass + try: + os.rename(file, self.__backup) + except os.error: + self.__backup = None + self.__file = _orig_open(file, mode, bufsize) + self.closed = self.__file.closed + self.fileno = self.__file.fileno + self.flush = self.__file.flush + self.isatty = self.__file.isatty + self.mode = self.__file.mode + self.name = self.__file.name + self.read = self.__file.read + self.readinto = self.__file.readinto + self.readline = self.__file.readline + self.readlines = self.__file.readlines + self.seek = self.__file.seek + self.softspace = self.__file.softspace + self.tell = self.__file.tell + self.truncate = self.__file.truncate + self.write = self.__file.write + self.writelines = self.__file.writelines + + def close(self): + self.__file.close() + if self.__backup is None: + return + import cmp + # don't use cmp.cmp because of NFS bugs :-( and + # anyway, the stat mtime values differ so do_cmp will + # most likely be called anyway + if cmp.do_cmp(self.__backup, self.__filename): + import os + os.unlink(self.__filename) + os.rename(self.__backup, self.__filename) + +def open(file, mode = 'r', bufsize = -1): + if 'w' not in mode: + return _orig_open(file, mode, bufsize) + return _BkFile(file, mode, bufsize) |