mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
updated Dockerfile
This commit is contained in:
@@ -2,7 +2,7 @@ import os, zipfile
|
||||
|
||||
|
||||
# 打包目录为zip文件(未压缩)
|
||||
def make_zip(source_dir, output_filename):
|
||||
def zip_file(source_dir, output_filename):
|
||||
zipf = zipfile.ZipFile(output_filename, 'w')
|
||||
pre_len = len(os.path.dirname(source_dir))
|
||||
for parent, dirnames, filenames in os.walk(source_dir):
|
||||
@@ -11,3 +11,13 @@ def make_zip(source_dir, output_filename):
|
||||
arcname = pathfile[pre_len:].strip(os.path.sep) # 相对路径
|
||||
zipf.write(pathfile, arcname)
|
||||
zipf.close()
|
||||
|
||||
|
||||
def unzip_file(zip_src, dst_dir):
|
||||
r = zipfile.is_zipfile(zip_src)
|
||||
if r:
|
||||
fz = zipfile.ZipFile(zip_src, 'r')
|
||||
for file in fz.namelist():
|
||||
fz.extract(file, dst_dir)
|
||||
else:
|
||||
print('This is not zip')
|
||||
|
||||
@@ -5,6 +5,14 @@ from collections import defaultdict
|
||||
SUFFIX_PATTERN = r'\.(\w{,10})$'
|
||||
suffix_regex = re.compile(SUFFIX_PATTERN, re.IGNORECASE)
|
||||
|
||||
SUFFIX_LANG_MAPPING = {
|
||||
'py': 'python',
|
||||
'js': 'javascript',
|
||||
'sh': 'shell',
|
||||
'java': 'java',
|
||||
'c': 'c',
|
||||
}
|
||||
|
||||
|
||||
def get_file_suffix(file_name: str):
|
||||
file_name = file_name.lower()
|
||||
@@ -32,3 +40,14 @@ def get_file_suffix_stats(path) -> dict:
|
||||
suffix = get_file_suffix(file_path)
|
||||
stats[suffix] += 1
|
||||
return stats
|
||||
|
||||
|
||||
def get_file_content(path) -> dict:
|
||||
with open(path) as f:
|
||||
suffix = get_file_suffix(path)
|
||||
lang = SUFFIX_LANG_MAPPING.get(suffix)
|
||||
return {
|
||||
'lang': lang,
|
||||
'suffix': suffix,
|
||||
'content': f.read()
|
||||
}
|
||||
|
||||
10
utils/node.py
Normal file
10
utils/node.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
from config import FLOWER_API_ENDPOINT
|
||||
|
||||
|
||||
def check_nodes_status():
|
||||
res = requests.get('%s/workers?status=1' % FLOWER_API_ENDPOINT)
|
||||
return json.loads(res.content.decode('utf-8'))
|
||||
Reference in New Issue
Block a user