Skip to content

Commit a4be5d8

Browse files
authored
Merge pull request chubin#255 from chubin/chubin.ci
Chubin.ci
2 parents f13d4f6 + a0a2268 commit a4be5d8

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ FROM alpine:3.12
33
## installing dependencies
44
RUN apk add --update --no-cache git py3-six py3-pygments py3-yaml py3-gevent \
55
libstdc++ py3-colorama py3-requests py3-icu py3-redis
6-
## building missing python packages
7-
RUN apk add --no-cache --virtual build-deps py3-pip g++ python3-dev \
8-
&& pip3 install --no-cache-dir rapidfuzz colored polyglot pycld2 \
9-
&& apk del build-deps
106
## copying
117
WORKDIR /app
128
COPY . /app
9+
## building missing python packages
10+
RUN apk add --no-cache --virtual build-deps py3-pip g++ python3-dev libffi-dev \
11+
&& pip3 install --no-cache-dir --upgrade pygments \
12+
&& pip3 install --no-cache-dir -r requirements.txt \
13+
&& apk del build-deps
14+
# fetching dependencies
1315
RUN mkdir -p /root/.cheat.sh/log/ \
1416
&& python3 lib/fetch.py fetch-all
1517

lib/adapter/adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def get_page_dict(self, topic, request_options=None):
145145
'topic': topic,
146146
'topic_type': self._adapter_name,
147147
'format': self._get_output_format(topic),
148+
'cache': self._cache_needed,
148149
}
149150
answer_dict.update(answer)
150151

lib/adapter/upstream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class UpstreamAdapter(Adapter):
4848

4949
_adapter_name = "upstream"
5050
_output_format = "ansi"
51-
_cache_needed = True
51+
_cache_needed = False
5252

5353
def _get_page(self, topic, request_options=None):
5454

@@ -58,7 +58,7 @@ def _get_page(self, topic, request_options=None):
5858
+ "?" + options_string
5959
try:
6060
response = requests.get(url, timeout=CONFIG["upstream.timeout"])
61-
answer = response.text
61+
answer = {"cache": False, "answer": response.text}
6262
except requests.exceptions.ConnectionError:
6363
answer = {"cache": False, "answer":_are_you_offline()}
6464
return answer

lib/routing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def get_answer_dict(self, topic, request_options=None):
182182
}
183183

184184
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
185-
cache.put('q:' + topic, answer)
185+
if answer.get("cache", True):
186+
cache.put('q:' + topic, answer)
186187
return answer
187188

188189
# Try to find cacheable queries in the cache.

tests/results/7

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Special pages:
3131
:bash_completion bash function for tab completion
3232
:styles list of color styles
3333
:styles-demo show color styles usage examples
34+
:random fetches a random cheat sheet
3435

3536
Shell client:
3637

@@ -75,6 +76,7 @@ each programming language topic has the following subptopics:
7576
hello hello world + how to start the program
7677
:learn big cheat sheet for learning language from scratch
7778
:list list of topics
79+
:random fetches a random cheat sheet belonging to the topic
7880

7981
Support programming languages:
8082

0 commit comments

Comments
 (0)