gstepanov | 5f936df | 2015-03-18 19:15:59 +0200 | [diff] [blame] | 1 | import argparse |
| 2 | import sys |
gstepanov | c82391e | 2015-03-17 15:46:36 +0200 | [diff] [blame] | 3 | import yaml |
gstepanov | 725cc30 | 2015-02-09 15:08:06 +0200 | [diff] [blame] | 4 | import os |
| 5 | |
stgleb | 75c7041 | 2015-02-17 02:52:00 +0200 | [diff] [blame] | 6 | |
gstepanov | c82391e | 2015-03-17 15:46:36 +0200 | [diff] [blame] | 7 | def parse_config(file_name): |
| 8 | with open(file_name) as f: |
| 9 | cfg = yaml.load(f.read()) |
| 10 | |
| 11 | return cfg |
| 12 | |
| 13 | |
gstepanov | 5f936df | 2015-03-18 19:15:59 +0200 | [diff] [blame] | 14 | parser = argparse.ArgumentParser(description="config file name") |
| 15 | parser.add_argument("-p", "--path") |
gstepanov | b3c7896 | 2015-03-20 15:47:58 +0200 | [diff] [blame^] | 16 | parser.add_argument("-b", "--basedir") |
| 17 | parser.add_argument("-t", "--testpath") |
| 18 | parser.add_argument("-d", "--database") |
| 19 | parser.add_argument("-c", "--chartpath") |
gstepanov | 5f936df | 2015-03-18 19:15:59 +0200 | [diff] [blame] | 20 | |
| 21 | config = parser.parse_args(sys.argv[1:]) |
| 22 | path = "config.yaml" |
| 23 | |
| 24 | if not config.path is None: |
| 25 | path = config.path |
| 26 | |
| 27 | cfg_dict = parse_config(os.path.join(os.path.dirname(__file__), path)) |
gstepanov | c82391e | 2015-03-17 15:46:36 +0200 | [diff] [blame] | 28 | basedir = cfg_dict['paths']['basedir'] |
| 29 | TEST_PATH = cfg_dict['paths']['TEST_PATH'] |
| 30 | SQLALCHEMY_MIGRATE_REPO = cfg_dict['paths']['SQLALCHEMY_MIGRATE_REPO'] |
| 31 | DATABASE_URI = cfg_dict['paths']['DATABASE_URI'] |
gstepanov | 5f936df | 2015-03-18 19:15:59 +0200 | [diff] [blame] | 32 | CHARTS_IMG_PATH = cfg_dict['paths']['CHARTS_IMG_PATH'] |
| 33 | |
gstepanov | b3c7896 | 2015-03-20 15:47:58 +0200 | [diff] [blame^] | 34 | if not config.basedir is None: |
| 35 | basedir = config.basedir |
| 36 | |
| 37 | if not config.testpath is None: |
| 38 | TEST_PATH = config.testpath |
| 39 | |
| 40 | if not config.database is None: |
| 41 | DATABASE_URI = config.database |
| 42 | |
| 43 | if not config.chartpath is None: |
| 44 | CHARTS_IMG_PATH = config.chartpath |
| 45 | |
gstepanov | 5f936df | 2015-03-18 19:15:59 +0200 | [diff] [blame] | 46 | |