Timezone setting change
[platform/upstream/mic.git] / mic / kickstart / __init__.py
old mode 100644 (file)
new mode 100755 (executable)
index 6594436..76cc525
@@ -20,6 +20,7 @@ import os, sys, re
 import shutil
 import subprocess
 import string
+import collections
 
 import pykickstart.sections as kssections
 import pykickstart.commands as kscommands
@@ -32,7 +33,8 @@ from pykickstart.handlers.control import dataMap
 
 from mic import msger
 from mic.utils import errors, misc, runner, fs_related as fs
-from custom_commands import desktop, micrepo, micboot, partition
+from custom_commands import desktop, micrepo, micboot, partition, installerfw
+from mic.utils.safeurl import SafeURL
 
 
 AUTH_URL_PTN = r"(?P<scheme>.*)://(?P<username>.*)(:?P<password>.*)?@(?P<url>.*)"
@@ -101,6 +103,7 @@ def read_kickstart(path):
     commandMap[using_version]["bootloader"] = micboot.Mic_Bootloader
     commandMap[using_version]["part"] = partition.Mic_Partition
     commandMap[using_version]["partition"] = partition.Mic_Partition
+    commandMap[using_version]["installerfw_plugins"] = installerfw.Mic_installerfw
     dataMap[using_version]["RepoData"] = micrepo.Mic_RepoData
     dataMap[using_version]["PartData"] = partition.Mic_PartData
     superclass = ksversion.returnClassForVersion(version=using_version)
@@ -160,6 +163,16 @@ class LanguageConfig(KickstartConfig):
             f.write("LANG=\"" + kslang.lang + "\"\n")
             f.close()
 
+            f = open(self.path("/etc/locale.conf"), "w+")
+            f.write("LANG=\"" + kslang.lang + "\"\n")
+            f.close()
+
+            #cp ks lang setting to other file, then can access the file in %post section
+            fs.makedirs(self.path("/etc/config"))
+            f = open(self.path("/etc/config/mic_language"), "w+")
+            f.write("LANG=\"" + kslang.lang + "\"\n")
+            f.close()
+
 class KeyboardConfig(KickstartConfig):
     """A class to apply a kickstart keyboard configuration to a system."""
     @apply_wrapper
@@ -187,16 +200,23 @@ class TimezoneConfig(KickstartConfig):
         f.write("ZONE=\"" + tz + "\"\n")
         f.write("UTC=" + utc + "\n")
         f.close()
+        if not os.path.exists("/opt/etc"):
+            fs.makedirs("/opt/etc")
         tz_source = "/usr/share/zoneinfo/%s" % (tz)
+        tz_midst = "/opt/etc/localtime"
         tz_dest = "/etc/localtime"
         try:
-            cpcmd = fs.find_binary_inchroot('cp', self.instroot)
-            if cpcmd:
-                self.call([cpcmd, "-f", tz_source, tz_dest])
+            lncmd = fs.find_binary_inchroot('ln', self.instroot)
+            if lncmd:
+                self.call([lncmd, "-s", tz_source, tz_midst])
+                self.call([lncmd, "-s", tz_midst, tz_dest])
             else:
-                cpcmd = fs.find_binary_path('cp')
-                subprocess.call([cpcmd, "-f",
+                lncmd = fs.find_binary_path('ln')
+                subprocess.call([lncmd, "-s",
                                  self.path(tz_source),
+                                 self.path(tz_midst)])
+                subprocess.call([lncmd, "-s",
+                                 self.path(tz_midst),
                                  self.path(tz_dest)])
         except (IOError, OSError), (errno, msg):
             raise errors.KsError("Timezone setting error: %s" % msg)
@@ -315,10 +335,7 @@ class UserConfig(KickstartConfig):
     @apply_wrapper
     def apply(self, user):
         for userconfig in user.userList:
-            try:
-                self.addUser(userconfig)
-            except:
-                raise
+            self.addUser(userconfig)
 
 class ServicesConfig(KickstartConfig):
     """A class to apply a kickstart services configuration to a system."""
@@ -639,6 +656,15 @@ class NetworkConfig(KickstartConfig):
         self.write_hosts(hostname)
         self.write_resolv(nodns, nameservers)
 
+def use_installerfw(ks, feature):
+    """ Check if the installer framework has to be used for a feature
+    "feature". """
+
+    features = ks.handler.installerfw.features
+    if features:
+        if feature in features or "all" in features:
+            return True
+    return False
 
 def get_image_size(ks, default = None):
     __size = 0
@@ -705,61 +731,47 @@ def get_default_kernel(ks, default = None):
         return default
     return ks.handler.bootloader.default
 
-def get_repos(ks, repo_urls=None):
+RepoType = collections.namedtuple("Repo",
+               "name, baseurl, mirrorlist, includepkgs, excludepkgs, proxy, \
+               proxy_username, proxy_password, debuginfo, \
+               source, gpgkey, disable, ssl_verify, nocache, \
+               cost, priority")
+
+def Repo(name, baseurl, mirrorlist=None, includepkgs=[], excludepkgs=[], proxy=None,
+         proxy_username=None, proxy_password=None, debuginfo=None,
+         source=None, gpgkey=None, disable=None, ssl_verify=None,
+         nocache=False, cost=None, priority=None):
+    return RepoType(name, baseurl, mirrorlist, includepkgs, excludepkgs, proxy,
+                    proxy_username, proxy_password, debuginfo,
+                    source, gpgkey, disable, ssl_verify, nocache,
+                    cost, priority)
+
+
+def get_repos(ks, repo_urls=None, ignore_ksrepo=False):
     repos = {}
-    for repo in ks.handler.repo.repoList:
-        inc = []
-        if hasattr(repo, "includepkgs"):
-            inc.extend(repo.includepkgs)
-
-        exc = []
-        if hasattr(repo, "excludepkgs"):
-            exc.extend(repo.excludepkgs)
-
-        baseurl = repo.baseurl
-        mirrorlist = repo.mirrorlist
-
-        if repo_urls and repo.name in repo_urls:
-            baseurl = repo_urls[repo.name]
-            mirrorlist = None
-
-        if repos.has_key(repo.name):
-            msger.warning("Overriding already specified repo %s" %(repo.name,))
-
-        proxy = None
-        if hasattr(repo, "proxy"):
-            proxy = repo.proxy
-        proxy_username = None
-        if hasattr(repo, "proxy_username"):
-            proxy_username = repo.proxy_username
-        proxy_password = None
-        if hasattr(repo, "proxy_password"):
-            proxy_password = repo.proxy_password
-        if hasattr(repo, "debuginfo"):
-            debuginfo = repo.debuginfo
-        if hasattr(repo, "source"):
-            source = repo.source
-        if hasattr(repo, "gpgkey"):
-            gpgkey = repo.gpgkey
-        if hasattr(repo, "disable"):
-            disable = repo.disable
-        ssl_verify = True
-        if hasattr(repo, "ssl_verify"):
-            ssl_verify = repo.ssl_verify == "yes"
-        nocache = False
-        if hasattr(repo, "nocache"):
-            nocache = repo.nocache
-        cost = None
-        if hasattr(repo, "cost"):
-            cost = repo.cost
-        priority = None
-        if hasattr(repo, "priority"):
-            priority = repo.priority
-
-        repos[repo.name] = (repo.name, baseurl, mirrorlist, inc, exc,
-                            proxy, proxy_username, proxy_password, debuginfo,
-                            source, gpgkey, disable, ssl_verify, nocache,
-                            cost, priority)
+    for repodata in ks.handler.repo.repoList:
+        repo = {}
+        for field in RepoType._fields:
+            if hasattr(repodata, field) and getattr(repodata, field):
+                repo[field] = getattr(repodata, field)
+
+        if hasattr(repodata, 'baseurl') and getattr(repodata, 'baseurl'):
+            repo['baseurl'] = SafeURL(getattr(repodata, 'baseurl'),
+                                      getattr(repodata, 'user', None),
+                                      getattr(repodata, 'passwd', None))
+
+        if 'name' in repo:
+            repos[repo['name']] = Repo(**repo)
+
+    if repo_urls:
+        if ignore_ksrepo:
+            repos = {}
+        for name, repo in repo_urls.items():
+            if 'baseurl' in repo:
+                repo['baseurl'] = SafeURL(repo.get('baseurl'),
+                                          repo.get('user', None),
+                                          repo.get('passwd', None))
+            repos[name] = Repo(**repo)
 
     return repos.values()
 
@@ -808,6 +820,13 @@ def get_post_scripts(ks):
         scripts.append(s)
     return scripts
 
+def get_sign_scripts(ks):
+    scripts = []
+    for s in ks.handler.scripts:
+        if s.type != ksparser.KS_SCRIPT_RUN:
+            continue
+        scripts.append(s)
+    return scripts
 def add_repo(ks, repostr):
     args = repostr.split()
     repoobj = ks.handler.repo.parse(args[1:])