X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=0d83b3418f54d61bd65704b2761b02fc85350a88;hb=71349e8d397cfb3e21ffb9fd9340fd9fda8b25a0;hp=a50a840f22b573dc08fd6710109d443de91dd41a;hpb=7132fa99d5e9754b353c58ecd69efac9b1ff86b9;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py index a50a840f..0d83b341 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -398,25 +398,24 @@ def parse_checksums(where, files, manifest, hashname): field = 'checksums-%s' % hashname if not field in manifest: return rejmsg - input = manifest[field] - for line in input.split('\n'): + for line in manifest[field].split('\n'): if not line: break - hash, size, file = line.strip().split(' ') - if not files.has_key(file): + checksum, size, checkfile = line.strip().split(' ') + if not files.has_key(checkfile): # TODO: check for the file's entry in the original files dict, not # the one modified by (auto)byhand and other weird stuff # rejmsg.append("%s: not present in files but in checksums-%s in %s" % # (file, hashname, where)) continue - if not files[file]["size"] == size: + if not files[checkfile]["size"] == size: rejmsg.append("%s: size differs for files and checksums-%s entry "\ - "in %s" % (file, hashname, where)) + "in %s" % (checkfile, hashname, where)) continue - files[file][hash_key(hashname)] = hash + files[checkfile][hash_key(hashname)] = checksum for f in files.keys(): if not files[f].has_key(hash_key(hashname)): - rejmsg.append("%s: no entry in checksums-%s in %s" % (file, + rejmsg.append("%s: no entry in checksums-%s in %s" % (checkfile, hashname, where)) return rejmsg @@ -570,8 +569,7 @@ switched to 'email (name)' format.""" def send_mail (message, filename=""): # If we've been passed a string dump it into a temporary file if message: - filename = tempfile.mktemp() - fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700) + (fd, filename) = tempfile.mkstemp() os.write (fd, message) os.close (fd) @@ -687,11 +685,11 @@ def regex_safe (s): # Perform a substition of template def TemplateSubst(map, filename): - file = open_file(filename) - template = file.read() + templatefile = open_file(filename) + template = templatefile.read() for x in map.keys(): template = template.replace(x,map[x]) - file.close() + templatefile.close() return template ################################################################################ @@ -787,13 +785,13 @@ def find_next_free (dest, too_many=100): ################################################################################ def result_join (original, sep = '\t'): - list = [] + resultlist = [] for i in xrange(len(original)): if original[i] == None: - list.append("") + resultlist.append("") else: - list.append(original[i]) - return sep.join(list) + resultlist.append(original[i]) + return sep.join(resultlist) ################################################################################ @@ -1360,26 +1358,16 @@ def clean_symlink (src, dest, root): ################################################################################ -def temp_filename(directory=None, dotprefix=None, perms=0700): +def temp_filename(directory=None, prefix="dak", suffix=""): """Return a secure and unique filename by pre-creating it. If 'directory' is non-null, it will be the directory the file is pre-created in. -If 'dotprefix' is non-null, the filename will be prefixed with a '.'.""" +If 'prefix' is non-null, the filename will be prefixed with it, default is dak. +If 'suffix' is non-null, the filename will end with it. - if directory: - old_tempdir = tempfile.tempdir - tempfile.tempdir = directory - - filename = tempfile.mktemp() - - if dotprefix: - filename = "%s/.%s" % (os.path.dirname(filename), os.path.basename(filename)) - fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, perms) - os.close(fd) - - if directory: - tempfile.tempdir = old_tempdir +Returns a pair (fd, name). +""" - return filename + return tempfile.mkstemp(suffix, prefix, directory) ################################################################################