From eed55a6afd9e322cc5ddb55559c86b2b954a911b Mon Sep 17 00:00:00 2001 From: JF Ding Date: Fri, 17 Feb 2012 22:22:48 +0800 Subject: [PATCH] development after 0.6 release using the 0.7git version and unified style and comments for recent patches --- VERSION | 2 +- distfiles/mic.conf | 2 ++ distfiles/mic.spec | 2 +- distfiles/mic.yaml | 2 +- mic/conf.py | 11 ++++++----- mic/utils/misc.py | 19 ++++++++++++------- tools/mic | 12 ++++++++---- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/VERSION b/VERSION index 5a2a580..b183568 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6 +0.7git diff --git a/distfiles/mic.conf b/distfiles/mic.conf index 7b8d702..cbad959 100644 --- a/distfiles/mic.conf +++ b/distfiles/mic.conf @@ -13,8 +13,10 @@ pkgmgr = zypp ; proxy = http://proxy.yourcompany.com:8080/ ; no_proxy = localhost,127.0.0.0/8,.yourcompany.com + # Prefix that is added in front of files that are produced. ; name_prefix = output + ; ssl_verify = no [convert] diff --git a/distfiles/mic.spec b/distfiles/mic.spec index d9fd526..6880be6 100644 --- a/distfiles/mic.spec +++ b/distfiles/mic.spec @@ -8,7 +8,7 @@ %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} Name: mic Summary: Image Creator for Linux Distributions -Version: 0.6 +Version: 0.7 Release: 1 Group: System/Base License: GPLv2 diff --git a/distfiles/mic.yaml b/distfiles/mic.yaml index c504a2c..12628b4 100644 --- a/distfiles/mic.yaml +++ b/distfiles/mic.yaml @@ -1,6 +1,6 @@ Name: mic Summary: Image Creator for Linux Distributions -Version: 0.6 +Version: 0.7 Release: 1 Group: System/Base License: GPLv2 diff --git a/mic/conf.py b/mic/conf.py index 40dea22..b199483 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -132,17 +132,18 @@ class ConfigMgr(object): if section != "common" and not section.startswith('bootstrap'): getattr(self, section).update(self.common) + # check and normalize the scheme of proxy url if self.create['proxy']: - urlptn = re.compile('://') - m = urlptn.search(self.create['proxy']) + m = re.match('^(\w+)://.*', self.create['proxy']) if m: - scheme = self.create['proxy'].split(':')[0] + scheme = m.group(1) if scheme not in ('http', 'https', 'ftp', 'socks'): msger.error("%s: proxy scheme is incorrect" % siteconf) else: - msger.warning("%s: proxy set without scheme, use http default" + msger.warning("%s: proxy url w/o scheme, use http as default" % siteconf) - self.create['proxy'] = "http://%s" % self.create['proxy'] + self.create['proxy'] = "http://" + self.create['proxy'] + proxy.set_proxies(self.create['proxy'], self.create['no_proxy']) for section in parser.sections(): diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 9bec55b..de38a3d 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -54,7 +54,9 @@ RPM_FMT = "%(name)s.%(arch)s %(ver_rel)s" SRPM_RE = re.compile("(.*)-(\d+.*)-(\d+\.\d+).src.rpm") def human_size(size): - # make Bytes size readable by human + """Return human readable string for Bytes size + """ + import math measure = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] expo = int(math.log(size, 1024)) @@ -62,12 +64,15 @@ def human_size(size): return "{0:.1f}{1:s}".format(mant, measure[expo]) def check_space_pre_cp(src, dst): - # check whether space is enough before 'cp' - srcsize = get_file_size(src) * 1024 * 1024 - dstsize = get_filesystem_avail(dst) - if srcsize > dstsize: - raise CreatorError("Space on %s (%s) is not enough than needed (%s)" - % (dst, human_size(dstsize), human_size(srcsize))) + """Check whether disk space is enough before 'cp' like + operations, else exception will be raised. + """ + + srcsize = get_file_size(src) * 1024 * 1024 + freesize = get_filesystem_avail(dst) + if srcsize > freesize: + raise CreatorError("space on %s(%s) is not enough for about %s files" + % (dst, human_size(freesize), human_size(srcsize))) def get_md5sum(fpath): blksize = 65536 # should be optimized enough diff --git a/tools/mic b/tools/mic index 4d5ee3f..4070357 100755 --- a/tools/mic +++ b/tools/mic @@ -131,14 +131,18 @@ class MicCmd(cmdln.Cmdln): if (srcimager and destimager) is None: raise errors.CreatorError("Can't convert from %s to %s" \ % (srcformat, destformat)) + else: - maptab = {"livecd": "iso", - "liveusb": "usbimg", - "loop": "img" + maptab = { + "livecd": "iso", + "liveusb": "usbimg", + "loop": "img", } - if destformat in maptab.keys(): + + if destformat in maptab: imgname = os.path.splitext(os.path.basename(srcimg))[0] dstname = "{0}.{1}".format(imgname, maptab[destformat]) + if os.path.exists(dstname): if msger.ask("Converted image %s seems existed, " "remove and continue?" % dstname): -- 2.7.4