-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
73 lines (51 loc) · 1.78 KB
/
parser.py
File metadata and controls
73 lines (51 loc) · 1.78 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
import os
import sys
import argparse
import configparser
from os import path
from parameters import Parameter
class ArgParser:
def process_args():
"""
Use this function to add/edit sys arguments
"""
parser = argparse.ArgumentParser(
prog='teer',
description='Sync your dot files with this fancy program.',
epilog='prajwaldev.com.np',
)
parser.add_argument('--force', action='store_true',
help='Overwrite currently existing configurations'
)
parser.add_argument('-i', '--interactive', action='store_true',
help='Choose what config to sync at run time'
)
parser.add_argument('--log', nargs='?',
help='Log the events of the program to a file'
)
return parser.parse_args()
class ParameterParser:
parameters_file = path.join(Parameter.SCRIPT_DIR, 'parameters.cfg')
@staticmethod
def process_params():
if not os.path.exists(ParameterParser.parameters_file):
return
parser = configparser.ConfigParser()
parser.read(ParameterParser.parameters_file)
Parameter.update_params(parser)
class Parser(ArgParser, ParameterParser):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@staticmethod
def parse():
args = Parser.process_args()
Parser.process_params()
if args.force:
Parameter.FORCE_OVERWRITE = True
if args.interactive:
Parameter.INTERACTIVE_SYNC = True
if '--log' in sys.argv:
Parameter.LOGGING_ENABLED = True
if args.log:
Parameter.LOG_FILE_PATH = args.log
return Parameter