forked from patrickwardle/knockknock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.py
51 lines (33 loc) · 818 Bytes
/
command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
__author__ = 'patrick'
import json
#project imports
import whitelist
class Command():
#init method
# ->save command and set white list flag
def __init__(self, command, file=None):
#save command
self.command = command
#save file
self.file = file
#init whitelist flag
# ->simply set to True if command is list of whitelisted commands
self.isWhitelisted = (self.command in whitelist.whitelistedCommands)
return
#for json output
def __repr__(self):
#return obj as JSON string
return json.dumps(self.__dict__)
#for normal output
def prettyPrint(self):
#pretty-printed string
string = ''
#when cmd has file
if self.file:
#init
string = '\n%s\n file: %s\n' % (self.command, self.file)
#no file
else:
#init
string = '\n%s\n' % (self.command)
return string