Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnowpass.py
More file actions
Latest commit
executable file
·98 lines (71 loc) · 2.28 KB
/
Copy pathnowpass.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
importos
importsys
importlogging
importnowpass.parser
importnowpass.element
importnowpass.engine
importnowpass.main_config
importerrno
try:
sys.setdefaultencoding('UTF8')
exceptException:
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'
}
defmain():
# 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)
ifconfig['Encryption']['passphrase'] =='':
config['Encryption']['passphrase'] =input('Enter your pass phrase: ')
# Starting here we need a command
ifargs.commandisNone:
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)
defcreate_storage_folder(path):
try:
os.makedirs(path)
exceptOSErrorasexception:
ifexception.errno!=errno.EEXIST:
raise
if__name__=="__main__":
main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4