-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnowpass.py
More file actions
executable file
·98 lines (71 loc) · 2.28 KB
/
nowpass.py
File metadata and controls
executable file
·98 lines (71 loc) · 2.28 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
import os
import sys
import logging
import nowpass.parser
import nowpass.element
import nowpass.engine
import nowpass.main_config
import errno
try:
sys.setdefaultencoding('UTF8')
except Exception:
pass
STORAGE_FOLDER = os.path.expanduser('~/.nowpass')
MAIN_CONFIG = STORAGE_FOLDER + '/main.conf'
# Testing work around for shortcuts
COMMANDS = {
'del': 'delete', 'delete': 'delete',
'a': 'add', 'add': 'add',
'l': 'list', 'list': 'list',
's': 'search', 'search': 'search',
'e': 'edit', 'edit': 'edit'
}
def main():
# Storage folder
create_storage_folder(STORAGE_FOLDER)
# Start args parser (needed for logging file)
# Wrapper Class
parser_class = nowpass.parser.Parser()
parser = parser_class.get()
args = parser.parse_args()
# Logging
logger = logging.getLogger('nowpass')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(formatter)
# File logging with debug
fh = logging.FileHandler(os.path.expanduser(args.logfile))
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
logger.debug('Starting nowpass CLI client')
# Config
main_config = nowpass.main_config.MainConfig(logger, MAIN_CONFIG)
config = main_config.get_config()
# Passphrase (stored or via input)
if config['Encryption']['passphrase'] == '':
config['Encryption']['passphrase'] = input('Enter your pass phrase: ')
# Starting here we need a command
if args.command is None:
print('Please supply a command, check --help for more details.')
exit(1)
command = args.command
logger.debug('Command: ' + command)
# Get the Engine for processing tasks
engine = nowpass.engine.Engine(logger, main_config)
task_to_call = getattr(engine, COMMANDS[command])
task_to_call(args)
exit(0)
def create_storage_folder(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
if __name__ == "__main__":
main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4