From 34195b0a3ae00d28e808df93a3b8d39cf3a2f430 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 11 Apr 2013 20:46:33 +0300 Subject: [PATCH] tools: refactoring Signed-off-by: Markus Lehtonen --- tools/updateinfo/create-update.py | 4 ++-- tools/updateinfo/updateutils.py | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/updateinfo/create-update.py b/tools/updateinfo/create-update.py index 2d19197..e63862a 100755 --- a/tools/updateinfo/create-update.py +++ b/tools/updateinfo/create-update.py @@ -102,8 +102,8 @@ else: shutil.rmtree(os.path.join(filepath)) # Get packages -p1 = get_package_list(opts.image, release_url, opts.old, credentials, target_dir, packages_files_dir) -p2 = get_package_list(opts.image, release_url, opts.new, credentials, target_dir, packages_files_dir) +p1 = get_package_list(release_url, opts.old, opts.image, credentials, target_dir, packages_files_dir) +p2 = get_package_list(release_url, opts.new, opts.image, credentials, target_dir, packages_files_dir) pkgs1 = {'%s|%s' % (pkg, attr['arch']) for pkg, attr in p1.iteritems()} pkgs2 = {'%s|%s' % (pkg, attr['arch']) for pkg, attr in p2.iteritems()} diff --git a/tools/updateinfo/updateutils.py b/tools/updateinfo/updateutils.py index 9642d6f..13ecb89 100755 --- a/tools/updateinfo/updateutils.py +++ b/tools/updateinfo/updateutils.py @@ -36,16 +36,13 @@ def download(url, fname, credentials, outdir, cachedir): if not os.path.exists(dest_file): shutil.copy2(cached_file, dest_file) -def get_package_list(image_name, base_url, build_id, credentials, outdir, cachedir): - cache_file = "%s/%s-%s.packages" %(cachedir, image_name, build_id ) - package_file = None +def get_package_list(base_url, build_id, image_name, credentials, out_dir, cache_dir): + cache_file = "%s/%s-%s.packages" % (cache_dir, image_name, build_id) if not os.path.exists(cache_file): image_packages = "%s/%s/images/%s/%s-%s.packages" %(base_url, build_id, image_name, image_name, build_id ) - #print image_packages package_file = http_get(image_packages, credentials) - cache = open(cache_file, "w") - cache.write(package_file.read()) - cache.close() + with open(cache_file, "w") as cache: + cache.write(package_file.read()) with open(cache_file, "rb") as package_file: packages = {} pkgreader = csv.reader(package_file, delimiter=' ', quotechar='|') @@ -55,7 +52,7 @@ def get_package_list(image_name, base_url, build_id, credentials, outdir, cached packages[pkg[0]] = {'scm': row[2], 'version': row[1], 'arch': pkg[1]} else: packages[pkg[0]] = {'scm': None, 'version': row[1], 'arch': pkg[1]} - shutil.copy2(cache_file, os.path.join(outdir, "packages")) + shutil.copy2(cache_file, os.path.join(out_dir, "packages")) return packages -- 2.7.4