From 9fc88f96d40b17c90bac53b90045a87b2d2cff84 Mon Sep 17 00:00:00 2001 From: Tom Zanussi Date: Sat, 24 Aug 2013 15:31:34 +0000 Subject: wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi Signed-off-by: Saul Wold Signed-off-by: Richard Purdie --- scripts/lib/mic/utils/grabber.py | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 scripts/lib/mic/utils/grabber.py (limited to 'scripts/lib/mic/utils/grabber.py') diff --git a/scripts/lib/mic/utils/grabber.py b/scripts/lib/mic/utils/grabber.py new file mode 100644 index 0000000000..45e30b4fb0 --- /dev/null +++ b/scripts/lib/mic/utils/grabber.py @@ -0,0 +1,97 @@ +#!/usr/bin/python + +import os +import sys +import rpm +import fcntl +import struct +import termios + +from mic import msger +from mic.utils import runner +from mic.utils.errors import CreatorError + +from urlgrabber import grabber +from urlgrabber import __version__ as grabber_version + +if rpm.labelCompare(grabber_version.split('.'), '3.9.0'.split('.')) == -1: + msger.warning("Version of python-urlgrabber is %s, lower than '3.9.0', " + "you may encounter some network issues" % grabber_version) + +def myurlgrab(url, filename, proxies, progress_obj = None): + g = grabber.URLGrabber() + if progress_obj is None: + progress_obj = TextProgress() + + if url.startswith("file:/"): + filepath = "/%s" % url.replace("file:", "").lstrip('/') + if not os.path.exists(filepath): + raise CreatorError("URLGrabber error: can't find file %s" % url) + if url.endswith('.rpm'): + return filepath + else: + # untouch repometadata in source path + runner.show(['cp', '-f', filepath, filename]) + + else: + try: + filename = g.urlgrab(url=str(url), + filename=filename, + ssl_verify_host=False, + ssl_verify_peer=False, + proxies=proxies, + http_headers=(('Pragma', 'no-cache'),), + quote=0, + progress_obj=progress_obj) + except grabber.URLGrabError, err: + msg = str(err) + if msg.find(url) < 0: + msg += ' on %s' % url + raise CreatorError(msg) + + return filename + +def terminal_width(fd=1): + """ Get the real terminal width """ + try: + buf = 'abcdefgh' + buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, buf) + return struct.unpack('hhhh', buf)[1] + except: # IOError + return 80 + +def truncate_url(url, width): + return os.path.basename(url)[0:width] + +class TextProgress(object): + # make the class as singleton + _instance = None + def __new__(cls, *args, **kwargs): + if not cls._instance: + cls._instance = super(TextProgress, cls).__new__(cls, *args, **kwargs) + + return cls._instance + + def __init__(self, totalnum = None): + self.total = totalnum + self.counter = 1 + + def start(self, filename, url, *args, **kwargs): + self.url = url + self.termwidth = terminal_width() + msger.info("\r%-*s" % (self.termwidth, " ")) + if self.total is None: + msger.info("\rRetrieving %s ..." % truncate_url(self.url, self.termwidth - 15)) + else: + msger.info("\rRetrieving %s [%d/%d] ..." % (truncate_url(self.url, self.termwidth - 25), self.counter, self.total)) + + def update(self, *args): + pass + + def end(self, *args): + if self.counter == self.total: + msger.raw("\n") + + if self.total is not None: + self.counter += 1 + -- cgit v1.2.3-54-g00ecf