def ftp_init(): authentication = load_user_table() if authentication: handler = FTPHandler handler.authorizer = authentication server = FTPServer((get_config( 'env', 'ftp_addr'), int(get_config('env', 'ftp_port'))), handler) server.serve_forever() else: print('==Unable to Start BioQueue FTP Server==')
def run(self): while True: try: authentication = load_user_table() if authentication: handler = FTPHandler handler.authorizer = authentication server = FTPServer((get_config('env', 'ftp_addr'), int(get_config('env', 'ftp_port'))), handler) server.serve_forever() else: print '==Unable to Start BioQueue FTP Server==' except Exception, e: print e
def load_user_table(): try: all_user = User.objects.all() """ con, cur = con_mysql() sql = '''SELECT `id`, `username`, `password` FROM `auth_user` WHERE `is_active` > 0;''' cur.execute(sql) """ auth = DummyMD5Authorizer() ws = get_config('env', 'workspace') ''' for u in cur.fetchall(): user_directory = os.path.join(ws, str(u[0]), 'uploads') if not os.path.exists(user_directory): os.makedirs(user_directory) ''' for user in all_user: user_directory = os.path.join(ws, str(user.id), 'uploads') if not os.path.exists(user_directory): os.makedirs(user_directory) auth.add_user(user.username, user.password, user_directory, perm='elradfmw') return auth except Exception, e: print e return 0
def feedback_checkpoint(software, parameter, hash, cpu_a, cpu_b, cpu_r, mem_a, mem_b, mem_r, disk_a, disk_b, disk_r, mail=''): """ Feedback checkpoint :param software: string, software name :param parameter: string, parameter :param hash: string, hash :param cpu_a: float, cpu a :param cpu_b: float, cpu b :param cpu_r: float, cpu r :param mem_a: float, memory a :param mem_b: float, memory b :param mem_r: float, memory r :param disk_a: float, disk a :param disk_b: float, disk b :param disk_r: float, disk r :return: """ from ui.tools import os_to_int post_data_dict = dict() post_data_dict['cpu'] = get_config('env', 'cpu') post_data_dict['mem'] = get_config('env', 'memory') post_data_dict['os'] = os_to_int() post_data_dict['software'] = software post_data_dict['parameter'] = parameter post_data_dict['hash'] = hash post_data_dict['parent'] = 1 if abs(float(cpu_r)) > 0.5: post_data_dict['cpu_a'] = cpu_a post_data_dict['cpu_b'] = cpu_b post_data_dict['cpu_r'] = cpu_r if abs(float(mem_r)) > 0.5: post_data_dict['mem_a'] = mem_a post_data_dict['mem_b'] = mem_b post_data_dict['mem_r'] = mem_r if abs(float(disk_r)) > 0.5: post_data_dict['disk_a'] = disk_a post_data_dict['disk_b'] = disk_b post_data_dict['disk_r'] = disk_r try: fb_url = get_config('program', 'api', 1) + '/Gate/cb_feedback' t = requests.post(fb_url, data=post_data_dict, timeout=3) except: pass
def load_user_table(): try: all_user = User.objects.all() auth = DummyMD5Authorizer() ws = get_config('env', 'workspace') for user in all_user: user_directory = os.path.join(ws, str(user.id), 'uploads') if not os.path.exists(user_directory): os.makedirs(user_directory) auth.add_user(user.username, user.password, user_directory, perm='elradfmw') return auth except Exception, e: print e return 0
def check_version(): """ Compare local version with remote version, decide whether the instance needs to be updated. :return: int, 0 or 1 """ import requests remote_address = get_config('program', 'latest_version') try: res_data = requests.get(remote_address) remote_version = res_data.content local_version = get_bioqueue_version() if remote_version == local_version: return 0 else: return 1 except Exception as e: print(e) return 0
def feedback_error(software, parameter, error_message): """ Feedback error :param software: string, software name :param parameter: string, parameter :param error_message: string, error message :return: """ post_data_dict = { 'ver': get_bioqueue_version(), 'software': software, 'parameter': parameter, 'error': error_message, } try: fb_url = get_config('ml', 'api') + '/Gate/error_feedback' _ = requests.post(fb_url, data=post_data_dict, timeout=3) except: pass
def feedback(software, parameter, hash): """ Usage feedback :param software: :param parameter: :param hash: :return: """ ver = base64.b64encode(get_bioqueue_version()) software = base64.b64encode(software) parameter = base64.b64encode(parameter) get_data_dict = {'ver': base64.b64encode(get_bioqueue_version()), 'software': software, 'parameter': parameter} try: fb_url = get_config('ml', 'api') + '/Gate/feedback' _ = requests.get(fb_url, params=get_data_dict, timeout=3) except: pass
def feedback_protocol(user_mail, formatted_protocol): """ Feedback protocol :param user_mail: :param formatted_protocol: :return: """ import json post_data_dict = { 'email': user_mail, 'pro': formatted_protocol, } try: fb_url = get_config('program', 'api', 1) + '/Protocol/protocol_feedback' # _ = requests.post(fb_url, data=post_data_dict, timeout=5) data = requests.post(fb_url, data=post_data_dict, timeout=5) protocol_json = json.loads(data.text) return protocol_json except Exception as e: print(e) return None
raise AuthenticationFailed def load_user_table(): try: all_user = User.objects.all() auth = DummyMD5Authorizer() ws = get_config('env', 'workspace') for user in all_user: user_directory = os.path.join(ws, str(user.id), 'uploads') if not os.path.exists(user_directory): os.makedirs(user_directory) auth.add_user(user.username, user.password, user_directory, perm='elradfmw') return auth except Exception, e: print e return 0 if __name__ == "__main__": authentication = load_user_table() if authentication: handler = FTPHandler handler.authorizer = authentication server = FTPServer((get_config('env', 'ftp_addr'), int(get_config('env', 'ftp_port'))), handler) server.serve_forever() else: print '==Unable to Start BioQueue FTP Server=='