mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 13:42:11 +01:00
Update sheets.py
Add color Add sbdir creation and search as well Add Remove sheet function
This commit is contained in:
parent
3c2bcf5073
commit
facd365d27
1 changed files with 27 additions and 13 deletions
|
@ -36,15 +36,23 @@ def get():
|
||||||
|
|
||||||
# otherwise, scan the filesystem
|
# otherwise, scan the filesystem
|
||||||
for cheat_dir in reversed(paths()):
|
for cheat_dir in reversed(paths()):
|
||||||
|
subdirs = []
|
||||||
|
for root, dirs, files in os.walk(cheat_dir, topdown=True):
|
||||||
|
dirs[:] = [d for d in dirs if not d.startswith('.')]
|
||||||
|
subdirs.append(root)
|
||||||
|
|
||||||
|
for subdir in subdirs:
|
||||||
cheats.update(
|
cheats.update(
|
||||||
dict([
|
dict([
|
||||||
(cheat, os.path.join(cheat_dir, cheat))
|
(cheat, os.path.join(subdir, cheat))
|
||||||
for cheat in os.listdir(cheat_dir)
|
for cheat in os.listdir(subdir)
|
||||||
if not cheat.startswith('.')
|
if not cheat.startswith('.')
|
||||||
and not cheat.startswith('__')
|
and not cheat.startswith('__')
|
||||||
|
and not os.path.isdir(os.path.join(subdir, cheat))
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return cheats
|
return cheats
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,15 +84,21 @@ def list():
|
||||||
return sheet_list
|
return sheet_list
|
||||||
|
|
||||||
|
|
||||||
def search(term):
|
def search(term, target_sheet):
|
||||||
""" Searches all cheatsheets for the specified term """
|
""" Searches all cheatsheets for the specified term.
|
||||||
|
Restrict search to target_sheet if given """
|
||||||
result = ''
|
result = ''
|
||||||
|
|
||||||
for cheatsheet in sorted(get().items()):
|
for cheatsheet in sorted(get().items()):
|
||||||
|
if target_sheet and target_sheet != cheatsheet[0]:
|
||||||
|
continue
|
||||||
match = ''
|
match = ''
|
||||||
for line in open(cheatsheet[1]):
|
# for line in open(cheatsheet[1]):
|
||||||
|
for index, line in enumerate(open(cheatsheet[1])):
|
||||||
if term in line:
|
if term in line:
|
||||||
match += ' ' + line
|
match += '[%d]\t\t' % index + line.strip() + '\n'
|
||||||
|
# if 'CHEATCOLORS' in os.environ:
|
||||||
|
# line = line.replace(term, '\033[1;31m'+ term +'\033[0m');
|
||||||
|
# match += ' ' + line
|
||||||
|
|
||||||
if match != '':
|
if match != '':
|
||||||
result += cheatsheet[0] + ":\n" + match + "\n"
|
result += cheatsheet[0] + ":\n" + match + "\n"
|
||||||
|
|
Loading…
Reference in a new issue