replay.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. #!/usr/bin/env python
  2. # Copyright 2010 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """Replays web pages under simulated network conditions.
  16. Must be run as administrator (sudo).
  17. To record web pages:
  18. 1. Start the program in record mode.
  19. $ sudo ./replay.py --record archive.wpr
  20. 2. Load the web pages you want to record in a web browser. It is important to
  21. clear browser caches before this so that all subresources are requested
  22. from the network.
  23. 3. Kill the process to stop recording.
  24. To replay web pages:
  25. 1. Start the program in replay mode with a previously recorded archive.
  26. $ sudo ./replay.py archive.wpr
  27. 2. Load recorded pages in a web browser. A 404 will be served for any pages or
  28. resources not in the recorded archive.
  29. Network simulation examples:
  30. # 128KByte/s uplink bandwidth, 4Mbps/s downlink bandwidth with 100ms RTT time
  31. $ sudo ./replay.py --up 128KByte/s --down 4Mbit/s --delay_ms=100 archive.wpr
  32. # 1% packet loss rate
  33. $ sudo ./replay.py --packet_loss_rate=0.01 archive.wpr
  34. """
  35. import argparse
  36. import json
  37. import logging
  38. import os
  39. import socket
  40. import sys
  41. import traceback
  42. import customhandlers
  43. import dnsproxy
  44. import httparchive
  45. import httpclient
  46. import httpproxy
  47. import net_configs
  48. import platformsettings
  49. import rules_parser
  50. import script_injector
  51. import servermanager
  52. import trafficshaper
  53. if sys.version < '2.6':
  54. print 'Need Python 2.6 or greater.'
  55. sys.exit(1)
  56. def configure_logging(log_level_name, log_file_name=None):
  57. """Configure logging level and format.
  58. Args:
  59. log_level_name: 'debug', 'info', 'warning', 'error', or 'critical'.
  60. log_file_name: a file name
  61. """
  62. if logging.root.handlers:
  63. logging.critical('A logging method (e.g. "logging.warn(...)")'
  64. ' was called before logging was configured.')
  65. log_level = getattr(logging, log_level_name.upper())
  66. log_format = (
  67. '(%(levelname)s) %(asctime)s %(module)s.%(funcName)s:%(lineno)d '
  68. '%(message)s')
  69. logging.basicConfig(level=log_level, format=log_format)
  70. logger = logging.getLogger()
  71. if log_file_name:
  72. fh = logging.FileHandler(log_file_name)
  73. fh.setLevel(log_level)
  74. fh.setFormatter(logging.Formatter(log_format))
  75. logger.addHandler(fh)
  76. system_handler = platformsettings.get_system_logging_handler()
  77. if system_handler:
  78. logger.addHandler(system_handler)
  79. def AddDnsForward(server_manager, host):
  80. """Forward DNS traffic."""
  81. server_manager.Append(platformsettings.set_temporary_primary_nameserver, host)
  82. def AddDnsProxy(server_manager, options, host, port, real_dns_lookup,
  83. http_archive):
  84. dns_filters = []
  85. if options.dns_private_passthrough:
  86. private_filter = dnsproxy.PrivateIpFilter(real_dns_lookup, http_archive)
  87. dns_filters.append(private_filter)
  88. server_manager.AppendRecordCallback(private_filter.InitializeArchiveHosts)
  89. server_manager.AppendReplayCallback(private_filter.InitializeArchiveHosts)
  90. if options.shaping_dns:
  91. delay_filter = dnsproxy.DelayFilter(options.record, **options.shaping_dns)
  92. dns_filters.append(delay_filter)
  93. server_manager.AppendRecordCallback(delay_filter.SetRecordMode)
  94. server_manager.AppendReplayCallback(delay_filter.SetReplayMode)
  95. server_manager.Append(dnsproxy.DnsProxyServer, host, port,
  96. dns_lookup=dnsproxy.ReplayDnsLookup(host, dns_filters))
  97. def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive):
  98. if options.rules_path:
  99. with open(options.rules_path) as file_obj:
  100. allowed_imports = [
  101. name.strip() for name in options.allowed_rule_imports.split(',')]
  102. rules = rules_parser.Rules(file_obj, allowed_imports)
  103. logging.info('Parsed %s rules:\n%s', options.rules_path, rules)
  104. else:
  105. rules = rules_parser.Rules()
  106. injector = script_injector.GetScriptInjector(options.inject_scripts)
  107. custom_handlers = customhandlers.CustomHandlers(options, http_archive)
  108. custom_handlers.add_server_manager_handler(server_manager)
  109. archive_fetch = httpclient.ControllableHttpArchiveFetch(
  110. http_archive, real_dns_lookup,
  111. injector,
  112. options.diff_unknown_requests, options.record,
  113. use_closest_match=options.use_closest_match,
  114. scramble_images=options.scramble_images)
  115. server_manager.AppendRecordCallback(archive_fetch.SetRecordMode)
  116. server_manager.AppendReplayCallback(archive_fetch.SetReplayMode)
  117. allow_generate_304 = not options.record
  118. server_manager.Append(
  119. httpproxy.HttpProxyServer,
  120. archive_fetch, custom_handlers, rules,
  121. host=host, port=options.port, use_delays=options.use_server_delay,
  122. allow_generate_304=allow_generate_304,
  123. **options.shaping_http)
  124. if options.ssl:
  125. if options.should_generate_certs:
  126. server_manager.Append(
  127. httpproxy.HttpsProxyServer, archive_fetch, custom_handlers, rules,
  128. options.https_root_ca_cert_path, host=host, port=options.ssl_port,
  129. allow_generate_304=allow_generate_304,
  130. use_delays=options.use_server_delay, **options.shaping_http)
  131. else:
  132. server_manager.Append(
  133. httpproxy.SingleCertHttpsProxyServer, archive_fetch,
  134. custom_handlers, rules, options.https_root_ca_cert_path, host=host,
  135. port=options.ssl_port, use_delays=options.use_server_delay,
  136. allow_generate_304=allow_generate_304,
  137. **options.shaping_http)
  138. if options.http_to_https_port:
  139. server_manager.Append(
  140. httpproxy.HttpToHttpsProxyServer,
  141. archive_fetch, custom_handlers, rules,
  142. host=host, port=options.http_to_https_port,
  143. use_delays=options.use_server_delay,
  144. allow_generate_304=allow_generate_304,
  145. **options.shaping_http)
  146. def AddTrafficShaper(server_manager, options, host):
  147. if options.shaping_dummynet:
  148. server_manager.AppendTrafficShaper(
  149. trafficshaper.TrafficShaper, host=host,
  150. use_loopback=not options.server_mode and host == '127.0.0.1',
  151. **options.shaping_dummynet)
  152. class OptionsWrapper(object):
  153. """Add checks, updates, and methods to option values.
  154. Example:
  155. options, args = arg_parser.parse_args()
  156. options = OptionsWrapper(options, arg_parser) # run checks and updates
  157. if options.record and options.HasTrafficShaping():
  158. [...]
  159. """
  160. _TRAFFICSHAPING_OPTIONS = {
  161. 'down', 'up', 'delay_ms', 'packet_loss_rate', 'init_cwnd', 'net'}
  162. _CONFLICTING_OPTIONS = (
  163. ('record', ('down', 'up', 'delay_ms', 'packet_loss_rate', 'net',
  164. 'spdy', 'use_server_delay')),
  165. ('append', ('down', 'up', 'delay_ms', 'packet_loss_rate', 'net',
  166. 'use_server_delay')), # same as --record
  167. ('net', ('down', 'up', 'delay_ms')),
  168. ('server', ('server_mode',)),
  169. )
  170. def __init__(self, options, parser):
  171. self._options = options
  172. self._parser = parser
  173. self._nondefaults = set([
  174. action.dest for action in parser._optionals._actions
  175. if getattr(options, action.dest, action.default) is not action.default])
  176. self._CheckConflicts()
  177. self._CheckValidIp('host')
  178. self._CheckFeatureSupport()
  179. self._MassageValues()
  180. def _CheckConflicts(self):
  181. """Give an error if mutually exclusive options are used."""
  182. for option, bad_options in self._CONFLICTING_OPTIONS:
  183. if option in self._nondefaults:
  184. for bad_option in bad_options:
  185. if bad_option in self._nondefaults:
  186. self._parser.error('Option --%s cannot be used with --%s.' %
  187. (bad_option, option))
  188. def _CheckValidIp(self, name):
  189. """Give an error if option |name| is not a valid IPv4 address."""
  190. value = getattr(self._options, name)
  191. if value:
  192. try:
  193. socket.inet_aton(value)
  194. except Exception:
  195. self._parser.error('Option --%s must be a valid IPv4 address.' % name)
  196. def _CheckFeatureSupport(self):
  197. if (self._options.should_generate_certs and
  198. not platformsettings.HasSniSupport()):
  199. self._parser.error('Option --should_generate_certs requires pyOpenSSL '
  200. '0.13 or greater for SNI support.')
  201. def _ShapingKeywordArgs(self, shaping_key):
  202. """Return the shaping keyword args for |shaping_key|.
  203. Args:
  204. shaping_key: one of 'dummynet', 'dns', 'http'.
  205. Returns:
  206. {} # if shaping_key does not apply, or options have default values.
  207. {k: v, ...}
  208. """
  209. kwargs = {}
  210. def AddItemIfSet(d, kw_key, opt_key=None):
  211. opt_key = opt_key or kw_key
  212. if opt_key in self._nondefaults:
  213. d[kw_key] = getattr(self, opt_key)
  214. if ((self.shaping_type == 'proxy' and shaping_key in ('dns', 'http')) or
  215. self.shaping_type == shaping_key):
  216. AddItemIfSet(kwargs, 'delay_ms')
  217. if shaping_key in ('dummynet', 'http'):
  218. AddItemIfSet(kwargs, 'down_bandwidth', opt_key='down')
  219. AddItemIfSet(kwargs, 'up_bandwidth', opt_key='up')
  220. if shaping_key == 'dummynet':
  221. AddItemIfSet(kwargs, 'packet_loss_rate')
  222. AddItemIfSet(kwargs, 'init_cwnd')
  223. elif self.shaping_type != 'none':
  224. if 'packet_loss_rate' in self._nondefaults:
  225. logging.warn('Shaping type, %s, ignores --packet_loss_rate=%s',
  226. self.shaping_type, self.packet_loss_rate)
  227. if 'init_cwnd' in self._nondefaults:
  228. logging.warn('Shaping type, %s, ignores --init_cwnd=%s',
  229. self.shaping_type, self.init_cwnd)
  230. return kwargs
  231. def _MassageValues(self):
  232. """Set options that depend on the values of other options."""
  233. if self.append and not self.record:
  234. self._options.record = True
  235. if self.net:
  236. self._options.down, self._options.up, self._options.delay_ms = \
  237. net_configs.GetNetConfig(self.net)
  238. self._nondefaults.update(['down', 'up', 'delay_ms'])
  239. if not self.ssl:
  240. self._options.https_root_ca_cert_path = None
  241. self.shaping_dns = self._ShapingKeywordArgs('dns')
  242. self.shaping_http = self._ShapingKeywordArgs('http')
  243. self.shaping_dummynet = self._ShapingKeywordArgs('dummynet')
  244. def __getattr__(self, name):
  245. """Make the original option values available."""
  246. return getattr(self._options, name)
  247. def __repr__(self):
  248. """Return a json representation of the original options dictionary."""
  249. return json.dumps(self._options.__dict__)
  250. def IsRootRequired(self):
  251. """Returns True iff the options require whole program root access."""
  252. if self.server:
  253. return True
  254. def IsPrivilegedPort(port):
  255. return port and port < 1024
  256. if IsPrivilegedPort(self.port) or (self.ssl and
  257. IsPrivilegedPort(self.ssl_port)):
  258. return True
  259. if self.dns_forwarding:
  260. if IsPrivilegedPort(self.dns_port):
  261. return True
  262. if not self.server_mode and self.host == '127.0.0.1':
  263. return True
  264. return False
  265. def replay(options, replay_filename):
  266. if options.record and sys.version_info < (2, 7, 9):
  267. print ('Need Python 2.7.9 or greater for recording mode.\n'
  268. 'For instructions on how to upgrade Python on Ubuntu 14.04, see:\n'
  269. 'http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html\n')
  270. if options.admin_check and options.IsRootRequired():
  271. platformsettings.rerun_as_administrator()
  272. configure_logging(options.log_level, options.log_file)
  273. server_manager = servermanager.ServerManager(options.record)
  274. if options.server:
  275. AddDnsForward(server_manager, options.server)
  276. else:
  277. real_dns_lookup = dnsproxy.RealDnsLookup(
  278. name_servers=[platformsettings.get_original_primary_nameserver()])
  279. if options.record:
  280. httparchive.HttpArchive.AssertWritable(replay_filename)
  281. if options.append and os.path.exists(replay_filename):
  282. http_archive = httparchive.HttpArchive.Load(replay_filename)
  283. logging.info('Appending to %s (loaded %d existing responses)',
  284. replay_filename, len(http_archive))
  285. else:
  286. http_archive = httparchive.HttpArchive()
  287. else:
  288. http_archive = httparchive.HttpArchive.Load(replay_filename)
  289. logging.info('Loaded %d responses from %s',
  290. len(http_archive), replay_filename)
  291. server_manager.AppendRecordCallback(real_dns_lookup.ClearCache)
  292. server_manager.AppendRecordCallback(http_archive.clear)
  293. ipfw_dns_host = None
  294. if options.dns_forwarding or options.shaping_dummynet:
  295. # compute the ip/host used for the DNS server and traffic shaping
  296. ipfw_dns_host = options.host
  297. if not ipfw_dns_host:
  298. ipfw_dns_host = platformsettings.get_server_ip_address(
  299. options.server_mode)
  300. if options.dns_forwarding:
  301. if not options.server_mode and ipfw_dns_host == '127.0.0.1':
  302. AddDnsForward(server_manager, ipfw_dns_host)
  303. AddDnsProxy(server_manager, options, ipfw_dns_host, options.dns_port,
  304. real_dns_lookup, http_archive)
  305. if options.ssl and options.https_root_ca_cert_path is None:
  306. options.https_root_ca_cert_path = os.path.join(os.path.dirname(__file__),
  307. 'wpr_cert.pem')
  308. http_proxy_address = options.host
  309. if not http_proxy_address:
  310. http_proxy_address = platformsettings.get_httpproxy_ip_address(
  311. options.server_mode)
  312. AddWebProxy(server_manager, options, http_proxy_address, real_dns_lookup,
  313. http_archive)
  314. AddTrafficShaper(server_manager, options, ipfw_dns_host)
  315. exit_status = 0
  316. try:
  317. server_manager.Run()
  318. except KeyboardInterrupt:
  319. logging.info('Shutting down.')
  320. except (dnsproxy.DnsProxyException,
  321. trafficshaper.TrafficShaperException,
  322. platformsettings.NotAdministratorError,
  323. platformsettings.DnsUpdateError) as e:
  324. logging.critical('%s: %s', e.__class__.__name__, e)
  325. exit_status = 1
  326. except Exception:
  327. logging.critical(traceback.format_exc())
  328. exit_status = 2
  329. if options.record:
  330. http_archive.Persist(replay_filename)
  331. logging.info('Saved %d responses to %s', len(http_archive), replay_filename)
  332. return exit_status
  333. def GetParser():
  334. arg_parser = argparse.ArgumentParser(
  335. usage='%(prog)s [options] replay_file',
  336. description=__doc__,
  337. formatter_class=argparse.RawDescriptionHelpFormatter,
  338. epilog='http://code.google.com/p/web-page-replay/')
  339. arg_parser.add_argument('replay_filename', type=str, help='Replay file',
  340. nargs='?')
  341. arg_parser.add_argument('-r', '--record', default=False,
  342. action='store_true',
  343. help='Download real responses and record them to replay_file')
  344. arg_parser.add_argument('--append', default=False,
  345. action='store_true',
  346. help='Append responses to replay_file.')
  347. arg_parser.add_argument('-l', '--log_level', default='debug',
  348. action='store',
  349. type=str,
  350. choices=('debug', 'info', 'warning', 'error', 'critical'),
  351. help='Minimum verbosity level to log')
  352. arg_parser.add_argument('-f', '--log_file', default=None,
  353. action='store',
  354. type=str,
  355. help='Log file to use in addition to writting logs to stderr.')
  356. network_group = arg_parser.add_argument_group(
  357. title='Network Simulation Options',
  358. description=('These options configure the network simulation in '
  359. 'replay mode'))
  360. network_group.add_argument('-u', '--up', default='0',
  361. action='store',
  362. type=str,
  363. help='Upload Bandwidth in [K|M]{bit/s|Byte/s}. Zero means unlimited.')
  364. network_group.add_argument('-d', '--down', default='0',
  365. action='store',
  366. type=str,
  367. help='Download Bandwidth in [K|M]{bit/s|Byte/s}. Zero means unlimited.')
  368. network_group.add_argument('-m', '--delay_ms', default='0',
  369. action='store',
  370. type=str,
  371. help='Propagation delay (latency) in milliseconds. Zero means no delay.')
  372. network_group.add_argument('-p', '--packet_loss_rate', default='0',
  373. action='store',
  374. type=str,
  375. help='Packet loss rate in range [0..1]. Zero means no loss.')
  376. network_group.add_argument('-w', '--init_cwnd', default='0',
  377. action='store',
  378. type=str,
  379. help='Set initial cwnd (linux only, requires kernel patch)')
  380. network_group.add_argument('--net', default=None,
  381. action='store',
  382. type=str,
  383. choices=net_configs.NET_CONFIG_NAMES,
  384. help='Select a set of network options: %s.' % ', '.join(
  385. net_configs.NET_CONFIG_NAMES))
  386. network_group.add_argument('--shaping_type', default='dummynet',
  387. action='store',
  388. choices=('dummynet', 'proxy'),
  389. help='When shaping is configured (i.e. --up, --down, etc.) decides '
  390. 'whether to use |dummynet| (default), or |proxy| servers.')
  391. harness_group = arg_parser.add_argument_group(
  392. title='Replay Harness Options',
  393. description=('These advanced options configure various aspects '
  394. 'of the replay harness'))
  395. harness_group.add_argument('-S', '--server', default=None,
  396. action='store',
  397. type=str,
  398. help='IP address of host running "replay.py --server_mode". '
  399. 'This only changes the primary DNS nameserver to use the given IP.')
  400. harness_group.add_argument('-M', '--server_mode', default=False,
  401. action='store_true',
  402. help='Run replay DNS & http proxies, and trafficshaping on --port '
  403. 'without changing the primary DNS nameserver. '
  404. 'Other hosts may connect to this using "replay.py --server" '
  405. 'or by pointing their DNS to this server.')
  406. harness_group.add_argument('-i', '--inject_scripts', default='deterministic.js',
  407. action='store',
  408. dest='inject_scripts',
  409. help='A comma separated list of JavaScript sources to inject in all '
  410. 'pages. By default a script is injected that eliminates sources '
  411. 'of entropy such as Date() and Math.random() deterministic. '
  412. 'CAUTION: Without deterministic.js, many pages will not replay.')
  413. harness_group.add_argument('-D', '--no-diff_unknown_requests', default=True,
  414. action='store_false',
  415. dest='diff_unknown_requests',
  416. help='During replay, do not show a diff of unknown requests against '
  417. 'their nearest match in the archive.')
  418. harness_group.add_argument('-C', '--use_closest_match', default=False,
  419. action='store_true',
  420. dest='use_closest_match',
  421. help='During replay, if a request is not found, serve the closest match'
  422. 'in the archive instead of giving a 404.')
  423. harness_group.add_argument('-U', '--use_server_delay', default=False,
  424. action='store_true',
  425. dest='use_server_delay',
  426. help='During replay, simulate server delay by delaying response time to'
  427. 'requests.')
  428. harness_group.add_argument('-I', '--screenshot_dir', default=None,
  429. action='store',
  430. type=str,
  431. help='Save PNG images of the loaded page in the given directory.')
  432. harness_group.add_argument('-P', '--no-dns_private_passthrough', default=True,
  433. action='store_false',
  434. dest='dns_private_passthrough',
  435. help='Don\'t forward DNS requests that resolve to private network '
  436. 'addresses. CAUTION: With this option important services like '
  437. 'Kerberos will resolve to the HTTP proxy address.')
  438. harness_group.add_argument('-x', '--no-dns_forwarding', default=True,
  439. action='store_false',
  440. dest='dns_forwarding',
  441. help='Don\'t forward DNS requests to the local replay server. '
  442. 'CAUTION: With this option an external mechanism must be used to '
  443. 'forward traffic to the replay server.')
  444. harness_group.add_argument('--host', default=None,
  445. action='store',
  446. type=str,
  447. help='The IP address to bind all servers to. Defaults to 0.0.0.0 or '
  448. '127.0.0.1, depending on --server_mode and platform.')
  449. harness_group.add_argument('-o', '--port', default=80,
  450. action='store',
  451. type=int,
  452. help='Port number to listen on.')
  453. harness_group.add_argument('--ssl_port', default=443,
  454. action='store',
  455. type=int,
  456. help='SSL port number to listen on.')
  457. harness_group.add_argument('--http_to_https_port', default=None,
  458. action='store',
  459. type=int,
  460. help='Port on which WPR will listen for HTTP requests that it will send '
  461. 'along as HTTPS requests.')
  462. harness_group.add_argument('--dns_port', default=53,
  463. action='store',
  464. type=int,
  465. help='DNS port number to listen on.')
  466. harness_group.add_argument('-c', '--https_root_ca_cert_path', default=None,
  467. action='store',
  468. type=str,
  469. help='Certificate file to use with SSL (gets auto-generated if needed).')
  470. harness_group.add_argument('--no-ssl', default=True,
  471. action='store_false',
  472. dest='ssl',
  473. help='Do not setup an SSL proxy.')
  474. harness_group.add_argument('--should_generate_certs', default=False,
  475. action='store_true',
  476. help='Use OpenSSL to generate certificate files for requested hosts.')
  477. harness_group.add_argument('--no-admin-check', default=True,
  478. action='store_false',
  479. dest='admin_check',
  480. help='Do not check if administrator access is needed.')
  481. harness_group.add_argument('--scramble_images', default=False,
  482. action='store_true',
  483. dest='scramble_images',
  484. help='Scramble image responses.')
  485. harness_group.add_argument('--rules_path', default=None,
  486. action='store',
  487. help='Path of file containing Python rules.')
  488. harness_group.add_argument('--allowed_rule_imports', default='rules',
  489. action='store',
  490. help='A comma-separate list of allowed rule imports, or \'*\' to allow'
  491. ' all packages. Defaults to %(default)s.')
  492. return arg_parser
  493. def main():
  494. arg_parser = GetParser()
  495. options = arg_parser.parse_args()
  496. options = OptionsWrapper(options, arg_parser)
  497. if options.server:
  498. options.replay_filename = None
  499. elif options.replay_filename is None:
  500. arg_parser.error('Must specify a replay_file')
  501. return replay(options, options.replay_filename)
  502. if __name__ == '__main__':
  503. sys.exit(main())