Skip to content
Snippets Groups Projects
Commit 7c11c4d6 authored by ulif's avatar ulif
Browse files

Add func to get all local wordlists names.

parent 53ce3f01
No related branches found
No related tags found
No related merge requests found
......@@ -124,6 +124,24 @@ def handle_options(args):
return args
def get_wordlist_names():
"""Get a all names of wordlists stored locally.
"""
result = []
filenames = os.listdir(WORDLISTS_DIR)
for filename in filenames:
if not os.path.isfile(os.path.join(WORDLISTS_DIR, filename)):
continue
if not "_" in filename:
continue
if not "." in filename:
continue
basename = filename.split(".")[0]
name = basename.split("_", 1)[1]
result.append(name)
return sorted(result)
def get_wordlist(file_descriptor):
"""Parse file in `file_descriptor` and build a word list of it.
......
......@@ -8,6 +8,7 @@ from diceware import (
WORDLISTS_DIR, RE_WORDLIST_NAME, SPECIAL_CHARS, get_wordlist,
get_wordlist_path, insert_special_char, get_passphrase,
handle_options, main, __version__, print_version, get_random_sources,
get_wordlist_names,
)
......@@ -120,6 +121,12 @@ class TestDicewareModule(object):
assert exc_info.value.args[0].startswith(
'Not a valid wordlist name')
def test_get_wordlist_names(self, wordlists_dir):
# we can get wordlist names also if directory is empty.
wlist_path = wordlists_dir.join('mywordlist_en_8k.txt')
wlist_path.write("some\nirrelevant\nwords")
assert get_wordlist_names() == ['en_8k']
def test_insert_special_char(self):
# we can insert special chars in words.
fake_rnd = FakeRandom()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment