Lines Matching refs:args
54 def start_replay_server(args, sites, discard_output=True):
58 generate_injection(f, sites, args.refresh)
59 http_port = 4080 + args.port_offset
60 https_port = 4443 + args.port_offset
62 args.replay_bin,
69 args.replay_wpr,
78 print("RUNNING REPLAY SERVER: %s with PID=%s" % (args.replay_bin, server.pid))
149 def get_chrome_replay_flags(args, arg_delimiter=""):
150 http_port = 4080 + args.port_offset
151 https_port = 4443 + args.port_offset
165 def run_site(site, domain, args, timeout=None):
169 result_template = "{domain}#{count}.txt" if args.repeat else "{domain}.txt"
171 if timeout is None: timeout = args.timeout
172 if args.replay_wpr:
173 timeout *= 1 + args.refresh
176 while count == 0 or args.repeat is not None and count < args.repeat:
180 while args.retries is None or retries < args.retries:
183 if args.user_data_dir:
184 user_data_dir = args.user_data_dir
188 if args.replay_wpr: js_flags += " --allow-natives-syntax"
189 if args.js_flags: js_flags += " " + args.js_flags
191 if args.replay_wpr:
192 chrome_flags += get_chrome_replay_flags(args)
195 if args.chrome_flags:
196 chrome_flags += args.chrome_flags.split()
199 args.with_chrome
205 with open(args.log_stderr or os.devnull, 'at') as err:
215 if args.print_url:
231 if not args.user_data_dir:
235 def read_sites_file(args):
239 with open(args.sites_file, "rt") as f:
244 if item['timeout'] > args.timeout: item['timeout'] = args.timeout
247 args.error("Warning: Could not read sites file as JSON, falling back to "
249 with open(args.sites_file, "rt") as f:
253 sites.append({'url': line, 'timeout': args.timeout})
256 args.error("Cannot read from {}. {}.".format(args.sites_file, e.strerror))
260 def read_sites(args):
262 if args.sites_file:
263 return read_sites_file(args)
264 return [{'url': site, 'timeout': args.timeout} for site in args.sites]
266 def do_run(args):
267 sites = read_sites(args)
268 replay_server = start_replay_server(args, sites) if args.replay_wpr else None
275 if args.domain:
276 domain = args.domain
282 args.error("Invalid URL {}.".format(site))
300 run_site(site, domain, args, timeout)
306 def do_run_replay_server(args):
307 sites = read_sites(args)
316 flags += get_chrome_replay_flags(args, "'")
319 replay_server = start_replay_server(args, sites, discard_output=False)
371 def read_stats(path, domain, args):
373 if args.aggregate:
439 def print_stats(S, args):
451 sort_func = sort_asc_func if args.sort == "asc" else sort_desc_func
456 if args.limit == 0:
458 elif args.sort == "desc":
459 low, high = 0, args.limit
461 low, high = N-args.limit, N
475 if args.totals and args.limit != 0 and not args.aggregate:
486 if args.totals:
488 if args.limit != 0 and not args.aggregate:
503 def do_stats(args):
505 for path in args.logfiles:
509 read_stats(path, domains[domain], args)
510 if args.aggregate:
511 create_total_page_stats(domains, args)
523 print_stats(domain_stats, args)
527 def create_total_page_stats(domains, args):
558 def _read_logs(args):
560 for path in args.logdirs:
570 versions[version][domain], args)
574 def do_raw_json(args):
575 versions = _read_logs(args)
578 if args.aggregate:
579 create_total_page_stats(domains, args)
598 def do_json(args):
599 versions = _read_logs(args)
602 if args.aggregate:
603 create_total_page_stats(domains, args)
622 def do_help(parser, subparsers, args):
623 if args.help_cmd:
624 if args.help_cmd in subparsers:
625 subparsers[args.help_cmd].print_help()
627 args.error("Unknown command '{}'".format(args.help_cmd))
763 func=lambda args: do_help(parser, subparsers, args),
770 args = parser.parse_args()
771 setattr(args, 'script_path', os.path.dirname(sys.argv[0]))
772 if args.command == "run" and coexist(args.sites_file, args.sites):
773 args.error("use either option --sites-file or site URLs")
775 elif args.command == "run" and not coexist(args.replay_wpr, args.replay_bin):
776 args.error("options --replay-wpr and --replay-bin must be used together")
779 args.func(args)