[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 359: Merging in fetch_image.py

Message ID 20110706141822.7642.25332.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

James Tunnicliffe July 6, 2011, 2:18 p.m.
Merge authors:
  James Tunnicliffe (dooferlad)
Related merge proposals:
  https://code.launchpad.net/~dooferlad/linaro-image-tools/fetch_image_cli/+merge/64710
  proposed by: James Tunnicliffe (dooferlad)
  review: Approve - James Westby (james-w)
------------------------------------------------------------
revno: 359 [merge]
committer: James Tunnicliffe <james.tunnicliffe@linaro.org>
branch nick: linaro-image-tools
timestamp: Fri 2011-06-17 19:15:35 +0100
message:
  Merging in fetch_image.py
  
  This is a command line client that will download the required files from release.linaro.org and snapshots.linaro.org to build a specified OS image for your hardware, for example:
  
  fetch_image.py -w panda -a linaro-n -i nano -b final -p panda -t ~/Desktop/panda.bin
  
  This will create a nano image for a panda board based on the final linaro-n release from release.linaro.org and place it on the users desktop.
added:
  fetch_image.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription

Patch

=== added file 'fetch_image.py'
--- fetch_image.py	1970-01-01 00:00:00 +0000
+++ fetch_image.py	2011-06-17 13:10:22 +0000
@@ -0,0 +1,79 @@ 
+#!/usr/bin/env python
+# Copyright (C) 2010, 2011 Linaro
+#
+# Author: James Tunnicliffe <james.tunnicliffe@linaro.org>
+#
+# This file is part of Linaro Image Tools.
+#
+# Linaro Image Tools is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# Linaro Image Tools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Linaro Image Tools; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+# USA.
+
+import sys
+import os
+import linaro_image_tools.FetchImage as FetchImage
+import logging
+
+
+def main():
+    file_handler = FetchImage.FileHandler()
+    config = FetchImage.FetchImageConfig()
+
+    # Unfortunately we need to do a bit of a hack here and look for some
+    # options before performing a full options parse.
+    clean_cache = ("--clean-cache" in sys.argv[1:]
+                   or "-x" in sys.argv[1:])
+
+    force_download = ("--force-download" in sys.argv[1:]
+                      or "-d" in sys.argv[1:])
+
+    if clean_cache:
+        file_handler.clean_cache()
+
+    # If the settings file and server index need updating, grab them
+    file_handler.update_files_from_server(force_download)
+
+    # Load settings YAML, which defines the parameters we ask for and
+    # acceptable responses from the user
+    config.read_config(file_handler.settings_file)
+
+    # Using the settings that the YAML defines as what we need for a build,
+    # generate a command line parser and parse the command line
+    config.parse_args(sys.argv[1:])
+
+    if config.args['platform'] == "snapshot":
+        config.args['release_or_snapshot'] = "snapshot"
+    else:
+        config.args['release_or_snapshot'] = "release"
+
+    # Using the config we have, look up URLs to download data from in the
+    # server index
+    db = FetchImage.DB(file_handler.index_file)
+
+    image_url, hwpack_url = db.get_image_and_hwpack_urls(config.args)
+
+    if(image_url and hwpack_url):
+
+        tools_dir = os.path.dirname(__file__)
+        if tools_dir == '':
+            tools_dir = None
+
+        file_handler.create_media(image_url, hwpack_url,
+                                  config.args, tools_dir)
+    else:
+        logging.error(
+            "Unable to find files that match the parameters specified")
+
+if __name__ == '__main__':
+    main()