commit a1ae398d2ad421357066363cf865636cf811a2e7
Author: Yi Yang <[email protected]>
Date:   Mon Dec 13 14:39:50 2010 +0800

    Allow to read all the options from config file
    
    Note: in mic2 config file, key name isn't different from
    option name for some options, here is a table for reference:
    
        cachedir                --cache
        tmpdir                  --tmpdir
        outdir                  --outdir
        format                  --format
        default_ks              --default-ks
        use_comps               --use-comps
        run_mode                --run-mode
        save_kernel             --save-kernel
        traceback               --traceback
        logfile                 --logfile
        verbose                 --verbose
        debug                   --debug
        bootimg_only            --bootimg-only
        kernel_rpm_path         --kernel-rpm-path
        kernel_rpm_url          --kernel-rpm-url
        kernel_path             --kernel-path
        kernel_url              --kernel-url
        initrd_path             --initrd-path
        initrd_url              --initrd-url
        overlay_size_mb         --overlay-size-mb
        fstype                  --fstype
        interactive             --interactive
        include_src             --include-source
        compress_disk_image     --compress-disk-image
        package                 --package
        local_pkgs_path         --local-pkgs-path
        record_pkgs             --record-pkgs
        alt_initrd_name         --alt-initrd-name
        arch                    --arch
        bootstrap               --bootstrap
        ignore_siteconf         --ignore-siteconf
        mainrepo                --mainrepo
        buildbootstrap          --build-bootstrap
        suffix                  --suffix
        prefix                  --prefix
        genchecksum             --genchecksum
        release                 --release
        config                  --config
        give_shell              --shell
        skip_minimize           --skip-minimize
        skip_compression        --skip-compression

diff --git a/tools/mic-image-creator b/tools/mic-image-creator
index ca32abb..67fd914 100755
--- a/tools/mic-image-creator
+++ b/tools/mic-image-creator
@@ -237,13 +237,6 @@ def parse_options(args):
     if logging.getLogger().level in (logging.DEBUG, logging.INFO, 
logging.WARN) or options.traceback:
         debugger.set_debug_level(1)
 
-    # kickstart file isn't necessary any more
-    if options.config and not os.path.isfile(options.config):
-        raise FatalError("kickstart config '%s' does'not exist" % 
options.config)
-
-    if options.record_pkgs is not None and options.record_pkgs not in ('name', 
'content'):
-        raise FatalError("Please specify what to be recorded: \"name\", 
\"content\"")
-
     return options
 
 
@@ -295,6 +288,33 @@ def get_siteconf_opt(siteconf, section, option):
 
     return None
 
+def get_options_from_siteconf(siteconf, options):
+    ignore_siteconf = get_siteconf_opt(siteconf, "main", "ignore_siteconf")
+    if ignore_siteconf != "0":
+        return
+    optlist = options.__dict__
+    for key in optlist.keys():
+        value = getattr(options, key)
+        if key == "run_mode" and value == -1:
+            """ If run_mode == -1, we should read it from siteconf """
+            value = None
+        if value == None or (type(value) is bool and value == False) or value 
== "":
+            value = get_siteconf_opt(siteconf, "main", key)
+            if key in ("run_mode", "overlay_size_mb"):
+                if value.isdigit():
+                    setattr(options, key, int(value))
+                continue
+            if key in ("compress_disk_image"):
+                """ none is also valid value for it """
+                setattr(options, key, value)
+                continue
+            if value in (None, "0", "none"):
+                continue
+            elif value == "1":
+                setattr(options, key, True)
+            else:
+                setattr(options, key, value)
+
 def rebuild_argv(argv, options, logfile = None):
     blacklist = ["bootstrap", "buildbootstrap", "mainrepo", "repo", 
"default_ks", "siteconf", "prefix", "ignore_siteconf", "run_mode"]
     changed_opts = {"overlaysizemb":"overlay-size-mb", "cachedir":"cache", 
"give_shell":"shell",
@@ -348,27 +368,32 @@ def main():
         imgcreate.misc.output_siteconf(siteconf)
     else:
         siteconf = None
+
+    """ Get global config from site config, but command line option has high 
priority, it will override settings from site config """
+    if not options.ignore_siteconf:
+        get_options_from_siteconf(siteconf, options)
+
+    if options.run_mode  == -1:
+        options.run_mode = 0
+    if options.run_mode not in (0, 1):
+        raise FatalError("Error: invalid run mode %d" % options.run_mode)
+
+    # kickstart file isn't necessary any more
+    if options.config and not os.path.isfile(options.config):
+        raise FatalError("kickstart config '%s' does'not exist" % 
options.config)
+
+    if options.record_pkgs is not None and options.record_pkgs not in ('name', 
'content'):
+        raise FatalError("Please specify what to be recorded: \"name\", 
\"content\"")
+
     imgcreate.get_local_distro()
 
-    if not options.pkgmgr:
-        options.pkgmgr = get_siteconf_opt(siteconf, "main", "pkgmgr")
     distro_name = get_siteconf_opt(siteconf, "main", "distro_name")
     if not distro_name:
         distro_name = "MeeGo"
 
     if imgcreate.is_meego_bootstrap("/") or (options.arch and 
options.arch.strip().startswith("arm")):
-       """ Obviously don't need bootstrap for MeeGo and bootstrap """
-       options.run_mode = 0
-    elif options.run_mode  == -1:
-        run_mode = get_siteconf_opt(siteconf, "main", "run_mode")
-        if not run_mode:
-            run_mode = "0"
-        if run_mode not in ("0", "1"):
-            raise FatalError("Error: invalid run mode %s" % run_mode)
-        else:
-            options.run_mode = int(run_mode)
-    if options.run_mode not in (0, 1):
-        raise FatalError("Error: invalid run mode %d" % options.run_mode)
+        """ Obviously don't need bootstrap for MeeGo and bootstrap """
+        options.run_mode = 0
 
     if options.run_mode == 1:
         if not options.buildbootstrap and not options.bootstrap:
@@ -406,8 +431,6 @@ def main():
     else:
         print "Run mode: legacy"
 
-    if not options.format:
-        options.format = get_siteconf_opt(siteconf, "main", "image_format")
     if options.format not in (imgcreate.supported_formats + 
appcreate.supported_formats):
         raise FatalError("Image format '%s' isn't supported. Supported 
formats: %s " % (options.format, ", ".join(imgcreate.supported_formats + 
appcreate.supported_formats)))
 
@@ -418,37 +441,24 @@ def main():
         print "WARNING: Image format 'nand' will be deprecated soon, and 
format 'mrstnand' is preferred."
         options.format = 'mrstnand'
 
-    """ Get global config from site config, but command line option has high 
priority, it will override settings from site config """
     if not options.tmpdir:
-        value = get_siteconf_diropt(siteconf, "tmpdir")
-        if value:
-            options.tmpdir = value
-        else:
-            options.tmpdir = "/var/tmp"
+        options.tmpdir = "/var/tmp"
 
     options.tmpdir = os.path.abspath(os.path.expanduser(options.tmpdir))
 
     print "Using %s as tmpdir." % (options.tmpdir)
 
     if not options.cachedir:
-        value = get_siteconf_diropt(siteconf, "cachedir")
-        if value:
-            options.cachedir = value
-        else:
-            """ If no cache dir is found from configs lets create dir to users 
home as default. """
-            options.cachedir = "~/.mic2_cachedir"
+        """ If no cache dir is found from configs lets create dir to users 
home as default. """
+        options.cachedir = "~/.mic2_cachedir"
 
     options.cachedir = os.path.abspath(os.path.expanduser(options.cachedir))
 
     print "Using %s as cache directory." % (options.cachedir)
 
     if not options.outdir:
-        value = get_siteconf_diropt(siteconf, "outdir")
-        if value:
-            options.outdir = value
-        else:
-            """ If no outdir is defined then we default to the current 
directory. """
-            options.outdir = "."
+        """ If no outdir is defined then we default to the current directory. 
"""
+        options.outdir = "."
 
     if options.release and options.config:
         fd = open(options.config, "r")
@@ -564,12 +574,6 @@ def main():
 
 
     # Parse patterns if exists
-    if not options.use_comps:
-        options.use_comps = get_siteconf_opt(siteconf, "main", "use_comps")
-        if options.use_comps != "1":
-            options.use_comps = False
-        else:
-            options.use_comps = True
     imgcreate.kickstart.support_patterns(ks, repometadata, options.use_comps)
 
     for siterepo in site_repos:
@@ -846,7 +850,6 @@ def main():
     finally:
         creator.cleanup()
 
-
     if options.format == "liveusb" and options.interactive:
         mypath = os.path.abspath(sys.argv[0])
         mypath = os.path.dirname(mypath)
_______________________________________________
MeeGo-distribution-tools mailing list
[email protected]
http://lists.meego.com/listinfo/meego-distribution-tools

Reply via email to