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())
|
self.fragments.append(style_reset())
|
||||||
|
|
||||||
def list_homes():
|
def list_homes():
|
||||||
already_listed = set()
|
usernames = []
|
||||||
|
home_dirs = []
|
||||||
|
|
||||||
with open("/etc/passwd") as f:
|
if os.path.exists("/etc/passwd"):
|
||||||
for line in f:
|
with open("/etc/passwd") as f:
|
||||||
tokens = line.split(":")
|
for line in f:
|
||||||
|
tokens = line.split(":")
|
||||||
|
|
||||||
if tokens[5] != "/dev/null":
|
if tokens[5] != "/dev/null":
|
||||||
if tokens[5] not in already_listed:
|
if tokens[5] not in home_dirs:
|
||||||
already_listed.add(tokens[5])
|
usernames.append(tokens[0])
|
||||||
yield (tokens[5], tokens[0])
|
home_dirs.append(tokens[5])
|
||||||
|
|
||||||
|
return list(zip(home_dirs, usernames))
|
||||||
|
|
||||||
class Dir:
|
class Dir:
|
||||||
def __init__(self, path, name=None, slash="/"):
|
def __init__(self, path, name=None, slash="/"):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue