-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.py
36 lines (30 loc) · 1.14 KB
/
configuration.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
#!/usr/bin/env python
import ConfigParser
class Configuration:
def __init__(self):
self.token = None
self.droplet_name = None
self.droplet_region = None
self.droplet_size_slug = None
self.image_name = None
self.domain_name = None
self.ssh_key_name = None
def read_config(self, config_file):
"""Return True on success, False on error"""
config = ConfigParser.SafeConfigParser()
files_read = config.read(config_file)
if not files_read:
return False
# We have a config, now read it
try:
self.token = config.get('misc', 'token')
self.droplet_name = config.get('droplet', 'name')
self.droplet_region = config.get('droplet', 'region')
self.droplet_size_slug = config.get('droplet', 'size_slug')
self.image_name = config.get('droplet', 'image_name')
self.domain_name = config.get('domain', 'name')
self.ssh_key_name = config.get('ssh', 'key_name')
except ConfigParser.NoOptionError as e:
print(e)
return False
return True