Skip to content

Commit

Permalink
Merge pull request #323 from cflowe/feature/config_dir
Browse files Browse the repository at this point in the history
Added use of the CCM_CONFIG_DIR environment variable
  • Loading branch information
ptnapoleon committed Jul 1, 2015
2 parents 9749956 + 1f267db commit 425a448
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ccmlib/cmds/command.py
Expand Up @@ -79,7 +79,7 @@ def _get_default_parser(self, usage, description, ignore_unknown_options=False):
else:
parser = OptionParser(usage=usage, description=description)
parser.add_option('--config-dir', type="string", dest="config_dir",
help="Directory for the cluster files [default to ~/.ccm]")
help="Directory for the cluster files [default to {0}]".format(common.get_default_path_display_name()))
return parser

def description(self):
Expand Down
16 changes: 15 additions & 1 deletion ccmlib/common.py
Expand Up @@ -29,6 +29,7 @@
CASSANDRA_SH = "cassandra.in.sh"

CONFIG_FILE = "config"
CCM_CONFIG_DIR = "CCM_CONFIG_DIR"

class CCMError(Exception):
pass
Expand All @@ -43,11 +44,24 @@ class UnavailableSocketError(CCMError):
pass

def get_default_path():
default_path = os.path.join(get_user_home(), '.ccm')
if CCM_CONFIG_DIR in os.environ and os.environ[CCM_CONFIG_DIR]:
default_path = os.environ[CCM_CONFIG_DIR]
else:
default_path = os.path.join(get_user_home(), '.ccm')

if not os.path.exists(default_path):
os.mkdir(default_path)
return default_path

def get_default_path_display_name():
default_path = get_default_path().lower()
user_home = get_user_home().lower()

if default_path.startswith(user_home):
default_path = os.path.join('~', default_path[len(user_home)+1:])

return default_path

def get_user_home():
if is_win():
if sys.platform == "cygwin":
Expand Down
2 changes: 1 addition & 1 deletion ccmlib/dse_node.py
Expand Up @@ -104,7 +104,7 @@ def start(self,
if profile_options is not None:
config = common.get_config()
if not 'yourkit_agent' in config:
raise NodeError("Cannot enable profile. You need to set 'yourkit_agent' to the path of your agent in a ~/.ccm/config")
raise NodeError("Cannot enable profile. You need to set 'yourkit_agent' to the path of your agent in a {0}/config".format(common.get_default_path_display_name()))
cmd = '-agentpath:%s' % config['yourkit_agent']
if 'options' in profile_options:
cmd = cmd + '=' + profile_options['options']
Expand Down

0 comments on commit 425a448

Please sign in to comment.