Revision 2d0b6dcc
b/kamaki/cli.py | ||
---|---|---|
73 | 73 |
from base64 import b64encode |
74 | 74 |
from grp import getgrgid |
75 | 75 |
from optparse import OptionParser |
76 |
from os.path import abspath, basename, exists, expanduser
|
|
76 |
from os.path import abspath, basename, exists |
|
77 | 77 |
from pwd import getpwuid |
78 | 78 |
from sys import argv, exit, stdout |
79 | 79 |
|
... | ... | |
89 | 89 |
from kamaki.utils import OrderedDict, print_addresses, print_dict, print_items |
90 | 90 |
|
91 | 91 |
|
92 |
# Path to the file that stores the configuration |
|
93 |
CONFIG_PATH = expanduser('~/.kamakirc') |
|
94 |
|
|
95 |
# Name of a shell variable to bypass the CONFIG_PATH value |
|
96 |
CONFIG_ENV = 'KAMAKI_CONFIG' |
|
97 |
|
|
98 |
|
|
99 | 92 |
_commands = OrderedDict() |
100 | 93 |
|
101 | 94 |
|
... | ... | |
878 | 871 |
exit(0) |
879 | 872 |
|
880 | 873 |
if '--config' in args: |
881 |
config_path = args.grouped['--config'].get(0)
|
|
874 |
config = Config(args.grouped['--config'].get(0))
|
|
882 | 875 |
else: |
883 |
config_path = os.environ.get(CONFIG_ENV, CONFIG_PATH) |
|
884 |
|
|
885 |
config = Config(config_path) |
|
886 |
|
|
876 |
config = Config() |
|
877 |
|
|
887 | 878 |
for option in args.grouped.get('-o', []): |
888 | 879 |
keypath, sep, val = option.partition('=') |
889 | 880 |
if not sep: |
b/kamaki/config.py | ||
---|---|---|
39 | 39 |
from .utils import OrderedDict |
40 | 40 |
|
41 | 41 |
|
42 |
# Path to the file that stores the configuration |
|
43 |
CONFIG_PATH = os.path.expanduser('~/.kamakirc') |
|
44 |
|
|
45 |
# Name of a shell variable to bypass the CONFIG_PATH value |
|
46 |
CONFIG_ENV = 'KAMAKI_CONFIG' |
|
47 |
|
|
42 | 48 |
HEADER = """ |
43 | 49 |
# Kamaki configuration file |
44 | 50 |
""" |
... | ... | |
78 | 84 |
class Config(RawConfigParser): |
79 | 85 |
def __init__(self, path=None): |
80 | 86 |
RawConfigParser.__init__(self, dict_type=OrderedDict) |
81 |
self.path = path |
|
87 |
self.path = path or os.environ.get(CONFIG_ENV, CONFIG_PATH)
|
|
82 | 88 |
self._overrides = defaultdict(dict) |
83 |
self.read(path) |
|
89 |
self.read(self.path)
|
|
84 | 90 |
|
85 | 91 |
def sections(self): |
86 | 92 |
return DEFAULTS.keys() |
Also available in: Unified diff