示例#1
0
def check(url):
    at, url, hostname = url.split('|')
    at = int(at)
    while True:
        current_ts = int(time())
        if current_ts < at:
            sleep(0.2)
        elif current_ts > at:
            LOG.debug('Aborted: %s - %s' % (at, url))
            return False
        else:
            break
    if hostname:
        cmd = 'curl -o /dev/null -w "code:%{http_code}\tsize:%{size_download}\tconnect:%{time_connect}\tttfb:%{time_starttransfer}\ttotal:%{time_total} \n" -H "Host: ' + hostname + '" ' + url
    else:
        cmd = 'curl -o /dev/null -w "code:%{http_code}\tsize:%{size_download}\tconnect:%{time_connect}\tttfb:%{time_starttransfer}\ttotal:%{time_total} \n" ' + url
    LOG.debug(cmd)
    output = getoutput(cmd)
    data = output.split('\n')[-1].split()
    info = dict()
    for i in data:
        key, value = i.split(':')
        if '.' in value:
            info[key] = round(float(value), 4)
        else:
            info[key] = int(value)
    info['url'] = url
    info['timestamp'] = at
    LOG.debug('Saved: %s - %s' % (current_ts, url))
    LOG.debug(info)
    api.save(info)
    return True
示例#2
0
def phase_scan(config, n_steps):
    for i in range(n_steps):
        phase = (pi / n_steps) * i
        print("\n\t-----------------------\n" \
            + "\n\t(%s) Analyzing phase %s\n" \
            + "\n\t-----------------------\n") % (i, phase)
        d = analysis(config, phase=phase)
        save(config, d)
示例#3
0
def phase_scan(config, n_steps):
    for i in range(n_steps):
        phase = (pi / n_steps) * i
        print("\n\t-----------------------\n" \
            + "\n\t(%s) Analyzing phase %s\n" \
            + "\n\t-----------------------\n") % (i, phase)
        d = analysis(config, phase=phase)
        save(config, d)
    def test_save_an_article(self, get_database_object, change,
                             transform_from_json, save_database_object,
                             transform_to_json, to_json):
        # def test_save_an_article(self, change):
        #when
        save({}, None)

        #verify get_database_object_invoked
        change.assert_called()
        get_database_object.assert_called()
        transform_from_json.assert_called()
        save_database_object.assert_called()
        transform_to_json.assert_called()
        to_json.assert_called()
示例#5
0
 def start(self, event):
     '''
     事件函数:开始执行按钮
     '''
     conf = {
         'uin': self.Ctrl_account.GetValue(),
         'pwd': self.Ctrl_password.GetValue(),
         'api': self.Ctrl_api.GetValue(),
         'id': self.Ctrl_id.GetValue(),
         'time': self.Ctrl_time.GetValue()
     }
     if self.check() is True:
         api.save(conf)
         self.conf = conf
         self.button_start.SetLabel("正在执行中...")
         self.button_start.Enable(False)
         Timer(0, self.taskPool, ()).start()
     else:
         pass
示例#6
0
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)
示例#7
0
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)