summaryrefslogtreecommitdiffstats
path: root/meta/classes/useradd-staticids.bbclass
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2015-12-19 00:53:49 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-18 11:47:06 +0000
commitb18e40ce2f5859865d26a4010d78e65f6f2972fc (patch)
tree0e5182592cf4ca8bfbabb6e042ac3acf28d60e64 /meta/classes/useradd-staticids.bbclass
parentb689aa0df3c2cd36d3b54dd84ec3e264e8fd85ff (diff)
downloadpoky-b18e40ce2f5859865d26a4010d78e65f6f2972fc.tar.gz
useradd-staticids.bbclass: Simplify some logic
The [<on_true>, <on_false>][not <condition>] construct may solve the problem of implementing a conditional operator, but it is not very readable. At least I find this: uaargs.groupid = field[3] or uaargs.gid or uaargs.groupname a lot more readable than this: uaargs.groupid = [uaargs.gid, uaargs.groupname][not uaargs.gid] uaargs.groupid = [field[3], uaargs.groupid][not field[3]] Also, the official conditional operator since Python 2.5 (<on_true> if <condition> else <on_false>) does not evaluate both <on_false> and <on_true> as [<on_true>, <on_false>][not <condition>] does. (From OE-Core rev: 274d38a6e2183ec88335a08b963f26c34b328558) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/useradd-staticids.bbclass')
-rw-r--r--meta/classes/useradd-staticids.bbclass15
1 files changed, 7 insertions, 8 deletions
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index c2e6579b22..0e855e91c7 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -97,7 +97,7 @@ def update_useradd_static_config(d):
97 if field[0] == uaargs.LOGIN: 97 if field[0] == uaargs.LOGIN:
98 if uaargs.uid and field[2] and (uaargs.uid != field[2]): 98 if uaargs.uid and field[2] and (uaargs.uid != field[2]):
99 bb.warn("%s: Changing username %s's uid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.uid, field[2])) 99 bb.warn("%s: Changing username %s's uid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.uid, field[2]))
100 uaargs.uid = [field[2], uaargs.uid][not field[2]] 100 uaargs.uid = field[2] or uaargs.uid
101 101
102 # Determine the possible groupname 102 # Determine the possible groupname
103 # Unless the group name (or gid) is specified, we assume that the LOGIN is the groupname 103 # Unless the group name (or gid) is specified, we assume that the LOGIN is the groupname
@@ -107,9 +107,8 @@ def update_useradd_static_config(d):
107 # is used, and we disable the user_group option. 107 # is used, and we disable the user_group option.
108 # 108 #
109 user_group = uaargs.user_group is None or uaargs.user_group is True 109 user_group = uaargs.user_group is None or uaargs.user_group is True
110 uaargs.groupname = [uaargs.LOGIN, uaargs.gid][not user_group] 110 uaargs.groupname = uaargs.LOGIN if user_group else uaargs.gid
111 uaargs.groupid = [uaargs.gid, uaargs.groupname][not uaargs.gid] 111 uaargs.groupid = field[3] or uaargs.gid or uaargs.groupname
112 uaargs.groupid = [field[3], uaargs.groupid][not field[3]]
113 112
114 if not uaargs.gid or uaargs.gid != uaargs.groupid: 113 if not uaargs.gid or uaargs.gid != uaargs.groupid:
115 if (uaargs.groupid and uaargs.groupid.isdigit()) and (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.groupid != uaargs.groupname): 114 if (uaargs.groupid and uaargs.groupid.isdigit()) and (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.groupid != uaargs.groupname):
@@ -123,7 +122,7 @@ def update_useradd_static_config(d):
123 uaargs.gid = uaargs.groupid 122 uaargs.gid = uaargs.groupid
124 uaargs.user_group = None 123 uaargs.user_group = None
125 groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True) 124 groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
126 newgroup = "%s %s" % (['', ' --system'][uaargs.system], uaargs.groupname) 125 newgroup = "%s %s" % (' --system' if uaargs.system else '', uaargs.groupname)
127 if groupadd: 126 if groupadd:
128 d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup)) 127 d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
129 else: 128 else:
@@ -140,9 +139,9 @@ def update_useradd_static_config(d):
140 else: 139 else:
141 d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup) 140 d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
142 141
143 uaargs.comment = ["'%s'" % field[4], uaargs.comment][not field[4]] 142 uaargs.comment = "'%s'" % field[4] if field[4] else uaargs.comment
144 uaargs.home_dir = [field[5], uaargs.home_dir][not field[5]] 143 uaargs.home_dir = field[5] or uaargs.home_dir
145 uaargs.shell = [field[6], uaargs.shell][not field[6]] 144 uaargs.shell = field[6] or uaargs.shell
146 break 145 break
147 146
148 # Should be an error if a specific option is set... 147 # Should be an error if a specific option is set...