initial import code into git
[platform/upstream/mic.git] / micng / utils / kscommands / desktop.py
1 #!/usr/bin/python -tt
2 #
3 # Yi Yang <yi.y.yang@intel.com>
4 #
5 # Copyright 2008, 2009, 2010 Intel, Inc.
6 #
7 # This copyrighted material is made available to anyone wishing to use, modify,
8 # copy, or redistribute it subject to the terms and conditions of the GNU
9 # General Public License v.2.  This program is distributed in the hope that it
10 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
11 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
17 # trademarks that are incorporated in the source code or documentation are not
18 # subject to the GNU General Public License and may only be used or replicated
19 # with the express permission of Red Hat, Inc.
20 #
21 from pykickstart.base import *
22 from pykickstart.errors import *
23 from pykickstart.options import *
24
25 class Moblin_Desktop(KickstartCommand):
26     def __init__(self, writePriority=0, defaultdesktop=None, defaultdm=None, autologinuser="meego", session="/usr/bin/mutter --sm-disable"):
27         KickstartCommand.__init__(self, writePriority)
28
29         self.__new_version = False
30         self.op = self._getParser()
31
32         self.defaultdesktop = defaultdesktop
33         self.autologinuser = autologinuser
34         self.defaultdm = defaultdm
35         self.session = session
36
37     def __str__(self):
38         retval = ""
39
40         if self.defaultdesktop != None:
41             retval += " --defaultdesktop=%s" % self.defaultdesktop
42         if self.session != None:
43             retval += " --session=\"%s\"" % self.session
44         if self.autologinuser != None:
45             retval += " --autologinuser=%s" % self.autologinuser
46         if self.defaultdm != None:
47             retval += " --defaultdm=%s" % self.defaultdm
48
49         if retval != "":
50             retval = "# Default Desktop Settings\ndesktop %s\n" % retval
51
52         return retval
53
54     def _getParser(self):
55         try:
56             op = KSOptionParser(lineno=self.lineno)
57         except TypeError:
58             # the latest version has not lineno argument
59             op = KSOptionParser()
60             self.__new_version = True
61
62         op.add_option("--defaultdesktop", dest="defaultdesktop", action="store", type="string", nargs=1)
63         op.add_option("--autologinuser", dest="autologinuser", action="store", type="string", nargs=1)
64         op.add_option("--defaultdm", dest="defaultdm", action="store", type="string", nargs=1)
65         op.add_option("--session", dest="session", action="store", type="string", nargs=1)
66         return op
67
68     def parse(self, args):
69         if self.__new_version:
70             (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
71         else:
72             (opts, extra) = self.op.parse_args(args=args)
73
74         if extra:
75             mapping = {"command": "desktop", "options": extra}
76             raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping)
77
78         self._setToSelf(self.op, opts)