def backup_and_restore(fill, check, node_lists): """ Do one backup-restore cycle. """ lib.start() try: fill() paths = [] for node_list in node_lists: argument = ",".join([host + ":" + str(port) for host, port in node_list]) if lib.is_dir_mode(): path = lib.temporary_path("dir") lib.backup_to_directory(path, "--node-list", argument) else: path = lib.temporary_path("asb") lib.backup_to_file(path, "--node-list", argument) paths.append(path) lib.reset() for path in paths: if lib.is_dir_mode(): lib.restore_from_directory(path) else: lib.restore_from_file(path) check() except Exception: lib.stop(True) raise else: lib.stop()
import thread from lib.common import * from lib.start import * if __name__ == "__main__": try: CONFIG_INI = get_config() # 读取配置 log.write('info', None, 0, u'获取配置成功') STATISTICS = get_statistics() # 读取统计信息 MASSCAN_AC = [0] NACHANGE = [0] thread.start_new_thread(monitor, (CONFIG_INI, STATISTICS, NACHANGE)) # 心跳线程 thread.start_new_thread(cruise, (STATISTICS, MASSCAN_AC)) # 失效记录删除线程 socket.setdefaulttimeout(int(CONFIG_INI['Timeout']) / 2) # 设置连接超时 ac_data = [] now_time = time.localtime() now_hour = now_time.tm_hour now_day = now_time.tm_mday now_date = str(now_time.tm_year) + str(now_time.tm_mon) + str(now_day) cy_day, ac_hour = CONFIG_INI['Cycle'].split('|') log.write('info', None, 0, u'扫描规则: ' + str(CONFIG_INI['Cycle'])) ac_data.append(now_date) NACHANGE[0] = 0 log.write('info', None, 0, u'开始扫描') s = start(CONFIG_INI) s.masscan_ac = MASSCAN_AC s.statistics = STATISTICS s.run() print('done~~~~') except Exception, e: print e
def index(): if request.method == 'POST': now_datetime = datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S') # now_datetime = '' upload_path = os.path.join(app.config['UPLOAD_FOLDER'], now_datetime) # upload_path = app.config['UPLOAD_FOLDER'] if not os.path.exists(upload_path): os.makedirs(upload_path) # 判断文件 if 'trainingData' not in request.files: raise Exception('没有trainingData.txt') # return Response(json.dumps({'code': 500, 'msg': '没有选择文件'}), 500) # 获取上传的文件 training_data = request.files['trainingData'] prediction_data = request.files.get('predictionData', None) prediction_data_annotated = request.files.get( 'predictionData_Annotated', None) training_data_path = os.path.join(upload_path, training_data.filename) training_data.save(training_data_path) # 判断是否有predictionData文件 prediction_data_path = os.path.join(upload_path, 'predictionData.txt') if prediction_data: prediction_data_path = os.path.join(upload_path, prediction_data.filename) prediction_data.save(prediction_data_path) if not os.path.exists(prediction_data_path): raise Exception('没有predictionData.txt') # 判断是否有predictionData_Annotated文件 prediction_data_annotated_path = os.path.join( upload_path, 'predictionData_Annotated.txt') if prediction_data_annotated: prediction_data_annotated_path = os.path.join( upload_path, prediction_data_annotated.filename) prediction_data_annotated.save(prediction_data_annotated_path) if not os.path.exists(prediction_data_annotated_path): raise Exception('没有predictionData_Annotated.txt') lib.resultDic = lib.sourceDic + "static/results/" + now_datetime + '/' # 开始执行文件 lib.start(training_data_path, prediction_data_path, prediction_data_annotated_path) results = [] with open(lib.resultDic + 'miRLocator_predResults.txt', 'r') as result_file: # 获取转换后的文件内容 lines = result_file.readlines() # 把每行的内容转化为html for i, line in enumerate(lines): # 获取文件名 mi_rna = line.split('\t')[0] png_url = '{path}/{name}.png'.format(path=os.path.join( 'static/results', now_datetime, 'dp_ss_pred'), name=mi_rna) png_path = os.path.join(__dir__, png_url) # 获取需要生成的html地址 html_url = '{path}/{name}.html'.format(path=os.path.join( 'static/results', now_datetime, 'dp_ss_pred'), name=mi_rna) html_path = os.path.join(__dir__, html_url) tmp = { 'mi_rna': mi_rna, 'line': line.split('\t'), 'img_url': '{}.png'.format(mi_rna), 'html_url': '/' + html_url } line_maps = [ '第一行'.decode('utf-8'), '第二行'.decode('utf-8'), '第三行'.decode('utf-8'), '第四行'.decode('utf-8') ] page_param = dict(line_maps=line_maps, **tmp) # 输出html context = render_template('pages.html', **page_param) try: with open(html_path, 'w') as html: html.write(context.encode('utf-8')) pass except Exception as e: raise e # 转化图片 try: call([ 'convert', '{path}/{file_name}'.format( path=os.path.join(lib.resultDic, 'dp_ss_pred'), file_name=mi_rna + '_ss.ps'), png_path ]) except OSError as e: if e.errno == os.errno.ENOENT: raise Exception('没有安装imagemagick') raise e except Exception as e: raise e results.append(tmp) # 打包结果 zip_file_path = os.path.join(lib.resultDic, 'results.zip') lib.zipdir(lib.resultDic, zip_file_path) return jsonify({ 'lines': results, 'zip_file_path': '/static/results/' + now_datetime + '/results.zip', }) else: # 显示首页 return render_template('index.html')
parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--cID', type=str, dest='calendarId', action='store', help='calendarId') #parser.add_argument('--from', type=str, dest='startDay', action='store',help='start date', required=True) #parser.add_argument('--to', type=str, dest='endDay', action='store',help='end date', required=True) parser.add_argument('--name', type=str, dest='name', action='store',help='truck name', required=True) parser.add_argument('--url', type=str, dest='url', action='store',help='website url') args = parser.parse_args() total = 0 fail = 0 skip = 0 success = 0 lib.start(args.name, args.url) calendarId = args.calendarId if not calendarId: url = args.url html = lib.get_url_content(url) if html == "": lib.finish(args.name, args.url) google_calendar_pattern = re.compile(r'https://www.google.com/calendar.*?src=(?P<cID>[0-9a-zA-Z].*?((%40)|@).*?\.com)') try: calendarId = google_calendar_pattern.search(html).groupdict()['cID'].replace("%40", "@") except Exception, e: lib.print_error("fail to get calendar ID")
date = "start" name = raw_input('Enter Truck name: (enter / to stop) ') if name == "/": break ret_name = [] if lib.check_truck_name(name, ret_name) == False: print "ERROR: Unknown truck name %s" % name continue name =ret_name[0] skip = 0 total = 0 fail = 0 success = 0 sys.stdout = log_file lib.start(name, "") sys.stdout = old_stdout while date != "/": while True: date = raw_input("Enter date (yymmdd) (enter / to stop this truck)") if date == "/": sys.stdout = log_file lib.finish(name = name, url = "null", total=total, fail = fail, skip = skip, success = success, exit = False) sys.stdout = old_stdout break input_date = date date = "20" + date[:2]+"-" + date[2:4] + "-" + date[4:] try: datetime.strptime(date, '%Y-%m-%d') except:
from lib.start import * if __name__ == "__main__": try: CONFIG_INI = get_config() # 读取配置 log.write('info', None, 0, u'获取配置成功') STATISTICS = get_statistics() # 读取统计信息 MASSCAN_AC = [0] NACHANGE = [0] thread.start_new_thread(monitor, (CONFIG_INI,STATISTICS,NACHANGE)) # 心跳线程 thread.start_new_thread(cruise, (STATISTICS,MASSCAN_AC)) # 失效记录删除线程 socket.setdefaulttimeout(int(CONFIG_INI['Timeout']) / 2) # 设置连接超时 ac_data = [] while True: now_time = time.localtime() now_hour = now_time.tm_hour now_day = now_time.tm_mday now_date = str(now_time.tm_year) + str(now_time.tm_mon) + str(now_day) cy_day, ac_hour = CONFIG_INI['Cycle'].split('|') log.write('info', None, 0, u'扫描规则: ' + str(CONFIG_INI['Cycle'])) if (now_hour == int(ac_hour) and now_day % int(cy_day) == 0 and now_date not in ac_data) or NACHANGE[0]: # 判断是否进入扫描时段 ac_data.append(now_date) NACHANGE[0] = 0 log.write('info', None, 0, u'开始扫描') s = start(CONFIG_INI) s.masscan_ac = MASSCAN_AC s.statistics = STATISTICS s.run() time.sleep(60) except Exception, e: print e
try: datetime.strptime(end_time, '%H%M') except: print "ERROR: incorrect end_time " + end_time continue break if end_time <= start_time: print "ERROR: end_time %s is smaller than start_time %s" % ( end_time, start_time) continue else: break address = raw_input("Enter address (better to be formatted)") sys.stdout = log_file lib.start(event_name, "") sys.stdout = old_stdout start_time = start_time[:2] + ":" + start_time[2:] + ":00" end_time = end_time[:2] + ":" + end_time[2:] + ":00" while name != "/": name = raw_input('Enter Truck name: (enter / to stop) ') if name == "/": break ret_name = [] if lib.check_truck_name(name, ret_name) == False: print "ERROR: Unknown truck name %s" % name continue name = ret_name[0] total += 1
date = "start" name = raw_input('Enter Truck name: (enter / to stop) ') if name == "/": break ret_name = [] if lib.check_truck_name(name, ret_name) == False: print "ERROR: Unknown truck name %s" % name continue name = ret_name[0] skip = 0 total = 0 fail = 0 success = 0 sys.stdout = log_file lib.start(name, "") sys.stdout = old_stdout while date != "/": while True: date = raw_input( "Enter date (yymmdd) (enter / to stop this truck)") if date == "/": sys.stdout = log_file lib.finish(name=name, url="null", total=total, fail=fail, skip=skip, success=success, exit=False) sys.stdout = old_stdout
action='store', help='truck name', required=True) parser.add_argument('--url', type=str, dest='url', action='store', help='website url') args = parser.parse_args() total = 0 fail = 0 skip = 0 success = 0 lib.start(args.name, args.url) calendarId = args.calendarId if not calendarId: url = args.url html = lib.get_url_content(url) if html == "": lib.finish(args.name, args.url) google_calendar_pattern = re.compile( r'https://www.google.com/calendar.*?src=(?P<cID>[0-9a-zA-Z].*?((%40)|@).*?\.com)' ) try: calendarId = google_calendar_pattern.search(
import lib lib.start()
end_time = raw_input("Enter end time (hhmm like 1330 or 0900)") try: datetime.strptime(end_time, '%H%M') except: print "ERROR: incorrect end_time " + end_time continue break if end_time <= start_time: print "ERROR: end_time %s is smaller than start_time %s" % (end_time,start_time) continue else: break address = raw_input("Enter address (better to be formatted)") sys.stdout = log_file lib.start(event_name, "") sys.stdout = old_stdout start_time = start_time[:2] + ":" + start_time[2:] + ":00" end_time = end_time[:2] + ":" + end_time[2:] + ":00" while name != "/": name = raw_input('Enter Truck name: (enter / to stop) ') if name == "/": break ret_name = [] if lib.check_truck_name(name, ret_name) == False: print "ERROR: Unknown truck name %s" % name continue name = ret_name[0] total += 1