# Path: worker/bases.py
# def get_config(section, key, const=0):
#     """
#     Get a configuration
#     :param section: string, the config insides which section
#     :param key: string
#     :param const: int, 0 means to look up user's conf, 1 means to look up bioqueue's conf
#     :return:
#     """
#     try:
#         config = config_init(const)
#         return config.get(section, key)
#     except:
#         return None
# 
# def rand_sig():
#     """
#     Generate a random signature
#     :return: string
#     """
#     import datetime
#     import hashlib
#     sig = hashlib.md5(str(datetime.datetime.now()).encode())
#     return sig.hexdigest()
# 
# def get_user_folder_size(user):
#     kb_to_mb = 1073741824
#     user_path = os.path.join(get_config('env', 'workspace'), str(user))
#     return round(get_folder_size(user_path)/kb_to_mb)


from django.http import JsonResponse, StreamingHttpResponse
from worker.bases import get_config, rand_sig, get_user_folder_size
from django.core.paginator import EmptyPage, PageNotAnInteger
    from django.contrib.auth.models import User
import os
    import json
    import os
    import os
    import platform
        print(e)
        disk_pool = disk_used = disk_perc = 0
    return disk_pool, disk_used, disk_perc


def get_maintenance_protocols():
    """
    Get maintenance protocols
    :return: list, module names
    """
    protocols = []
    protocols_path = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'maintenance_protocols')
    for model_name in os.listdir(protocols_path):
        if not model_name.endswith('.py') or model_name.startswith('_') or model_name.startswith('maintenance'):
            continue
        protocols.append(model_name.replace('.py', ''))
    return protocols


def error(message, jump_url='.', msg_title="error", status=0, wait_second=3):
    json_data = dict()
    json_data['msg_title'] = msg_title
    json_data['info'] = str(message)
    json_data['url'] = jump_url
    json_data['status'] = status
    json_data['wait_second'] = wait_second
    return JsonResponse(json_data)


def handle_uploaded_file(f):

# Path: worker/bases.py
# def get_config(section, key, const=0):
#     """
#     Get a configuration
#     :param section: string, the config insides which section
#     :param key: string
#     :param const: int, 0 means to look up user's conf, 1 means to look up bioqueue's conf
#     :return:
#     """
#     try:
#         config = config_init(const)
#         return config.get(section, key)
#     except:
#         return None
# 
# def rand_sig():
#     """
#     Generate a random signature
#     :return: string
#     """
#     import datetime
#     import hashlib
#     sig = hashlib.md5(str(datetime.datetime.now()).encode())
#     return sig.hexdigest()
# 
# def get_user_folder_size(user):
#     kb_to_mb = 1073741824
#     user_path = os.path.join(get_config('env', 'workspace'), str(user))
#     return round(get_folder_size(user_path)/kb_to_mb)


# Path: ui/tools.py
from django.http import JsonResponse, StreamingHttpResponse
from worker.bases import get_config, rand_sig, get_user_folder_size
from django.core.paginator import EmptyPage, PageNotAnInteger
    from django.contrib.auth.models import User
import os
    import json
    import os
    import os
    import platform

        print(e)
        disk_pool = disk_used = disk_perc = 0
    return disk_pool, disk_used, disk_perc


def get_maintenance_protocols():
    """
    Get maintenance protocols
    :return: list, module names
    """
    protocols = []
    protocols_path = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'maintenance_protocols')
    for model_name in os.listdir(protocols_path):
        if not model_name.endswith('.py') or model_name.startswith('_') or model_name.startswith('maintenance'):
            continue
        protocols.append(model_name.replace('.py', ''))
    return protocols


def error(message, jump_url='.', msg_title="error", status=0, wait_second=3):
    json_data = dict()
    json_data['msg_title'] = msg_title
    json_data['info'] = str(message)
    json_data['url'] = jump_url
    json_data['status'] = status
    json_data['wait_second'] = wait_second
    return JsonResponse(json_data)


def handle_uploaded_file(f):

    file_name = os.path.join(get_config('env', 'batch_job'), rand_sig()+'.txt')