rework the output format for --list-keywords
This commit is contained in:
parent
b6b214f7e9
commit
4c88c0d496
@ -175,22 +175,39 @@ class KeywordJob(Job):
|
|||||||
def run(self):
|
def run(self):
|
||||||
for msg in self.extractor:
|
for msg in self.extractor:
|
||||||
if msg[0] == Message.Url:
|
if msg[0] == Message.Url:
|
||||||
print("Keywords for filenames:")
|
print("\nKeywords for filenames:")
|
||||||
|
print("-----------------------")
|
||||||
self.update_kwdict(msg[2])
|
self.update_kwdict(msg[2])
|
||||||
self.print_keywords(msg[2])
|
self.print_keywords(msg[2])
|
||||||
return
|
return
|
||||||
elif msg[0] == Message.Directory:
|
elif msg[0] == Message.Directory:
|
||||||
print("Keywords for directory names:")
|
print("Keywords for directory names:")
|
||||||
|
print("-----------------------------")
|
||||||
self.update_kwdict(msg[1])
|
self.update_kwdict(msg[1])
|
||||||
self.print_keywords(msg[1])
|
self.print_keywords(msg[1])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def print_keywords(keywords):
|
def print_keywords(keywords, prefix="", suffix=""):
|
||||||
"""Print key-value pairs with formatting"""
|
"""Print key-value pairs with formatting"""
|
||||||
offset = max(map(len, keywords.keys())) + 1
|
|
||||||
for key, value in sorted(keywords.items()):
|
for key, value in sorted(keywords.items()):
|
||||||
print(key, ":", " "*(offset-len(key)), value, sep="")
|
|
||||||
print()
|
if isinstance(value, dict):
|
||||||
|
nprefix = prefix + key + "["
|
||||||
|
KeywordJob.print_keywords(value, nprefix, suffix + "]")
|
||||||
|
|
||||||
|
elif isinstance(value, list):
|
||||||
|
if value and isinstance(value[0], dict):
|
||||||
|
nprefix = prefix + key + "[][",
|
||||||
|
KeywordJob.print_keywords(value[0], nprefix, suffix + "]")
|
||||||
|
else:
|
||||||
|
print(prefix, key, "[]", suffix, sep="")
|
||||||
|
for val in value:
|
||||||
|
print(" - ", val, sep="")
|
||||||
|
|
||||||
|
else:
|
||||||
|
# string or number
|
||||||
|
print(prefix, key, suffix, sep="")
|
||||||
|
print(" ", value, sep="")
|
||||||
|
|
||||||
|
|
||||||
class UrlJob(Job):
|
class UrlJob(Job):
|
||||||
|
@ -51,7 +51,7 @@ skip = [
|
|||||||
# dont work on travis-ci
|
# dont work on travis-ci
|
||||||
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
|
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
|
||||||
# temporary issues
|
# temporary issues
|
||||||
"yomanga",
|
"yomanga", "hbrowse",
|
||||||
]
|
]
|
||||||
# enable selective testing for direct calls
|
# enable selective testing for direct calls
|
||||||
if __name__ == '__main__' and len(sys.argv) > 1:
|
if __name__ == '__main__' and len(sys.argv) > 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user