From c10ac61ee410b4f10a96202b65f53b69418e2700 Mon Sep 17 00:00:00 2001 From: Mike O'Connor Date: Wed, 21 Jan 2009 17:30:20 -0500 Subject: [PATCH] get rid of popen2 calls in generate_index_diffs Signed-off-by: Mike O'Connor --- dak/generate_index_diffs.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/dak/generate_index_diffs.py b/dak/generate_index_diffs.py index 286c1eba..a58abdc5 100755 --- a/dak/generate_index_diffs.py +++ b/dak/generate_index_diffs.py @@ -32,6 +32,7 @@ import sys, os, tempfile import apt_pkg +import bz2, gzip, time from daklib import utils ################################################################################ @@ -82,9 +83,9 @@ def smartopen(file): if os.path.isfile(file): f = open(file, "r") elif os.path.isfile("%s.gz" % file): - f = create_temp_file(os.popen("zcat %s.gz" % file, "r")) + f = decompressors[ 'zcat' ]( file ) elif os.path.isfile("%s.bz2" % file): - f = create_temp_file(os.popen("bzcat %s.bz2" % file, "r")) + f = decompressors[ 'bzcat' ]( file ) else: f = None return f @@ -173,17 +174,8 @@ class Updates: for h in l: out.write(" %s %7d %s\n" % (hs[h][1][0], hs[h][1][1], h)) -def create_temp_file(r): - f = tempfile.TemporaryFile() - while 1: - x = r.readline() - if not x: break - f.write(x) - r.close() - del x,r - f.flush() - f.seek(0) - return f +decompressors = { 'zcat' : gzip.GzipFile, + 'bzip2' : bz2.BZ2File } def sizesha1(f): size = os.fstat(f.fileno())[6] @@ -306,10 +298,7 @@ def main(): if not Options.has_key("PatchName"): format = "%Y-%m-%d-%H%M.%S" - i,o = os.popen2("date +%s" % (format)) - i.close() - Options["PatchName"] = o.readline()[:-1] - o.close() + Options["PatchName"] = time.strftime( format ) AptCnf = apt_pkg.newConfiguration() apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file()) -- 2.39.5