-
Notifications
You must be signed in to change notification settings - Fork 2
/
argparser.py
42 lines (30 loc) · 1.39 KB
/
argparser.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
import argparse
class Parser:
_instance = None
_default_conf_path = '/home/juraj/Documents/mYstable/config/config.json'
def __init__(self):
if self._initialized is True:
return
self._parser = argparse.ArgumentParser()
#here command line arguments should be specified
self._add_commandline_argument()
self._handle_arguments()
self._initialized = True
def __new__(cls, *args, **kwargs):
if Parser._instance is None:
Parser._instance = object.__new__(cls)
Parser._instance._initialized = False
return Parser._instance
def _add_commandline_argument(self):
'Here should be specified arguments from commandline we want to work with'
self._parser.add_argument("-c", "--config",
metavar="<filename>",
dest="config_file",
default=Parser._default_conf_path,
type=argparse.FileType('r'),
help="sets path to configuration file")
def _handle_arguments(self):
arguments = self._parser.parse_args()
attributes = arguments.__dict__
for arg, value in attributes.items(): #loop in given arguments from command line and set attributes equal
setattr(self, arg, value) #to them