Skip to content

Commit

Permalink
Merge pull request mitmproxy#2689 from cortesi/grideditor.save
Browse files Browse the repository at this point in the history
console.grideditor.save
  • Loading branch information
cortesi authored Dec 17, 2017
2 parents 45c613f + ed3cd94 commit 33585bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mitmproxy/tools/console/consoleaddons.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import typing

from mitmproxy import ctx
Expand Down Expand Up @@ -417,6 +418,20 @@ def grideditor_load_escaped(self, path: command.Path) -> None:
"""
self._grideditor().cmd_read_file_escaped(path)

@command.command("console.grideditor.save")
def grideditor_save(self, path: command.Path) -> None:
"""
Save data to file as a CSV.
"""
rows = self._grideditor().value
with open(path, "w", newline='', encoding="utf8") as fp:
writer = csv.writer(fp)
for row in rows:
writer.writerow(
[strutils.always_str(x) or "" for x in row] # type: ignore
)
ctx.log.alert("Saved %s rows as CSV." % (len(rows)))

@command.command("console.grideditor.editor")
def grideditor_editor(self) -> None:
"""
Expand Down
6 changes: 6 additions & 0 deletions mitmproxy/tools/console/defaultkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def map(km):
"Load a Python-style escaped string into the current cell from file"
)
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
km.add(
"w",
"console.command console.grideditor.save ",
["grideditor"],
"Save data to file as CSV"
)

km.add("z", "eventstore.clear", ["eventlog"], "Clear")

Expand Down

0 comments on commit 33585bd

Please sign in to comment.