Merge pull request #425 from tekii/master

append option added to dump (flow file is open in append mode instead of overwrite)
This commit is contained in:
Maximilian Hils 2014-12-11 22:26:21 +01:00
commit 93d4a0132a
3 changed files with 23 additions and 10 deletions

View File

@ -179,7 +179,7 @@ def get_common_options(options):
stickyauth=stickyauth,
stream_large_bodies=stream_large_bodies,
showhost=options.showhost,
wfile=options.wfile,
outfile=options.outfile,
verbosity=options.verbose,
nopop=options.nopop,
replay_ignore_content = options.replay_ignore_content,
@ -249,11 +249,17 @@ def common_options(parser):
action="store_const", dest="verbose", default=1, const=2,
help="Increase event log verbosity."
)
parser.add_argument(
outfile = parser.add_mutually_exclusive_group()
outfile.add_argument(
"-w", "--wfile",
action="store", dest="wfile", default=None,
action="store", dest="outfile", type=lambda f: (f, "wb"),
help="Write flows to file."
)
outfile.add_argument(
"-a", "--afile",
action="store", dest="outfile", type=lambda f: (f, "ab"),
help="Append flows to file."
)
parser.add_argument(
"-z", "--anticomp",
action="store_true", dest="anticomp", default=False,
@ -371,7 +377,7 @@ def common_options(parser):
group = parser.add_argument_group("Onboarding App")
group.add_argument(
"-a", "--noapp",
"--noapp",
action="store_false", dest="app", default=True,
help="Disable the mitmproxy onboarding app."
)

View File

@ -36,7 +36,7 @@ class Options(object):
"stickyauth",
"stream_large_bodies",
"verbosity",
"wfile",
"outfile",
"replay_ignore_content",
"replay_ignore_params",
]
@ -92,10 +92,10 @@ class DumpMaster(flow.FlowMaster):
if options.stickyauth:
self.set_stickyauth(options.stickyauth)
if options.wfile:
path = os.path.expanduser(options.wfile)
if options.outfile:
path = os.path.expanduser(options.outfile[0])
try:
f = file(path, "wb")
f = file(path, options.outfile[1])
self.start_stream(f, self.filt)
except IOError, v:
raise DumpError(v.strerror)

View File

@ -143,9 +143,16 @@ class TestDumpMaster:
def test_write(self):
with tutils.tmpdir() as d:
p = os.path.join(d, "a")
self._dummy_cycle(1, None, "", wfile=p, verbosity=0)
self._dummy_cycle(1, None, "", outfile=(p,"wb"), verbosity=0)
assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 1
def test_write_append(self):
with tutils.tmpdir() as d:
p = os.path.join(d, "a.append")
self._dummy_cycle(1, None, "", outfile=(p,"wb"), verbosity=0)
self._dummy_cycle(1, None, "", outfile=(p,"ab"), verbosity=0)
assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 2
def test_write_err(self):
tutils.raises(
dump.DumpError,
@ -153,7 +160,7 @@ class TestDumpMaster:
1,
None,
"",
wfile = "nonexistentdir/foo"
outfile = ("nonexistentdir/foo", "wb")
)
def test_script(self):