prompt: don't crash on missing /etc/passwd
This commit is contained in:
parent
7bfa0deecd
commit
d8b5c3eb73
1 changed files with 13 additions and 9 deletions
|
@ -220,16 +220,20 @@ class LoginPart(Part):
|
|||
self.fragments.append(style_reset())
|
||||
|
||||
def list_homes():
|
||||
already_listed = set()
|
||||
usernames = []
|
||||
home_dirs = []
|
||||
|
||||
if os.path.exists("/etc/passwd"):
|
||||
with open("/etc/passwd") as f:
|
||||
for line in f:
|
||||
tokens = line.split(":")
|
||||
|
||||
if tokens[5] != "/dev/null":
|
||||
if tokens[5] not in already_listed:
|
||||
already_listed.add(tokens[5])
|
||||
yield (tokens[5], tokens[0])
|
||||
if tokens[5] not in home_dirs:
|
||||
usernames.append(tokens[0])
|
||||
home_dirs.append(tokens[5])
|
||||
|
||||
return list(zip(home_dirs, usernames))
|
||||
|
||||
class Dir:
|
||||
def __init__(self, path, name=None, slash="/"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue