mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 21:26:44 +02:00
Merge branch 'master' of https://github.com/chubin/cheat.sh
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ import requests
|
||||
import jinja2
|
||||
from flask import Flask, request, send_from_directory, redirect, Response
|
||||
|
||||
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
||||
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
|
||||
sys.path.append("%s/lib/" % MYDIR)
|
||||
|
||||
from globals import FILE_QUERIES_LOG, LOG_FILE, TEMPLATES, STATIC, MALFORMED_RESPONSE_HTML_PAGE
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ from tempfile import NamedTemporaryFile
|
||||
|
||||
import redis
|
||||
|
||||
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
||||
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
|
||||
sys.path.append("%s/lib/" % MYDIR)
|
||||
from languages_data import VIM_NAME
|
||||
from globals import PATH_VIM_ENVIRONMENT
|
||||
|
||||
@@ -17,7 +17,7 @@ import colored
|
||||
from pygments import highlight as pygments_highlight
|
||||
from pygments.formatters import Terminal256Formatter # pylint: disable=no-name-in-module
|
||||
|
||||
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
||||
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
|
||||
sys.path.append("%s/lib/" % MYDIR)
|
||||
from globals import error, ANSI2HTML, COLOR_STYLES
|
||||
from buttons import TWITTER_BUTTON, GITHUB_BUTTON, GITHUB_BUTTON_FOOTER
|
||||
|
||||
+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
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import logging
|
||||
import os
|
||||
from pygments.styles import get_all_styles
|
||||
|
||||
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
||||
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
|
||||
|
||||
ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user