From patchwork Wed Sep 11 09:22:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: kim.hansen@prevas.dk X-Patchwork-Id: 274206 X-Patchwork-Delegate: esben@haabendal.dk Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hugin.dotsrc.org (hugin.dotsrc.org [IPv6:2001:878:346::102]) by ozlabs.org (Postfix) with ESMTP id DCF302C0119 for ; Wed, 11 Sep 2013 19:23:15 +1000 (EST) Received: from hugin.dotsrc.org (localhost [127.0.0.1]) by hugin.dotsrc.org (Postfix) with ESMTP id 6ADFB3F877 for ; Wed, 11 Sep 2013 11:23:12 +0200 (CEST) X-Original-To: dev@oe-lite.org Delivered-To: dev@oe-lite.org Received: from mail02.prevas.se (mail02.prevas.se [62.95.78.10]) by hugin.dotsrc.org (Postfix) with ESMTPS id 357373F877 for ; Wed, 11 Sep 2013 11:23:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=8682; q=dns/txt; s=ironport2; t=1378891390; x=1410427390; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=eI/OWrVeBll1MM6yhdUgBwF9vZeZNSAAPfVGaatMUBM=; b=ZA55GIA2d/CwiWilsluf9k0R3q9UBheRpa3VIyENhOGiFacWhckCp+Qc 44e35GE2kVCJaG9Yo814VbkWvtkQtZ9ulcEu9hvB1pbGGAm7QU4ZWTJMw IVIR7TxSx5G7PXXetVkp9HtaPaMRztUygEODXm9ojenWmdILHxtOtgpth 8=; X-IronPort-AV: E=Sophos;i="4.90,883,1371074400"; d="scan'208";a="3563261" Received: from vmprevas3.prevas.se (HELO smtp.prevas.se) ([172.16.8.103]) by ironport2.prevas.se with ESMTP/TLS/AES128-SHA; 11 Sep 2013 11:23:09 +0200 Received: from arh146.prevas.dk (172.16.11.6) by smtp.prevas.se (172.16.8.105) with Microsoft SMTP Server (TLS) id 14.2.347.0; Wed, 11 Sep 2013 11:23:09 +0200 Received: by arh146.prevas.dk (Postfix, from userid 1000) id 853B52741530; Wed, 11 Sep 2013 11:22:51 +0200 (CEST) From: To: Subject: [core] add hostprep command Date: Wed, 11 Sep 2013 11:22:50 +0200 Message-ID: <1378891370-25037-1-git-send-email-kim.hansen@prevas.dk> X-Mailer: git-send-email 1.8.4 MIME-Version: 1.0 X-Originating-IP: [172.16.11.6] X-BeenThere: dev@oe-lite.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: OE-lite development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dev-bounces@oe-lite.org Errors-To: dev-bounces@oe-lite.org From: Kim Højgaard-Hansen The hostprep command can show what command is needed to prepare the host for OE-lite. A file for each supported host configuration must be added to th supported-host-configs directory. The file should contain the command needed to install the dependencies needed for using oe-lite. The file name should be: distro_release_codename as defined by lsb-release. The lsb-release file/tool is used for automatic host detection. A list of the supported host configurations can be shown by passing -l to the hostprep command. If only the command for the host should be shown, run 'hostprep -c' --- lib/oelite/cmd/__init__.py | 2 +- lib/oelite/cmd/hostprep.py | 130 +++++++++++++++++++++ .../cmd/supported-host-configs/exherbo_none_none | 1 + .../supported-host-configs/ubuntu_12.04_precise | 7 ++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 lib/oelite/cmd/hostprep.py create mode 100644 lib/oelite/cmd/supported-host-configs/exherbo_none_none create mode 100644 lib/oelite/cmd/supported-host-configs/ubuntu_12.04_precise diff --git a/lib/oelite/cmd/__init__.py b/lib/oelite/cmd/__init__.py index d2feabe..6919262 100644 --- a/lib/oelite/cmd/__init__.py +++ b/lib/oelite/cmd/__init__.py @@ -1 +1 @@ -manifest_cmds = [ "bake", "show", "cherry" ] +manifest_cmds = [ "bake", "hostprep","show", "cherry" ] diff --git a/lib/oelite/cmd/hostprep.py b/lib/oelite/cmd/hostprep.py new file mode 100644 index 0000000..1ed08be --- /dev/null +++ b/lib/oelite/cmd/hostprep.py @@ -0,0 +1,130 @@ +import oebakery +import logging +import os +import subprocess + +description = "Host preparation tool" +arguments = () + +def add_parser_options(parser): + parser.add_option("-c", "--command", + action="store_true", default=False, + help="Show the command needed to prepare the host for OE-lite") + parser.add_option("-l", "--list-supported-host-configs", + action="store_true", default=False, + help="Show a list of known host configurations") + parser.add_option("-s", "--select-host-config", + action="store_true", default=False, + help="Manually select a host configuration") + parser.add_option("-d", "--debug", + action="store_true", default=False, + help="Debug the OE-lite metadata") + return + + +def parse_args(options, args): + if options.debug: + logging.getLogger().setLevel(logging.DEBUG) + else: + logging.getLogger().setLevel(logging.INFO) + if args: + options.head = args.pop(0) + else: + options.head = None + return + +def get_supported_host_configs(): + logging.debug("Reading supported host configurations") + #TODO: fix path handling, find place to put host configs + hid = 0 + hc=[] + config_dir = "./meta/core/lib/oelite/cmd/supported-host-configs" + logging.debug("Using config directory: %s", config_dir) + for config in os.listdir(config_dir): + logging.debug("Reading config: %s", config) + keys = config.split('_') + if(len(keys) != 3): + logging.debug("Ignoring host-config with wrong name: %s", config) + continue + #read out the cmd to run for this host configuration + try: + logging.debug("Read the host preparation command") + #strip off the last newline + cmd = open(config_dir+"/"+config, 'r').read()[:-1] + except: + logging.debug("Reading the host preparation command from the host configuration file failed") + raise + hc.append(dict(distro=keys[0], release=keys[1], codename=keys[2], hostID=hid, command=cmd)) + hid+=1 + logging.debug("Adding host config for unknown host") + hc.append(dict(distro="unknown", release="none", codename="none", hostID=hid, command="Unknown host - Please refer to the installation documentation")) + return hc + +def determine_host(host_configs): + logging.debug("Running host detection") + logging.debug("Searching for lsb_release information") + #try lsb-release which is the most widely available method + if(os.path.exists("/etc/lsb-release") and os.path.isfile("/etc/lsb-release")): + try: + logging.debug("checking for the lsb_release binary") + subprocess.call(["lsb_release"]) + except OSError as e: + if e.errno == os.errno.ENOENT: + # handle file not found error. + logging.debug("/etc/lsb-release found, but lsb_release binary not available") + return (host for host in host_configs if host["distro"] == "unknown").next() + else: + logging.debug("unhandled exception when calling lsb_release") + raise + else: + try: + logging.debug("using lsb_release to get host information") + #strip newlines and make lowercase for later matching + distro = subprocess.check_output(["lsb_release", "-si"])[:-1].lower() + release = subprocess.check_output(["lsb_release", "-sr"])[:-1].lower() + codename = subprocess.check_output(["lsb_release", "-sc"])[:-1].lower() + except: + logging.debug("unhandled exception when calling lsb_release") + raise + else: + logging.debug("matching lsb_release information to supported configs") + logging.debug("lsb_release: distro: %s | release: %s | codename: %s", distro, release, codename) + for host in host_configs: + if((distro == host["distro"]) and (release == host["release"]) and (codename == host["codename"])): + logging.debug("found matching host config with ID: %d", host["hostID"]) + return host + logging.debug("No lsb_release information found") + logging.debug("Checking for Exherbo") + if(os.path.exists("/etc/exherbo-release") and os.path.isfile("/etc/exherbo-release")): + return (host for host in host_configs if host["distro"] == "exherbo").next() + logging.debug("No host config found for this host") + return (host for host in host_configs if host["distro"] == "unknown").next() + +def print_host_config(host): + print '{0:8}{1:15}{2:9}{3:15}{4:9}{5:15}{6:22}{7:2}'.format("Distro:", host["distro"], "Release:", host["release"], "Codename", host["codename"], "Host Configuration ID:", host["hostID"]) + +def run(options, args, config): + logging.debug("hostprep.run %s", options) + + hc = get_supported_host_configs() + + if(options.list_supported_host_configs): + print "List of supported host configurations:\n" + for host in hc: + print_host_config(host) + return 0 + + #try automatic host detection + host = determine_host(hc) + if(options.command): + logging.debug("printing command for hostID: %d", host["hostID"]) + logging.debug("Command: '%s'", host["command"]) + print host["command"] + return 0 + print "Your host configuration detected to be:\n" + print_host_config(host) + print + print "Run this command on your host to prepare it for OE-lite:\n" + print host["command"] + + return 0 diff --git a/lib/oelite/cmd/supported-host-configs/exherbo_none_none b/lib/oelite/cmd/supported-host-configs/exherbo_none_none new file mode 100644 index 0000000..2161776 --- /dev/null +++ b/lib/oelite/cmd/supported-host-configs/exherbo_none_none @@ -0,0 +1 @@ +sudo cave resolve oe-bakery diff --git a/lib/oelite/cmd/supported-host-configs/ubuntu_12.04_precise b/lib/oelite/cmd/supported-host-configs/ubuntu_12.04_precise new file mode 100644 index 0000000..98c533c --- /dev/null +++ b/lib/oelite/cmd/supported-host-configs/ubuntu_12.04_precise @@ -0,0 +1,7 @@ +sudo apt-get install python python-support python-magic python-ply \ +python-pycurl python-pysqlite2 python-pkg-resources python-dev \ +coreutils sed git-core cvs subversion mercurial quilt gawk texinfo \ +automake autoconf autopoint libtool curl texi2html diffstat \ +openjade groff mtd-utils build-essential make gcc g++ binutils \ +bison flex bc ncurses-dev unzip lzma gtk-doc-tools docbook-utils \ +libxml2-utils xmlto help2man libglib2.0-dev lzop gperf python-svn