-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
41 lines (33 loc) · 1.75 KB
/
common.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
#!/usr/bin/env python
#coding=utf-8
import sys
import os
import time
import ConfigParser
class Common:
@staticmethod
def LoadConfig():
cfg_fn = os.path.join(os.path.dirname(os.path.abspath(__file__)) + "\\config.cfg")
required_ops = [("Base", "AccessKeyId"), ("Base", "AccessKeySecret"), ("Base", "LogEndpoint"), ("Base", "LogProject"), ("Base", "Logstore"), ("Base", "OSSEndpoint"), ("Base", "OSSBucketName")]
#optional_ops = [("Optional", "SecurityToken")]
# Read config.cfg and parse the configuration parameters
parser = ConfigParser.ConfigParser()
parser.read(cfg_fn)
# Check if any of the manadatory parameters are missing
for sec,op in required_ops:
if not parser.has_option(sec, op):
sys.stderr.write("ERROR: need (%s, %s) in %s.\n" % (sec,op,cfg_fn))
sys.stderr.write("Read README to get help inforamtion.\n")
sys.exit(1)
# Assign each of the configuration parameters values to separate varaiables
accessKeyId = parser.get("Base", "AccessKeyId")
accessKeySecret = parser.get("Base", "AccessKeySecret")
logEndPoint = parser.get("Base", "LogEndpoint")
logProject = parser.get("Base", "LogProject")
logStore = parser.get("Base", "Logstore")
ossEndPoint = parser.get("Base", "OSSEndpoint")
ossBucketName = parser.get("Base", "OSSBucketName")
securityToken = ""
if parser.has_option("Optional", "SecurityToken") and parser.get("Optional", "SecurityToken") != "$SecurityToken":
securityToken = parser.get("Optional", "SecurityToken")
return accessKeyId,accessKeySecret,logEndPoint,logProject,logStore,ossEndPoint,ossBucketName,securityToken