summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/3rdparty/pykickstart/commands/user.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-08-24 15:31:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch)
tree63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/3rdparty/pykickstart/commands/user.py
parent53a1d9a788fd9f970af980da2ab975cca60685c4 (diff)
downloadpoky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/user.py')
-rw-r--r--scripts/lib/mic/3rdparty/pykickstart/commands/user.py173
1 files changed, 173 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/user.py b/scripts/lib/mic/3rdparty/pykickstart/commands/user.py
new file mode 100644
index 0000000000..189dc7585f
--- /dev/null
+++ b/scripts/lib/mic/3rdparty/pykickstart/commands/user.py
@@ -0,0 +1,173 @@
1#
2# Chris Lumens <clumens@redhat.com>
3#
4# Copyright 2007 Red Hat, Inc.
5#
6# This copyrighted material is made available to anyone wishing to use, modify,
7# copy, or redistribute it subject to the terms and conditions of the GNU
8# General Public License v.2. This program is distributed in the hope that it
9# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11# See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# this program; if not, write to the Free Software Foundation, Inc., 51
15# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16# trademarks that are incorporated in the source code or documentation are not
17# subject to the GNU General Public License and may only be used or replicated
18# with the express permission of Red Hat, Inc.
19#
20from pykickstart.base import *
21from pykickstart.constants import *
22from pykickstart.errors import *
23from pykickstart.options import *
24
25import gettext
26import warnings
27_ = lambda x: gettext.ldgettext("pykickstart", x)
28
29class FC6_UserData(BaseData):
30 removedKeywords = BaseData.removedKeywords
31 removedAttrs = BaseData.removedAttrs
32
33 def __init__(self, *args, **kwargs):
34 BaseData.__init__(self, *args, **kwargs)
35 self.groups = kwargs.get("groups", [])
36 self.homedir = kwargs.get("homedir", "")
37 self.isCrypted = kwargs.get("isCrypted", False)
38 self.name = kwargs.get("name", "")
39 self.password = kwargs.get("password", "")
40 self.shell = kwargs.get("shell", "")
41 self.uid = kwargs.get("uid", None)
42
43 def __eq__(self, y):
44 return self.name == y.name
45
46 def __str__(self):
47 retval = BaseData.__str__(self)
48
49 if self.uid != "":
50 retval += "user"
51 retval += self._getArgsAsStr() + "\n"
52
53 return retval
54
55 def _getArgsAsStr(self):
56 retval = ""
57
58 if len(self.groups) > 0:
59 retval += " --groups=%s" % ",".join(self.groups)
60 if self.homedir:
61 retval += " --homedir=%s" % self.homedir
62 if self.name:
63 retval += " --name=%s" % self.name
64 if self.password:
65 retval += " --password=%s" % self.password
66 if self.isCrypted:
67 retval += " --iscrypted"
68 if self.shell:
69 retval += " --shell=%s" % self.shell
70 if self.uid:
71 retval += " --uid=%s" % self.uid
72
73 return retval
74
75class F8_UserData(FC6_UserData):
76 removedKeywords = FC6_UserData.removedKeywords
77 removedAttrs = FC6_UserData.removedAttrs
78
79 def __init__(self, *args, **kwargs):
80 FC6_UserData.__init__(self, *args, **kwargs)
81 self.lock = kwargs.get("lock", False)
82
83 def _getArgsAsStr(self):
84 retval = FC6_UserData._getArgsAsStr(self)
85
86 if self.lock:
87 retval += " --lock"
88
89 return retval
90
91class F12_UserData(F8_UserData):
92 removedKeywords = F8_UserData.removedKeywords
93 removedAttrs = F8_UserData.removedAttrs
94
95 def __init__(self, *args, **kwargs):
96 F8_UserData.__init__(self, *args, **kwargs)
97 self.gecos = kwargs.get("gecos", "")
98
99 def _getArgsAsStr(self):
100 retval = F8_UserData._getArgsAsStr(self)
101
102 if self.gecos:
103 retval += " --gecos=\"%s\"" % (self.gecos,)
104
105 return retval
106
107class FC6_User(KickstartCommand):
108 removedKeywords = KickstartCommand.removedKeywords
109 removedAttrs = KickstartCommand.removedAttrs
110
111 def __init__(self, writePriority=0, *args, **kwargs):
112 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
113 self.op = self._getParser()
114
115 self.userList = kwargs.get("userList", [])
116
117 def __str__(self):
118 retval = ""
119 for user in self.userList:
120 retval += user.__str__()
121
122 return retval
123
124 def _getParser(self):
125 def groups_cb (option, opt_str, value, parser):
126 for d in value.split(','):
127 parser.values.ensure_value(option.dest, []).append(d)
128
129 op = KSOptionParser()
130 op.add_option("--groups", dest="groups", action="callback",
131 callback=groups_cb, nargs=1, type="string")
132 op.add_option("--homedir")
133 op.add_option("--iscrypted", dest="isCrypted", action="store_true",
134 default=False)
135 op.add_option("--name", required=1)
136 op.add_option("--password")
137 op.add_option("--shell")
138 op.add_option("--uid", type="int")
139 return op
140
141 def parse(self, args):
142 ud = self.handler.UserData()
143 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
144 self._setToObj(self.op, opts, ud)
145 ud.lineno = self.lineno
146
147 # Check for duplicates in the data list.
148 if ud in self.dataList():
149 warnings.warn(_("A user with the name %s has already been defined.") % ud.name)
150
151 return ud
152
153 def dataList(self):
154 return self.userList
155
156class F8_User(FC6_User):
157 removedKeywords = FC6_User.removedKeywords
158 removedAttrs = FC6_User.removedAttrs
159
160 def _getParser(self):
161 op = FC6_User._getParser(self)
162 op.add_option("--lock", action="store_true", default=False)
163 op.add_option("--plaintext", dest="isCrypted", action="store_false")
164 return op
165
166class F12_User(F8_User):
167 removedKeywords = F8_User.removedKeywords
168 removedAttrs = F8_User.removedAttrs
169
170 def _getParser(self):
171 op = F8_User._getParser(self)
172 op.add_option("--gecos", type="string")
173 return op