Patchwork [2/2] wic: Check for external modules

login
register
mail settings
Submitter Darren Hart
Date Oct. 15, 2013, 9:46 p.m.
Message ID <2752ed00149228af88202212aacdc0d209e3bb39.1381869082.git.dvhart@linux.intel.com>
Download mbox | patch
Permalink /patch/59955/
State Accepted
Commit b11bfadba20c1f39a63e396e605a8316c2ed2a94
Headers show

Comments

Darren Hart - Oct. 15, 2013, 9:46 p.m.
Since eight unique files import rpm, perform a check at the top level
for the existence of the rpm module print a sensible error message if it
is not. This may be able to be removed if some of the core rpm
dependencies are removed from the mic libs.

Also check for urlgrabber.

This avoids a bracktrace in the event the modules are not installed
which can be very off-putting to would-be users.

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Cc: Tom Zanussi <tom.zanussi@intel.com>
---
 scripts/wic |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch

diff --git a/scripts/wic b/scripts/wic
index 06e72bb..f665823 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -31,11 +31,23 @@ 
 
 __version__ = "0.1.0"
 
+# Python Standard Library modules
 import os
 import sys
 import optparse
 import logging
 
+# External modules
+try:
+    import rpm
+    import urlgrabber
+except ImportError:
+    print("ERROR: failed to import necessary modules.")
+    print("Please ensure the following modules are installed:")
+    print("\trpm");
+    print("\turlgrabber");
+    sys.exit(1)
+
 scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
 lib_path = scripts_path + '/lib'
 sys.path = sys.path + [lib_path]