mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 13:16:44 +02:00
+37
-32
@@ -56,48 +56,53 @@ INTERNAL_TOPICS = [
|
||||
':share',
|
||||
]
|
||||
|
||||
def _get_filenames(path):
|
||||
return [os.path.split(topic)[1] for topic in glob.glob(path)]
|
||||
|
||||
def _update_tldr_topics():
|
||||
answer = []
|
||||
for topic in glob.glob(PATH_TLDR_PAGES):
|
||||
_, filename = os.path.split(topic)
|
||||
if filename.endswith('.md'):
|
||||
answer.append(filename[:-3])
|
||||
return answer
|
||||
TLDR_TOPICS = _update_tldr_topics()
|
||||
return [ filename[:-3] for filename in _get_filenames(PATH_TLDR_PAGES) if filename.endswith('.md') ]
|
||||
|
||||
def _update_cheat_topics():
|
||||
answer = []
|
||||
for topic in glob.glob(PATH_CHEAT_PAGES):
|
||||
_, filename = os.path.split(topic)
|
||||
answer.append(filename)
|
||||
return answer
|
||||
return _get_filenames(PATH_CHEAT_PAGES)
|
||||
|
||||
|
||||
|
||||
TLDR_TOPICS = _update_tldr_topics()
|
||||
CHEAT_TOPICS = _update_cheat_topics()
|
||||
|
||||
def _remove_initial_underscore(filename):
|
||||
if filename.startswith('_'):
|
||||
filename = filename[1:]
|
||||
return filename
|
||||
|
||||
def _sanitize_dirname(dirname):
|
||||
dirname = os.path.basename(dirname)
|
||||
dirname = remove_initial_underscore(dirname)
|
||||
return dirname
|
||||
|
||||
def _format_answer(dirname,filename):
|
||||
return "%s/%s" % ( _sanitize_dirname(dirname), filename )
|
||||
|
||||
def _get_answer_files_from_folder():
|
||||
topics = map(os.path.split, glob.glob(PATH_CHEAT_SHEETS + "*/*"))
|
||||
return [_format_answer(dirname,filename) for dirname, filename in topics if filename not in ['_info.yaml'] ]
|
||||
def _isdir(topic):
|
||||
return os.path.isdir(topic)
|
||||
def _get_answers_and_dirs():
|
||||
topics = glob.glob(PATH_CHEAT_SHEETS + "*")
|
||||
answer_dirs = [_remove_initial_underscore(os.path.split(topic)[1]) for topic in topics if _isdir(topic)]
|
||||
answers = [ os.path.split(topic)[1] for topic in topics if not _isdir(topic)]
|
||||
return answer_dirs, answers
|
||||
|
||||
def _update_cheat_sheets_topics():
|
||||
answer = []
|
||||
answer_dirs = []
|
||||
answers = _get_answer_files_from_folder()
|
||||
cheatsheet_answers, cheatsheet_dirs = _get_answers_and_dirs()
|
||||
return answers+cheatsheet_answers, cheatsheet_dirs
|
||||
|
||||
for topic in glob.glob(PATH_CHEAT_SHEETS + "*/*"):
|
||||
dirname, filename = os.path.split(topic)
|
||||
if filename in ['_info.yaml']:
|
||||
continue
|
||||
dirname = os.path.basename(dirname)
|
||||
if dirname.startswith('_'):
|
||||
dirname = dirname[1:]
|
||||
answer.append("%s/%s" % (dirname, filename))
|
||||
|
||||
for topic in glob.glob(PATH_CHEAT_SHEETS + "*"):
|
||||
_, filename = os.path.split(topic)
|
||||
if os.path.isdir(topic):
|
||||
if filename.startswith('_'):
|
||||
filename = filename[1:]
|
||||
answer_dirs.append(filename+'/')
|
||||
else:
|
||||
answer.append(filename)
|
||||
return answer, answer_dirs
|
||||
CHEAT_SHEETS_TOPICS, CHEAT_SHEETS_DIRS = _update_cheat_sheets_topics()
|
||||
|
||||
CACHED_TOPICS_LIST = [[]]
|
||||
|
||||
def get_topics_list(skip_dirs=False, skip_internal=False):
|
||||
"""
|
||||
List of topics returned on /:list
|
||||
|
||||
Reference in New Issue
Block a user