updated Dockerfile

This commit is contained in:
Marvin Zhang
2019-02-28 18:57:44 +08:00
parent cf1d1ca878
commit ae5ea03043
19 changed files with 236 additions and 59 deletions

View File

@@ -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')

View File

@@ -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
View 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'))