diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-12-17 13:09:29 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-17 13:09:29 +1300 |
commit | 33585bd2a2da80443205e7fd3d464d06b64ab6df (patch) | |
tree | e0948c75c6b03be6366607dc1dafb4410e33a69e | |
parent | 45c613f970e23ce47fff175b5fc08f54ac9e9418 (diff) | |
parent | ed3cd949e41a27232897275640291370846f86e4 (diff) | |
download | mitmproxy-33585bd2a2da80443205e7fd3d464d06b64ab6df.tar.gz mitmproxy-33585bd2a2da80443205e7fd3d464d06b64ab6df.tar.bz2 mitmproxy-33585bd2a2da80443205e7fd3d464d06b64ab6df.zip |
Merge pull request #2689 from cortesi/grideditor.save
console.grideditor.save
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 15 | ||||
-rw-r--r-- | mitmproxy/tools/console/defaultkeys.py | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 95100fbf..453e9e1c 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -1,3 +1,4 @@ +import csv import typing from mitmproxy import ctx @@ -417,6 +418,20 @@ class ConsoleAddon: """ 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: """ diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index 69c6e49f..0fdec10c 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -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") |