Source

cloudster / api / shelf / configuration / config.py

Full commit
import os
import sys

__author__ = 'guillermo'


class ConfigurationManager():

	USR_HOME_FOLDER = os.path.expanduser('~')
	APP_HOME_FOLDER_NAME = '.cloudster'
	APP_HOME_FOLDER_PATH = os.path.join(USR_HOME_FOLDER, APP_HOME_FOLDER_NAME)
	APP_CONFIG_PATH = os.path.join(APP_HOME_FOLDER_PATH, 'config')
	APP_INSTANCES_PATH = os.path.join(APP_HOME_FOLDER_PATH, 'instances')

	def settleIfNecessary(self):
		self.__create_app_folder_structure()

	def list_defined_instances(self, name_expression=None):

		instances = os.listdir(self.APP_INSTANCES_PATH)

		if name_expression is not None:
			return [instance for instance in instances if name_expression.match(instance)]
		else:
			return instances


	def __create_app_folder_structure(self):

		ConfigurationManager.__create_dir(self.APP_HOME_FOLDER_PATH)
		ConfigurationManager.__create_dir(self.APP_CONFIG_PATH)
		ConfigurationManager.__create_dir(self.APP_INSTANCES_PATH)


	@staticmethod
	def __create_dir(full_dir_path):
		if not os.path.exists(full_dir_path) or not os.path.isdir(full_dir_path):
			os.makedirs(full_dir_path)