Skip to content

Commit b23801b

Browse files
committed
first commit
0 parents  commit b23801b

File tree

190 files changed

+635721
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+635721
-0
lines changed

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
*.pyc
2+
*.bak
3+
*.cache
4+
*.dir
5+
*.so
6+
*.pyd
7+
*.sqlite3
8+
*.ini
9+
*.json
10+
*.dat
11+
*.log
12+
.Windows.cache
13+
.Linux.cache
14+
migrations/
15+
__pycache__/
16+
build/
17+
/.idea/
18+
/.git/
19+
/venv/
20+
/media/uploads/
21+
/huaci/error.log
22+
/huaci/debug.log
23+
/init_manga_path.py
24+
/log/
25+
/manga/
26+
/mynav/
27+
/static/img/
28+
/static/css/
29+
/templates/
30+
/media/mynav/
31+
/blob_storage/
32+
/export/
33+
/base/extract_zip.py
34+
/base/update_zip.py
35+
manga.md
36+
auto_tool.bat
37+
auto_tool.py

base/__init__.py

Whitespace-only changes.

base/base_constant.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
builtin_dic_prefix = '''
2+
<link rel='stylesheet' href='/static/bootstrap-4.4.1/css/bootstrap.min.css'>
3+
<link rel='stylesheet' href='/static/mdict/css/mdict.css'>
4+
<script>
5+
//启用mathjax的行内模式
6+
MathJax = {
7+
tex: {
8+
inlineMath: [['$', '$']]
9+
}
10+
};
11+
function elementDisplay(objname){
12+
var obj=document.getElementsByName(objname);
13+
for(var i=0;i<obj.length;i++){
14+
if(obj[i].style.display !='none'){
15+
obj[i].style.display='none';
16+
}else{
17+
obj[i].style.display='block';
18+
}
19+
}
20+
}
21+
</script>
22+
<script id="MathJax-script" async src="/static/mdict/MathJax-master/es5/tex-chtml-full.js"></script>
23+
'''

base/base_func.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import mimetypes
2+
import os, re, inspect, json
3+
from enum import IntEnum
4+
from mysite.settings import BASE_DIR
5+
from django.http.request import QueryDict
6+
7+
font_path = os.path.join(BASE_DIR, 'media', 'font')
8+
9+
10+
def get_log_header(mod_name, debug_level, start=-1, end=-1):
11+
if debug_level == DebugLevel.error:
12+
dl = 'ERROR'
13+
elif debug_level == DebugLevel.warning:
14+
dl = 'WARNING'
15+
16+
if debug_level == DebugLevel.debug:
17+
header = '[' + mod_name.upper() + ']'
18+
else:
19+
header = '[' + mod_name.upper() + ' ' + dl + ']'
20+
21+
if end > 0 and start > 0:
22+
return header + ' ' + get_running_time(start, end)
23+
else:
24+
return header
25+
26+
27+
class DebugLevel(IntEnum):
28+
debug = 0
29+
warning = 1
30+
error = 2
31+
32+
33+
def print_log_info(log_content='', debug_level=DebugLevel.debug, start=-1, end=-1):
34+
prev_frame = inspect.getframeinfo(inspect.currentframe().f_back)
35+
# currentframe()是当前函数,f_back是上一帧,即调用函数
36+
# prev_frame,0是文件路径,1是行数,2是函数名(如果不在函数里,显示<module>),3显示调用本函数的那一行代码,4索引
37+
prev_file = os.path.basename(prev_frame[0]).split('.')[0]
38+
prev_func = prev_frame[2]
39+
if prev_func == '<module>':
40+
mod_name = prev_file
41+
else:
42+
mod_name = prev_file + '.' + prev_func
43+
44+
print(get_log_header(mod_name, debug_level, start, end), log_content)
45+
46+
47+
def get_running_time(start, end):
48+
return '[' + str(round(abs(end - start), 4)) + 's' + ']'
49+
50+
51+
def is_en_func(s): # 是否纯英文
52+
zhmodel = re.compile(r'^[ \'a-zA-Z\-]+$')
53+
match = zhmodel.search(s)
54+
if match:
55+
return True
56+
else:
57+
return False
58+
59+
60+
def conatain_upper_characters(s):
61+
zhmodel = re.compile(r'[A-Z]')
62+
match = zhmodel.search(s)
63+
if match:
64+
return True
65+
else:
66+
return False
67+
68+
69+
def strQ2B(ustring):
70+
"""把字符串全角转半角"""
71+
rstring = ""
72+
for uchar in ustring:
73+
inside_code = ord(uchar)
74+
# ord返回字符的十六进制数
75+
if inside_code == 0x3000:
76+
inside_code = 0x0020
77+
else:
78+
inside_code -= 0xfee0
79+
if inside_code < 0x0020 or inside_code > 0x7e: # 转完之后不是半角字符返回原来的字符
80+
rstring += uchar
81+
else:
82+
rstring += chr(inside_code)
83+
# 将十六进制数转换回字符
84+
return rstring
85+
86+
87+
def request_body_serialze(request):
88+
# 对request.body做QuertDict编码转换处理
89+
# 如果不做数据处理:格式b'id=49&name=%E4%B8%AD&name_cn=&comment='
90+
# 页面中提交的中文“中”,变成%E4%B8%AD
91+
querydict = QueryDict(request.body.decode("utf-8"), encoding="utf-8")
92+
response_dict = {}
93+
try:
94+
for key, val in querydict.items():
95+
response_dict[key] = json.loads(val)
96+
except:
97+
pass
98+
return response_dict
99+
100+
101+
def guess_mime(f_name):
102+
mime_type = mimetypes.guess_type(f_name)[0]
103+
if mime_type is None:
104+
if f_name.endswith('.spx'):
105+
mime_type = 'audio/x-speex'
106+
return mime_type

base/base_func2.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Dec 20 12:11:06 2019
4+
5+
@author: jns
6+
"""
7+
import os
8+
import stat
9+
10+
11+
def rename_file(path, r_path):
12+
try:
13+
os.rename(path, r_path)
14+
except PermissionError as e:
15+
print('权限错误,修改只读属性。')
16+
print(e)
17+
os.chmod(path, stat.S_IWRITE)
18+
os.rename(path, r_path)
19+
except Exception as e:
20+
print('未处理的错误')
21+
print(e)
22+
23+
24+
def delete_file(path):
25+
try:
26+
os.remove(path)
27+
except PermissionError as e:
28+
print(e)
29+
if os.path.isdir(path):
30+
if len(os.listdir(path)) > 0:
31+
print('文件夹非空,无法删除')
32+
else:
33+
print('删除文件夹')
34+
os.rmdir(path)
35+
else:
36+
print('修改只读属性。')
37+
os.chmod(path, stat.S_IWRITE)
38+
os.remove(path)
39+
except Exception as e:
40+
print('未处理的错误')
41+
print(e)
42+
43+
44+
def process_num(t):
45+
str1 = ''
46+
if t < 10:
47+
str1 = '00' + str(t)
48+
elif 10 <= t < 100:
49+
str1 = '0' + str(t)
50+
else:
51+
str1 = str(t)
52+
return str1
53+
54+
55+
def is_number(s):
56+
try:
57+
float(s)
58+
return True
59+
except ValueError:
60+
pass
61+
62+
try:
63+
import unicodedata
64+
unicodedata.numeric(s)
65+
return True
66+
except (TypeError, ValueError):
67+
pass
68+
69+
return False

base/base_func3.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from opencc import OpenCC
2+
s2t = OpenCC('s2t')
3+
t2s = OpenCC('t2s')

base/sys_utils.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import re
2+
import platform
3+
4+
reg1 = r'^[a-zA-Z]:[/\\]'
5+
reg2 = r'[/|\\]'
6+
regp = re.compile(reg2)
7+
8+
9+
def split_os_path(path):
10+
absolute = ''
11+
if check_system() == 0:
12+
if path[0] == '/' or path[0] == '\\':
13+
absolute = '/'
14+
path = path[1:]
15+
else:
16+
result = re.match(reg1, path)
17+
if result is not None:
18+
absolute = result.group()
19+
path = path[len(absolute):]
20+
absolute = absolute.replace('/', '').replace('\\', '')
21+
path_list = list(filter(None, regp.split(path)))
22+
23+
path_dict = {'absolute': absolute, 'path': path_list}
24+
return path_dict
25+
26+
27+
def find_os_path(a, b):
28+
# 获取to_find_path_list在target_path_list中的位置,不存在返回(-1,-1),若重复,则返回最右面那个
29+
start = -1
30+
end = -1
31+
flag = 0
32+
if len(b) > len(a):
33+
return -1, -1
34+
b0_list = [i for i, x in enumerate(a) if x == b[0]]
35+
if len(b0_list) == 0:
36+
return -1, -1
37+
flag = False
38+
for i in reversed(b0_list):
39+
flag = False
40+
for j in range(len(b)):
41+
if not b[j] == a[i + j]:
42+
flag = True
43+
break
44+
if flag:
45+
continue
46+
return i, i + len(b)
47+
return -1, -1
48+
49+
50+
default_system = ''
51+
52+
53+
def get_sys_name(set_system=''):
54+
global default_system
55+
if set_system != '':
56+
default_system = set_system
57+
if default_system != '':
58+
return default_system
59+
return platform.system()
60+
61+
62+
def check_system():
63+
sys_name = get_sys_name()
64+
if sys_name == 'Linux': # 下一步区分linux和wsl
65+
return 0
66+
elif sys_name == 'Windows':
67+
return 1
68+
else:
69+
print('unknown system')
70+
return 1
71+
72+
73+

django-mdict.conf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<IfModule expires_module>
2+
#设置浏览器端缓存
3+
ExpiresActive on
4+
#缓存时长7200000/3600/24=83天
5+
ExpiresByType text/css A7200000
6+
ExpiresByType application/x-javascript A7200000
7+
ExpiresByType application/javascript A7200000
8+
ExpiresByType text/plain A7200000
9+
#ExpiresByType text/html A7200000
10+
ExpiresByType image/jpeg A7200000
11+
ExpiresByType image/gif A7200000
12+
ExpiresByType image/png A7200000
13+
ExpiresByType image/x-icon A7200000
14+
ExpiresByType font/ttf A7200000
15+
ExpiresByType font/woff A7200000
16+
</IfModule>
17+
WSGIApplicationGroup %{GLOBAL}
18+
WSGIPassAuthorization On
19+
#允许通过请求头传递认证信息
20+
WSGIPythonPath ${PRJTROOT}
21+
<VirtualHost *:80>
22+
ServerAdmin webmaster@localhost
23+
ServerName django-mdict
24+
DocumentRoot ${PRJTROOT}
25+
AllowEncodedSlashes NoDecode
26+
Alias /media ${PRJTROOT}/media
27+
<Directory ${PRJTROOT}/collect_static>
28+
Require all granted
29+
</Directory>
30+
<Directory ${PRJTROOT}/media>
31+
Require all granted
32+
</Directory>
33+
WSGIScriptAlias / ${PRJTROOT}/mysite/wsgi.py
34+
# wsgi.py文件的父级目录
35+
<Directory ${PRJTROOT}/mysite>
36+
<Files wsgi.py>
37+
Require all granted
38+
</Files>
39+
</Directory>
40+
</VirtualHost>

0 commit comments

Comments
 (0)