diff options
Diffstat (limited to 'minidinstall/misc.py')
| -rw-r--r-- | minidinstall/misc.py | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/minidinstall/misc.py b/minidinstall/misc.py index 372c450..5f7fb71 100644 --- a/minidinstall/misc.py +++ b/minidinstall/misc.py @@ -2,7 +2,7 @@ # misc tools for mini-dinstall -# Copyright © 2004 Thomas Viehmann <tv@beamnet.de> +# Copyright (c) 2004 Thomas Viehmann <tv@beamnet.de> # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -18,26 +18,25 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -import os, errno, time, string, re, hashlib +import os, errno, time, re, hashlib -def dup2(fd,fd2): +def dup2(fd, fd2): # dup2 with EBUSY retries (cf. dup2(2) and Debian bug #265513) - success = 0 + success = False tries = 0 - while (not success): + while not success: try: - os.dup2(fd,fd2) - success = 1 + os.dup2(fd, fd2) + success = True except OSError as e: - if (e.errno != errno.EBUSY) or (tries >= 3): + if e.errno != errno.EBUSY or tries >= 3: raise - # wait 0-2 seconds befor next try + # wait 0-2 seconds before next try time.sleep(tries) tries += 1 def format_changes(L): """ remove changelog header and all lines with only a dot """ - dotmatch = re.compile('^\.$') L1 = [] @@ -48,16 +47,11 @@ def format_changes(L): def get_file_sum(self, type, filename): """ generate hash sums for file """ - if type == 'md5': - sum = hashlib.md5() - elif type == 'sha1': - sum = hashlib.sha1() - elif type == 'sha256': - sum = hashlib.sha256() + sum = getattr(hashlib, type)() self._logger.debug("Generate %s (python-internal) for %s" % (type, filename)) - f = open(filename,'rb') + f = open(filename, 'rb') buf = f.read(8192) - while buf != '': + while buf: sum.update(buf) buf = f.read(8192) return sum.hexdigest() |
