2021SC@SDUSC
我们继续分析seafes部分的文件。
Seafes connection.py此文件用于连接服务器。
import requests
from elasticsearch import Elasticsearch
from seafes.config import seafes_config
def es_get_conn():
es = Elasticsearch(['{}:{}'.format(seafes_config.host, seafes_config.port)], maxsize=50, timeout=30)
return es
def es_get_status():
""" return True if es server work normal, otherwise return false
"""
protocol = ['http', 'https']
urls = []
for p in protocol:
urls.append(p + '://' + str(seafes_config.host) + ':' + str(seafes_config.port) + '/repofiles?pretty')
alive = False
try:
for url in urls:
if requests.get(url, timeout=10).status_code == 200:
alive = True
except:
pass
return alive
在es_get_conn()函数中服务器正常工作则返回true,否则返回false。
constants.py该文件定义了项目中可能会出现的所有文件的后缀。
text_suffixes = [
'txt',
'md',
'markdown'
]
office_suffixes = [
'doc',
'docx',
'ppt',
'pptx',
'xls',
'xlsx',
'pdf',
'odt',
'ods',
'odp',
]
之后我们还会继续分析其他文件。



