From 8e242f8bdd6070af4c21d2e54475e539b6a53ad8 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Fri, 18 Apr 2014 12:01:02 +0800 Subject: [PATCH] Make imagedata save function more generic When save image config and ks to one directory, it should not limit the directory to the repo directory. The directory hierarchy, like 'buiddata' should be handled by high module. Change-Id: Iabe8b1b4970d24449ee6734f2e9d53393d01b2a8 Signed-off-by: Lin Yang --- common/imagedata.py | 18 ++++++++---------- tests/test_imagedata.py | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/common/imagedata.py b/common/imagedata.py index d3a1fa6..3347101 100644 --- a/common/imagedata.py +++ b/common/imagedata.py @@ -87,25 +87,23 @@ class ImageData(object): return content - def save(self, path_to_repo, hreadable=True): + def save(self, path, hreadable=True): """ Save image data to xml file and save ks files to image-configuration dir """ - if not os.path.isdir(os.path.join(path_to_repo, - 'builddata', + if not os.path.isdir(os.path.join(path, 'image-configurations')): - os.makedirs(os.path.join(path_to_repo, - 'builddata', - 'image-configurations')) + os.makedirs(os.path.join(path, + 'image-configurations')) # Write content down - with open(os.path.join(path_to_repo, - 'builddata/images.xml'), 'w') as out: + with open(os.path.join(path, + 'images.xml'), 'w') as out: out.write(self.to_xml(hreadable)) for ksname, kscontent in self.ksi.items(): - with open(os.path.join(path_to_repo, - 'builddata/image-configurations', + with open(os.path.join(path, + 'image-configurations', ksname), 'w') as out: out.write(kscontent) diff --git a/tests/test_imagedata.py b/tests/test_imagedata.py index be6b77b..dcdbde8 100644 --- a/tests/test_imagedata.py +++ b/tests/test_imagedata.py @@ -87,6 +87,6 @@ class ImageDataTest(unittest.TestCase): fname = 'test_save.tmp' saved.save(fname) loaded = ImageData() - loaded.load(open(os.path.join(fname, 'builddata/images.xml')).read()) + loaded.load(open(os.path.join(fname, 'images.xml')).read()) self.assertEqual(saved.images, loaded.images) shutil.rmtree(fname) -- 2.7.4