def subscription(): api.load_config() s = request.forms.get("subscription") subscription = [] if request.forms.get("default"): for ea in api.echoareas: subscription.append(ea[0]) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') redirect("/") if s: for ea in s.strip().replace("\r", "").split("\n"): if api.echo_filter(ea): subscription.append(ea) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') redirect("/") subscription = request.get_cookie("subscription", secret='some-secret-key') echoareas = [] for echoarea in api.echoareas: echoareas.append( [echoarea[0], api.get_echoarea_count(echoarea[0]), echoarea[1]]) return template("tpl/subscription.tpl", nodename=api.nodename, dsc=api.nodedsc, echoareas=echoareas, subscription=subscription, background=api.background)
def index(): api.load_config() echoareas = [] s = request.get_cookie("subscription", secret='some-secret-key') if not s: subscription = [] for ea in api.echoareas: subscription.append(ea[0]) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') s = subscription if api.nosubscription: subscription = api.echoareas else: subscription = [] for ea in s: flag = False for e in api.echoareas: if ea in e: flag = True subscription.append(e) if not flag: subscription.append([ea, ""]) ea = [[echoarea[0], echoarea[1], api.get_time(echoarea[0])] for echoarea in subscription] for echoarea in sorted(ea, key=lambda ea: ea[2], reverse=True)[0:5]: last = request.get_cookie(echoarea[0], secret='some-secret-key') if not last in api.get_echo_msgids(echoarea[0]): last = False if not last or len(last) == 0: last = api.get_last_msgid(echoarea[0]) if last and len(last) > 0: page = get_page(api.get_echoarea(echoarea[0]).index(last)) else: page = get_page(len(api.get_echoarea(echoarea[0]))) echoareas.append({ "echoname": echoarea[0], "count": api.get_echoarea_count(echoarea[0]), "dsc": echoarea[1], "msg": api.get_last_msg(echoarea[0]), "last": last, "page": page }) allechoareas = echoes(subscription) auth = request.get_cookie("authstr") msgfrom, addr = points.check_point(auth) return template("tpl/index.tpl", nodename=api.nodename, dsc=api.nodedsc, echoareas=echoareas, allechoareas=allechoareas, addr=addr, auth=auth, background=api.background, nosubscription=api.nosubscription)
def x_small_echolist(): write_to_log("x/small-echolist") response.set_header("content-type", "text/plain; charset=utf-8") api.load_config() echoareas = api.echoareas echoareas = echoareas + api.shortareas echolist = "" for echoarea in sorted(echoareas, key=lambda echoareas: echoareas[0]): echolist = echolist + echoarea[0] + "\n" return echolist
def x_caesium(): write_to_log("x/caesium") response.set_header("content-type", "text/plain; charset=utf-8") api.load_config() echoareas = api.echoareas echoareas = echoareas +api.shortareas echolist = "" for echoarea in sorted(echoareas, key=lambda echoareas: echoareas[0]): echolist = echolist + "echo %s %s\n" % (echoarea[0], echoarea[1]) return echolist
def x_small_echolist(): write_to_log("x/small-echolist") response.set_header("content-type", "text/plain; charset=utf-8") api.load_config() echoareas = api.echoareas echoareas = echoareas + api.shortareas echolist = "" for echoarea in sorted(echoareas, key=lambda echoareas: echoareas[0]): echolist = echolist + echoarea[0] + "\n" return echolist
def x_caesium(): write_to_log("x/caesium") response.set_header("content-type", "text/plain; charset=utf-8") api.load_config() echoareas = api.echoareas echoareas = echoareas + api.shortareas echolist = "" for echoarea in sorted(echoareas, key=lambda echoareas: echoareas[0]): echolist = echolist + "echo %s %s\n" % (echoarea[0], echoarea[1]) return echolist
def showmsg(msgid): api.load_config() if api.msg_filter(msgid): body = api.get_msg(msgid).split("\n") if body != [""]: msgfrom, addr = points.check_point(request.get_cookie("authstr")) kludges = body[0].split("/") if "repto" in kludges: repto = kludges[kludges.index("repto") + 1] else: repto = False if len(body) > 0: echoarea = [ea for ea in api.echoareas if ea[0] == body[1]] if len(echoarea) == 0: echoarea = [body[1], ""] else: echoarea = echoarea[0] else: echoarea = ["", ""] t = api.formatted_time(body[2]) point = body[3] address = body[4] to = body[5] subj = body[6] body = body[8:] index = api.get_echoarea(echoarea[0]) current = index.index(msgid) response.set_cookie(echoarea[0], msgid, max_age=180 * 24 * 60 * 60, secret='some-secret-key') auth = request.get_cookie("authstr") return template("tpl/message.tpl", nodename=api.nodename, echoarea=echoarea, index=index, msgid=msgid, repto=repto, current=current, time=t, point=point, address=address, to=to, subj=subj, body=body, msgfrom=msgfrom, background=api.background, auth=auth) else: redirect("/") else: redirect("/")
def rss(echoarea): response.set_header("content-type", "application/rss+xml; charset=utf-8") api.load_config() msglist = api.get_echoarea(echoarea) msgs = [] for msgid in msglist[-50:]: msgs.append([msgid, api.get_msg(msgid).split("\n")]) return template("tpl/rss.tpl", nodename=api.nodename, dsc=api.nodedsc, nodeurl=api.nodeurl, msgs=reversed(msgs), echoarea=echoarea)
def menu_load_config_action(self): self.change_gui_state('off') self.log_text.delete('1.0', tk.END) # toplevel = tk.Toplevel() file_opts = { 'defaultextension': '.ini', 'initialdir': os.curdir, 'initialfile': 'config.ini', # 'parent': toplevel, 'parent': self.root, 'title': 'Select a configuration file to load.', } file_path = tkFileDialog.askopenfilename(**file_opts) # toplevel.destroy() if file_path == '' or file_path is None: self.change_gui_state('on') return None config = load_config(file_path, logger_name=self.logger_name) if config is None: self.change_gui_state('on') return None self.config = config self.update_entries_from_config() self.change_gui_state('on') return None
def ffeed(echoarea, msgid, page): api.load_config() msglist = api.get_echoarea(echoarea) result = [] last = request.get_cookie(echoarea, secret='some-secret-key') if not last in api.get_echoarea(echoarea): last = False if not last or len(last) == 0: last = api.get_last_msgid(echoarea) if not page: if not last: page = get_page(len(msglist)) if page == 0: page = 1 else: page = get_page(msglist.index(last)) page = int(page) start = page * 50 - 50 end = start + 50 for mid in msglist[start:end]: msg = api.get_msg(mid).split("\n") if len(msg) > 1: result.append([mid, msg]) ea = [ea for ea in api.echoareas if ea[0] == echoarea] if len(ea) != 1: ea = [echoarea, ""] else: ea = ea[0] auth = request.get_cookie("authstr") if len(msglist) <= end: end = api.get_last_msgid(echoarea) else: end = msglist[end] response.set_cookie(echoarea, end, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') return template("tpl/feed.tpl", nodename=api.nodename, dsc=api.nodedsc, echoarea=ea, page=page, msgs=result, msgid=msgid, background=api.background, auth=auth)
def msg_list(echoarea, page=False, msgid=False): api.load_config() msglist = api.get_echoarea(echoarea) result = [] for mid in msglist: msg = api.get_msg(mid).split("\n") try: subject = msg[6] f = msg[3] t = msg[5] result.append({ "msgid": mid, "subject": subject, "from": f, "to": t }) except: None ea = [ea for ea in api.echoareas if ea[0] == echoarea] if len(ea) == 0: ea = [echoarea, ''] else: ea = ea[0] if not page: if not msgid: page = get_page(len(msglist)) else: page = get_page(msglist.index(msgid)) if page == 0: page = 1 return template("tpl/msglist.tpl", nodename=api.nodename, dsc=api.nodedsc, page=int(page), echoarea=ea, msgid=msgid, msglist=result, topiclist=False, background=api.background)
def echolist(): api.load_config() echoareas = [] s = request.get_cookie("subscription", secret='some-secret-key') if not s: subscription = [] for ea in api.echoareas: subscription.append(ea[0]) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') s = subscription if api.nosubscription: subscription = api.echoareas else: subscription = [] for ea in s: flag = False for e in api.echoareas: if ea in e: flag = True subscription.append(e) if not flag: subscription.append([ea, ""]) allechoareas = echoes(subscription) auth = request.get_cookie("authstr") msgfrom, addr = points.check_point(auth) return template("tpl/echolist.tpl", nodename=api.nodename, dsc=api.nodedsc, allechoareas=allechoareas, addr=addr, auth=auth, background=api.background, nosubscription=api.nosubscription)
def generate_message(filename): "Generate message for sending by filename." echoarea = filename.split("/")[1] message = read_message(filename) return "{0}\n{1}".format(echoarea, "\n".join(message)) def encode_message(message): "Base64 encode of message." return base64.b64encode(message.encode("utf-8")) def send_mail(): "Send all new message to uplink." global node, auth for filename in find_new_messages(): message = generate_message(filename) encoded = encode_message(message) data = {"pauth": api.auth, "tmsg": encoded} try: requests.post(api.node + "u/point", data=data) except requests.exceptions.RequestException as exception: print("\n\n{}".format(exception)) sys.exit(1) os.remove(filename) api.load_config() send_mail()
def test_get_weather2(self): api.load_config() result = api.get_weather("1234567") self.assertEqual(result['cod'], "404")
def test_get_weather1(self): api.load_config() result = api.get_weather("3448433") self.assertEqual(result['name'], "São Paulo")
def test_request_and_store2(self): api.load_config() result = api.request_and_store("1234567") self.assertEqual(result['cod'], "404")
def test_request_and_store1(self): api.load_config() result = api.request_and_store("3448433") self.assertEqual(result['name'], "São Paulo")
def run_with_optlist(optlist): if len(optlist) == 0: return print_help() opts = { 'config-file': None, 'gui-mode': False, 'logging-level': 'info', 'phase': None, 'load-data': False, 'load-data-from': None, 'save-data': False, #'save-data-at': None, 'show-plot': False, } for opt, arg in optlist: if (opt == '-h' or opt == '--help'): return print_help() elif (opt == '-c' or opt == '--config-file'): opts['config-file'] = arg elif (opt == '-g' or opt == '--gui-mode'): opts['gui-mode'] = eval(arg) elif (opt == '-l' or opt == '--logging_level'): opts['logging-level'] = arg elif (opt == '-p' or opt == '--phase'): # Generate a single K-wall network at a phase opts['phase'] = float(arg) elif opt == '--load-data': opts['load-data'] = True elif opt == '--load-data-from': opts['load-data-from'] = arg elif opt == '--save-data': opts['save-data'] = True #elif opt == '--save-data-at': # opts['save-data-at'] = arg elif opt == '--show-plot': opts['show-plot'] = True # End of option setting. set_logging(opts['logging-level']) if opts['gui-mode'] is True: return open_gui(config, data) # Load config & data. if opts['load-data'] is True: # Load config & data using a file dialog. config, data = load() if data is None: return None elif opts['load-data-from'] is not None: # Load config & data according to the command line args. data_dir = opts['load-data-from'] config, data = load(data_dir) else: # Read in the specified config file. config = load_config(opts['config-file']) if config is None: return None data = None if data is None: data = analysis( config, phase=opts['phase'], ) if (opts['show-plot'] is True # (opts['show-plot'] or opts['save-data']) is True #or (opts['save-data-at'] is not None) ): k_wall_network_plot, ms_wall_plot = make_plots( config, data, show_plot=opts['show-plot'], ) if opts['save-data'] is True: #save(config, data, k_wall_network_plot, ms_wall_plot) save(config, data, open_dialog=False)
os.remove("./temp") else: return "error: no auth" else: return "incorrect file echoarea" @route("/f/blacklist.txt") def file_blacklist(): write_to_log("f/blacklist.txt") response.set_header("content-type", "text/plain; charset=utf-8") return open("fblacklist.txt", "r").read() @route("/f/list.txt") def felist(): write_to_log("f/list.tx") response.set_header("content-type", "text/plain; charset=utf-8") ret = "" for fecho in api.fechoareas: flen = len(open("fecho/%s" % fecho[0], "r").read().split("\n")) - 1 ret = ret + fecho[0] + ":" + str(flen) + ":" + fecho[1] + "\n" return ret api.check_config() api.load_config() api.init() if api.web_interface: from api.web import * run(host="0.0.0.0", port=3000)#, quiet=True)
import api import time test, thr = api.load_config() api.trap_server_init() api.slack_server_init() while len(api.users) < test['min_users']: time.sleep(5) api.waiting = False api.running = True print('[Main] Starting the test... (UID: ' + api.test_id + ')') for user in api.users: ip = user['ip'] domain = user['slack'] + '@' + user['ip'] user['discard'] = [] discard = False api.trap_config(ip) print('[Main] Starting analysis for', domain) print('[Main] Getting device information for ' + domain + '...') static_data = api.get_static_data(ip) if static_data['cpu_cores'] < thr['cpu_thr']: discard = True user['discard'].append({"cpu_cores": static_data['cpu_cores']}) print('[DISCARD] ' + domain + ' has cpu_cores < ', thr['cpu_thr']) if static_data['installed_ram'] < thr['ram_thr']: discard = True
#!/usr/bin/env python # -*- coding: utf-8 -*- import logging from datetime import datetime from playhouse.migrate import * from peewee import ProgrammingError from api import load_config config = load_config() db = PostgresqlDatabase(**config['DB_CONFIG']) migrator = PostgresqlMigrator(db) logger = logging.getLogger('sanic') class MigrationRecord(Model): id = PrimaryKeyField() table = CharField() version = CharField() author = CharField() create_time = DateTimeField(verbose_name='创建时间', default=datetime.utcnow()) class Meta: table_name = 'migration_record' database = db def info(version=None, author=None, datetime=None):
def run_with_optlist(optlist): if len(optlist) == 0: return print_help() opts = { 'config-file': None, 'gui-mode': False, 'logging-level': 'info', 'phase': None, 'load-data': False, 'load-data-from': None, 'save-data': False, #'save-data-at': None, 'show-plot': False, } for opt, arg in optlist: if (opt == '-h' or opt == '--help'): return print_help() elif (opt == '-c' or opt == '--config-file'): opts['config-file'] = arg elif (opt == '-g' or opt == '--gui-mode'): opts['gui-mode'] = eval(arg) elif (opt == '-l' or opt == '--logging_level'): opts['logging-level'] = arg elif (opt == '-p' or opt == '--phase'): # Generate a single K-wall network at a phase opts['phase'] = float(arg) elif opt == '--load-data': opts['load-data'] = True elif opt == '--load-data-from': opts['load-data-from'] = arg elif opt == '--save-data': opts['save-data'] = True #elif opt == '--save-data-at': # opts['save-data-at'] = arg elif opt == '--show-plot': opts['show-plot'] = True # End of option setting. set_logging(opts['logging-level']) if opts['gui-mode'] is True: return open_gui(config, data) # Load config & data. if opts['load-data'] is True: # Load config & data using a file dialog. config, data = load() if data is None: return None elif opts['load-data-from'] is not None: # Load config & data according to the command line args. data_dir = opts['load-data-from'] config, data = load(data_dir) else: # Read in the specified config file. config = load_config(opts['config-file']) if config is None: return None data = None if data is None: data = analysis(config, phase=opts['phase'],) if ( opts['show-plot'] is True # (opts['show-plot'] or opts['save-data']) is True #or (opts['save-data-at'] is not None) ): k_wall_network_plot, ms_wall_plot = make_plots( config, data, show_plot=opts['show-plot'], ) if opts['save-data'] is True: #save(config, data, k_wall_network_plot, ms_wall_plot) save(config, data, open_dialog=False)
def __init__( self, config_file_path, logging_level, ): root = tk.Tk() root.wm_title('loom') # Put the window at the center. ws = root.winfo_screenwidth() hs = root.winfo_screenheight() root.geometry('+{}+{}'.format(ws / 2, hs / 2)) # Tkinter root self.root = root # Logging handling self.logging_queue = multiprocessing.Queue() self.logger_name = 'gui_loom' set_logging( logger_name=self.logger_name, logging_level=logging_level, logging_queue=self.logging_queue, logging_file_name=LOGGING_FILE_PATH, ) self.logging_stream = StringIO() self.logging_stream_handler = get_logging_handler( logging_level, logging.StreamHandler, self.logging_stream, ) # Load default config. self.config = load_config(config_file_path, logger_name=self.logger_name) self.entry = {} self.entry_var = {} self.mb = None self.check = {} self.button = {} self.sw_data = None self.spectral_networks = [] # Array of config options. # Entries that will be placed in the same row # are in the same row of this array. self.entry_array = [ ['description'], ['root_system', 'representation'], ['casimir_differentials'], ['differential_parameters'], ['regular_punctures'], ['irregular_punctures'], ['branch_points'], ['ramification_points'], ['ramification_point_finding_method'], ['mt_params'], ['plot_range'], ['num_of_steps'], ['num_of_iterations'], ['size_of_small_step'], ['size_of_large_step'], ['size_of_bp_neighborhood'], ['size_of_puncture_cutoff'], ['accuracy'], ['mass_limit'], ['phase'], ]