-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
71 lines (57 loc) · 2.07 KB
/
config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
import argparse
from logger import logger
BACKUP_LOCATION_DB = "db"
BACKUP_LOCATION_JSON = "json"
BACKUP_TYPE_FULL = "full"
BACKUP_TYPE_INCREMENTAL = "incremental"
def get_config():
'''
Get all required configration values from environment
variables, or else exit if any value is missing
'''
success = True
token = os.getenv('RAINDROP_IO_TOKEN')
if token is None:
success = False
logger.error("Raindrop IO token is not provided")
db_username = os.getenv('POSTGRES_USERNAME')
if db_username is None:
success = False
logger.error("DB username is not provided")
db_password = os.getenv('POSTGRES_PASSWORD')
if db_password is None:
success = False
logger.error("DB password is not provided")
db_host = os.getenv('POSTGRES_HOST')
if db_host is None:
success = False
logger.error("DB host is not provided")
db_port = os.getenv('POSTGRES_PORT')
if db_port is None:
success = False
logger.error("DB port is not provided")
if success:
return {
'token': token,
'db_username': db_username,
'db_password': db_password,
'db_host': db_host,
'db_port': db_port
}
else:
sys.exit(1)
def get_command_line_args():
'''
Get configration values from command line arguments
'''
parser = argparse.ArgumentParser(
description="This tool is used to backup bookmarks stored in Raindrop.io")
parser.add_argument("-s", "--save", help="Specify save location of backup",
choices=[BACKUP_LOCATION_DB, BACKUP_LOCATION_JSON], default=BACKUP_LOCATION_DB)
parser.add_argument(
"-f", "--file", help=f"Specify JSON file to save backup in, use in conjunction with `--save {BACKUP_LOCATION_JSON}``")
parser.add_argument("-t", "--type", help="Specify type of backup", choices=[
BACKUP_TYPE_FULL, BACKUP_TYPE_INCREMENTAL], default=BACKUP_TYPE_INCREMENTAL)
return parser.parse_args()