From dc580be8f9ef38a1c0903820b04e1b5c7217da16 Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Tue, 3 Apr 2018 06:50:04 +0200 Subject: Various improvements in coding style. --- minidinstall/misc.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'minidinstall/misc.py') 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 +# Copyright (c) 2004 Thomas Viehmann # 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() -- cgit v1.2.3