From patchwork Thu Sep 12 07:02:34 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: 274445 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 0E0602C039D for ; Thu, 12 Sep 2013 17:03:21 +1000 (EST) Received: from hugin.dotsrc.org (localhost [127.0.0.1]) by hugin.dotsrc.org (Postfix) with ESMTP id A3C853F88F for ; Thu, 12 Sep 2013 09:03:19 +0200 (CEST) X-Original-To: dev@oe-lite.org Delivered-To: dev@oe-lite.org Received: from mail01.prevas.se (mail01.prevas.se [62.95.78.3]) by hugin.dotsrc.org (Postfix) with ESMTPS id 0A8D03F88F for ; Thu, 12 Sep 2013 09:03:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=9958; q=dns/txt; s=ironport1; t=1378969398; x=1410505398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9W6WCTXXNnsrpJgxg5q947LtQpaq7W1mGNmjBE/e6So=; b=QVdk06COKIn1fmHaSRp7N6XgpgJTEKdpiXO+pSoGM7amsuhlIjUT+njy D/zEHcxiwHYEnq/H6K//ljVB8buVTcEBOS+YInJr4T0GCbN5HkMRatu1n hjhfv8eh/JYE73lhvL4IMc8JaSmv5U7YW6K7KDXaSw8DusxdRjJQGsRod c=; X-IronPort-AV: E=Sophos;i="4.90,889,1371074400"; d="scan'208";a="3840057" Received: from vmprevas3.prevas.se (HELO smtp.prevas.se) ([172.16.8.103]) by ironport1.prevas.se with ESMTP/TLS/AES128-SHA; 12 Sep 2013 09:03:17 +0200 Received: from arh146.prevas.dk (172.16.11.8) by smtp.prevas.se (172.16.8.105) with Microsoft SMTP Server (TLS) id 14.2.347.0; Thu, 12 Sep 2013 09:03:17 +0200 Received: by arh146.prevas.dk (Postfix, from userid 1000) id 33D3D2741530; Thu, 12 Sep 2013 09:02:58 +0200 (CEST) From: To: Subject: [core] add oe hostprep command Date: Thu, 12 Sep 2013 09:02:34 +0200 Message-ID: <1378969354-28800-1-git-send-email-kim.hansen@prevas.dk> X-Mailer: git-send-email 1.8.4 In-Reply-To: <[core] add hostprep command> References: <[core] add hostprep command> MIME-Version: 1.0 X-Originating-IP: [172.16.11.8] 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 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 preparation command for the current host should be shown, run 'hostprep -c' --- lib/oelite/cmd/__init__.py | 2 +- lib/oelite/cmd/hostprep.py | 132 +++++++++++++++++++++ .../cmd/supported-host-configs/centos_6.4_final | 13 ++ .../cmd/supported-host-configs/exherbo_none_none | 1 + .../supported-host-configs/ubuntu_12.04_precise | 7 ++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 lib/oelite/cmd/hostprep.py create mode 100644 lib/oelite/cmd/supported-host-configs/centos_6.4_final 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..ae82fd8 --- /dev/null +++ b/lib/oelite/cmd/hostprep.py @@ -0,0 +1,132 @@ +import oebakery +from oelite import util +import logging +import os +import subprocess +import oelite + +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 = oelite.util.shcmd("lsb_release -si", quiet=True)[:-1].lower() + release = oelite.util.shcmd("lsb_release -sr", quiet=True)[:-1].lower() + codename = oelite.util.shcmd("lsb_release -sc", quiet=True)[:-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("Could not match information from lsb_release to any known host config") + 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:10}{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/centos_6.4_final b/lib/oelite/cmd/supported-host-configs/centos_6.4_final new file mode 100644 index 0000000..2da269f --- /dev/null +++ b/lib/oelite/cmd/supported-host-configs/centos_6.4_final @@ -0,0 +1,13 @@ +wget http://mirrors.nl.eu.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm \ +&& sudo yum install epel-release-6-8.noarch.rpm \ +&& sudo yum install git python-ply python-setuptools \ +&& wget -qO- http://oe-lite.org/download/bakery/oe-lite-bakery-4.0.2.tar.gz \ + | tar -xz && cd oe-lite-bakery-4.0.2 && sudo python setup.py install \ +&& sudo yum groupinstall "Development Tools" \ +&& sudo yum install python-sqlite2 python-magic python-pycurl python-devel \ +fakeroot gettext-devel ncurses-devel libtool texinfo flex bison \ +coreutils sed git-core cvs subversion mercurial quilt gawk texinfo \ +automake autoconf curl openjade groff make gcc-c++ gcc binutils bc \ +unzip gtk-doc docbook-utils xmlto glib2-devel intltool glibc-static \ +gperf + 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