mirror of
https://github.com/chubin/cheat.sh.git
synced 2024-11-22 18:17:38 +03:00
support for python3
This commit is contained in:
parent
5390146874
commit
adcac9bfeb
@ -14,5 +14,5 @@ __all__ = [
|
||||
for f in glob.glob(join(dirname(__file__), "*.py"))
|
||||
if isfile(f) and not f.endswith('__init__.py')]
|
||||
|
||||
from adapter import all_adapters
|
||||
from .adapter import all_adapters
|
||||
from . import *
|
||||
|
@ -7,7 +7,7 @@ Each cheat sheet is a separate file without extension
|
||||
|
||||
# pylint: disable=relative-import,abstract-method
|
||||
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
|
||||
class Cheat(GitRepositoryAdapter):
|
||||
"""
|
||||
|
@ -9,7 +9,7 @@ sheets covering programming languages are are located in subdirectories.
|
||||
import os
|
||||
import glob
|
||||
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
|
||||
def _remove_initial_underscore(filename):
|
||||
if filename.startswith('_'):
|
||||
@ -84,7 +84,7 @@ class CheatSheets(GitRepositoryAdapter):
|
||||
# though it should not happen
|
||||
answer = "%s:%s not found" % (str(self.__class__), topic)
|
||||
|
||||
return answer.decode('utf-8')
|
||||
return answer
|
||||
|
||||
class CheatSheetsDir(CheatSheets):
|
||||
|
||||
|
@ -5,9 +5,8 @@
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
from gevent.subprocess import Popen, PIPE
|
||||
patch_all()
|
||||
|
||||
from adapter import Adapter
|
||||
from .adapter import Adapter
|
||||
|
||||
class CommandAdapter(Adapter):
|
||||
"""
|
||||
|
@ -5,7 +5,7 @@ Implementation of `GitRepositoryAdapter`, adapter that is used to handle git rep
|
||||
import glob
|
||||
import os
|
||||
|
||||
from adapter import Adapter # pylint: disable=relative-import
|
||||
from .adapter import Adapter # pylint: disable=relative-import
|
||||
|
||||
def _get_filenames(path):
|
||||
return [os.path.split(topic)[1] for topic in glob.glob(path)]
|
||||
@ -49,7 +49,7 @@ class RepositoryAdapter(Adapter):
|
||||
# though it should not happen
|
||||
answer = "%s:%s not found" % (str(self.__class__), topic)
|
||||
|
||||
return answer.decode('utf-8')
|
||||
return answer
|
||||
|
||||
|
||||
class GitRepositoryAdapter(RepositoryAdapter): #pylint: disable=abstract-method
|
||||
|
@ -12,7 +12,7 @@ import collections
|
||||
from fuzzywuzzy import process, fuzz
|
||||
|
||||
from config import CONFIG
|
||||
from adapter import Adapter
|
||||
from .adapter import Adapter
|
||||
from fmt.internal import colorize_internal
|
||||
|
||||
_INTERNAL_TOPICS = [
|
||||
|
@ -10,7 +10,7 @@ The adapter exposes one page ("latencies") and several its aliases
|
||||
|
||||
import sys
|
||||
import os
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
|
||||
class Latenz(GitRepositoryAdapter):
|
||||
|
||||
@ -25,7 +25,7 @@ class Latenz(GitRepositoryAdapter):
|
||||
def _get_page(self, topic, request_options=None):
|
||||
sys.path.append(os.path.join(self.local_repository_location(), 'bin'))
|
||||
import latencies
|
||||
return latencies.render().decode("utf-8")
|
||||
return latencies.render()
|
||||
|
||||
def _get_list(self, prefix=None):
|
||||
return ['latencies']
|
||||
|
@ -12,7 +12,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import re
|
||||
from config import CONFIG
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
|
||||
class LearnXinY(GitRepositoryAdapter):
|
||||
|
||||
@ -37,7 +37,7 @@ class LearnXinY(GitRepositoryAdapter):
|
||||
lang, topic = topic.split('/', 1)
|
||||
if lang not in self.adapters:
|
||||
return ''
|
||||
return self.adapters[lang].get_page(topic).decode("utf-8")
|
||||
return self.adapters[lang].get_page(topic)
|
||||
|
||||
def _get_list(self, prefix=None):
|
||||
"""
|
||||
|
@ -10,7 +10,6 @@ from __future__ import print_function
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
from gevent.subprocess import Popen, PIPE
|
||||
patch_all()
|
||||
|
||||
import os
|
||||
import re
|
||||
@ -19,8 +18,8 @@ from polyglot.detect import Detector
|
||||
from polyglot.detect.base import UnknownLanguage
|
||||
|
||||
from config import CONFIG
|
||||
from upstream import UpstreamAdapter
|
||||
from languages_data import SO_NAME
|
||||
from .upstream import UpstreamAdapter
|
||||
|
||||
class Question(UpstreamAdapter):
|
||||
|
||||
|
@ -12,8 +12,8 @@ import os
|
||||
import glob
|
||||
import yaml
|
||||
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from cheat_sheets import CheatSheets
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
from .cheat_sheets import CheatSheets
|
||||
|
||||
class Rosetta(GitRepositoryAdapter):
|
||||
|
||||
|
@ -12,7 +12,7 @@ The pages are formatted with a markdown dialect
|
||||
import re
|
||||
import os
|
||||
|
||||
from git_adapter import GitRepositoryAdapter
|
||||
from .git_adapter import GitRepositoryAdapter
|
||||
|
||||
class Tldr(GitRepositoryAdapter):
|
||||
|
||||
|
@ -13,7 +13,7 @@ import textwrap
|
||||
import requests
|
||||
|
||||
from config import CONFIG
|
||||
from adapter import Adapter
|
||||
from .adapter import Adapter
|
||||
|
||||
def _are_you_offline():
|
||||
return textwrap.dedent(
|
||||
|
@ -14,11 +14,11 @@ Configuration parameters:
|
||||
|
||||
import os
|
||||
import json
|
||||
import redis
|
||||
from config import CONFIG
|
||||
|
||||
_REDIS = None
|
||||
if CONFIG['cache.type'] == 'redis':
|
||||
import redis
|
||||
_REDIS = redis.StrictRedis(
|
||||
host=CONFIG['cache.redis.host'],
|
||||
port=CONFIG['cache.redis.port'],
|
||||
|
@ -44,8 +44,9 @@ specified by an environment variable is not an integer, it is ignored.
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import yaml
|
||||
from pygments.styles import get_all_styles
|
||||
# from pygments.styles import get_all_styles
|
||||
def get_all_styles():
|
||||
return []
|
||||
|
||||
_ENV_VAR_PREFIX = "CHEATSH"
|
||||
|
||||
@ -221,6 +222,7 @@ def _get_nested(data, key):
|
||||
return None
|
||||
|
||||
def _load_config_from_file(default_config, filename):
|
||||
import yaml
|
||||
|
||||
update = {}
|
||||
if not os.path.exists(filename):
|
||||
@ -244,8 +246,8 @@ def _load_config_from_file(default_config, filename):
|
||||
|
||||
CONFIG = Config()
|
||||
CONFIG.update(_CONFIG)
|
||||
CONFIG.update(_load_config_from_file(_CONFIG, _CONF_FILE_MYDIR))
|
||||
CONFIG.update(_load_config_from_file(_CONFIG, _CONF_FILE_WORKDIR))
|
||||
# CONFIG.update(_load_config_from_file(_CONFIG, _CONF_FILE_MYDIR))
|
||||
# CONFIG.update(_load_config_from_file(_CONFIG, _CONF_FILE_WORKDIR))
|
||||
CONFIG.update(_load_config_from_environ(_CONFIG))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -24,7 +24,6 @@ from __future__ import print_function
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
from gevent.subprocess import Popen
|
||||
patch_all()
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
@ -7,7 +7,6 @@ Configuration parameters:
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
from gevent.subprocess import Popen, PIPE
|
||||
patch_all()
|
||||
|
||||
# pylint: disable=wrong-import-position,wrong-import-order
|
||||
import sys
|
||||
|
@ -2,11 +2,18 @@
|
||||
Standalone wrapper for the cheat.sh server.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import textwrap
|
||||
import urlparse
|
||||
try:
|
||||
import urlparse
|
||||
except ModuleNotFoundError:
|
||||
import urllib.parse as urlparse
|
||||
|
||||
import config
|
||||
config.CONFIG["cache.type"] = "none"
|
||||
|
||||
import cheat_wrapper
|
||||
import options
|
||||
|
||||
@ -15,13 +22,13 @@ def show_usage():
|
||||
Show how to use the program in the standalone mode
|
||||
"""
|
||||
|
||||
print textwrap.dedent("""
|
||||
print(textwrap.dedent("""
|
||||
Usage:
|
||||
|
||||
lib/standalone.py [OPTIONS] QUERY
|
||||
|
||||
For OPTIONS see :help
|
||||
""")[1:-1]
|
||||
""")[1:-1])
|
||||
|
||||
def parse_cmdline(args):
|
||||
"""
|
||||
@ -50,10 +57,9 @@ def main(args):
|
||||
standalone wrapper for cheat_wrapper()
|
||||
"""
|
||||
|
||||
config.CONFIG["cache.type"] = "none"
|
||||
query, request_options = parse_cmdline(args)
|
||||
answer, _ = cheat_wrapper.cheat_wrapper(query, request_options=request_options)
|
||||
sys.stdout.write(answer.encode("utf-8"))
|
||||
sys.stdout.write(answer)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
|
@ -1,3 +1,4 @@
|
||||
wheel
|
||||
gevent
|
||||
flask
|
||||
requests
|
||||
|
@ -380,7 +380,7 @@ if [ "$CHTSH_MODE" = auto ] && [ -d "$CHEATSH_INSTALLATION" ]; then
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
local url; url="$1"; shift
|
||||
"$CHEATSH_INSTALLATION/ve/bin/python" "$CHEATSH_INSTALLATION/lib/standalone.py" "${url#"$CHTSH_URL"}" "$@"
|
||||
PYTHONIOENCODING=UTF-8 "$CHEATSH_INSTALLATION/ve/bin/python" "$CHEATSH_INSTALLATION/lib/standalone.py" "${url#"$CHTSH_URL"}" "$@"
|
||||
}
|
||||
elif [ "$(uname -s)" = OpenBSD ] && [ -x /usr/bin/ftp ]; then
|
||||
# any better test not involving either OS matching or actual query?
|
||||
|
@ -13,7 +13,7 @@ python/copy+file?QT # [online]
|
||||
/
|
||||
//
|
||||
python/:learn
|
||||
latencies
|
||||
latencies # [python3]
|
||||
az # chubin/cheat.sheets
|
||||
python/rosetta/Substring # rosetta
|
||||
python/rosetta/Substring?T # rosetta
|
||||
@ -22,3 +22,4 @@ js/:learn # short names check
|
||||
javascript/:learn # short names check
|
||||
emacs:go-mode/:list # special editor names
|
||||
mkffs.ffatt # unknown
|
||||
latencies # [python2]
|
||||
|
Loading…
Reference in New Issue
Block a user