-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroupradd.py
More file actions
26 lines (22 loc) · 802 Bytes
/
groupradd.py
File metadata and controls
26 lines (22 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from random import choice
from string import ascii_lowercase
from groupadd import groupadd
from groupadd import groupdel
from groupadd import groupexists
""" https://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits#2257449 """
def id_generator(size=6, chars=ascii_lowercase):
#return ''.join(choice(chars) for _ in range(size))
return ''.join(map(lambda _: choice(chars), range(size)))
def groupradd():
while True:
group = id_generator()
if not groupexists(group): break
#while groupexists(group = id_generator()): pass
groupadd(group)
return group
def main():
group = groupradd()
assert groupexists(group)
groupdel(group)
assert not groupexists(group)
if __name__ == "__main__": main()