-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor coloring, make file controller, add banner
- Loading branch information
1 parent
418fa1f
commit 149c0d7
Showing
10 changed files
with
89 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
#!/usr/bin/python3 | ||
import argparse | ||
from multidiff import MultidiffModel, StreamView, SocketController, FileController | ||
|
||
from multidiff import MultidiffModel, StreamView, SocketController | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description='The multidiff tool of the future.') | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=""" | ||
\x1b[1mN E O N S E N S E\x1b[0m | ||
augmentations inc | ||
┌───────────────┐ | ||
│ \x1b[1mM U L T I\x1b[0m │ | ||
│ \x1b[1mD I F F\x1b[0m │ | ||
│ sensor module │ | ||
└───────────────┘ | ||
""") | ||
|
||
parser.add_argument('file', | ||
metavar='file', | ||
type=str, | ||
nargs='*', | ||
help='a file or directory whose content is to be included in the multidiff') | ||
help='file or directory to include in multidiff') | ||
|
||
parser.add_argument('-m', '--mode', | ||
dest='mode', | ||
default='sequence', | ||
help='mode of operation, either "baseline" or "sequence"') | ||
|
||
parser.add_argument('-e','--encode', | ||
dest='encode', | ||
default='hexdump', | ||
help='choose encoding of the data. One of "hex", "hexdump", or "utf8"') | ||
help='encoding of the output data, one of "hex", "hexdump", or "utf8"') | ||
|
||
parser.add_argument('-p','--port', | ||
dest='port', | ||
default=0, | ||
type=int, | ||
help='start a local socket server on a port') | ||
|
||
if __name__ == '__main__': | ||
args = parser.parse_args() | ||
m = MultidiffModel() | ||
v = StreamView(m, encoding=args.encode) | ||
#f = FileController(m) | ||
#f.add_files(args.files) | ||
s = SocketController(('127.0.0.1', args.port), m) | ||
s.serve_forever() | ||
f = FileController(m) | ||
f.add_paths(args.file) | ||
if args.port != 0: | ||
s = SocketController(('127.0.0.1', args.port), m) | ||
s.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Ansi: | ||
reset = '\x1b[0m' | ||
bold = '\x1b[1m' | ||
on_red = '\x1b[41m' | ||
on_green = '\x1b[42m' | ||
on_blue = '\x1b[44m' | ||
white = '\x1b[37m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
class FileController: | ||
def __init__(self, model): | ||
self.model = model | ||
|
||
def add_paths(self, paths): | ||
for path in paths: | ||
self.add_path(path) | ||
|
||
def add_path(self, path): | ||
if os.path.isdir(path): | ||
for name in os.listdir(path): | ||
self.add_path(os.path.join(path, name)) | ||
elif os.path.isfile(path): | ||
data = open(path, 'rb').read(-1) | ||
self.model.add(data, name=path) | ||
else: | ||
raise NotImplemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,7 @@ | ||
""" | ||
The tool of future | ||
___________________ | ||
| | | ||
| M U L T I | | ||
| | | ||
| D I F F | | ||
|___________________| | ||
i n t e l l i g e c e | ||
""" | ||
|
||
from .multidiffmodel import MultidiffModel | ||
from .render import Render, HexdumpEncoder | ||
from .Ansi import Ansi | ||
from .baselineview import BaselineView | ||
from .SocketController import SocketController | ||
from .StreamView import StreamView | ||
from .FileController import FileController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
foobar | ||
fooba[44m[37mg[0m | ||
[44m[37mgee[0mbar | ||
foo[42m[37mx[0mbar | ||
f[41m[37m[0mobar | ||
[41m[37m[0m | ||
fooba[37m[44mg[0m | ||
[37m[44mgee[0mbar | ||
foo[37m[42mx[0mbar | ||
f[37m[41m[0mobar | ||
[37m[41m[0m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
{ | ||
"d": { | ||
"r": 45[44m[37m4[0m, | ||
"r": 45[37m[44m4[0m, | ||
"b": { | ||
"p": "/ps/6W1HJ648/chats/-KpBN[44m[37mFr[0mY[44m[37mEBtFQ41l9wJ[0mg[41m[37m[0m", | ||
"p": "/ps/6W1HJ648/chats/-KpBN[37m[44mFr[0mY[37m[44mEBtFQ41l9wJ[0mg[37m[41m[0m", | ||
"d": { | ||
"message": "a", | ||
"timestamp": "2017-07-16T17:10:1[42m[37m5.8[0m7[44m[37m5[0mZ" | ||
"timestamp": "2017-07-16T17:10:1[37m[42m5.8[0m7[37m[44m5[0mZ" | ||
} | ||
} | ||
} | ||
} | ||
{ | ||
"d": { | ||
"r": 45[44m[37m1[0m, | ||
"r": 45[37m[44m1[0m, | ||
"b": { | ||
"p": "/ps/6W1HJ648/chats/-KpBNF[44m[37mI[0mY[44m[37mZdU8KG[0mw[44m[37mTKf2T[0m", | ||
"p": "/ps/6W1HJ648/chats/-KpBNF[37m[44mI[0mY[37m[44mZdU8KG[0mw[37m[44mTKf2T[0m", | ||
"d": { | ||
"message": "a", | ||
"timestamp": "2017-07-16T17:10:1[42m[37m3.[0m5[41m[37m[0m7[44m[37m0[0mZ" | ||
"timestamp": "2017-07-16T17:10:1[37m[42m3.[0m5[37m[41m[0m7[37m[44m0[0mZ" | ||
} | ||
} | ||
} | ||
}[42m[37m | ||
}[37m[42m | ||
[0m |