2014-01-03 13:32:13 -05:00
|
|
|
__author__ = u'schmatz'
|
|
|
|
import configuration
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import errors
|
|
|
|
import shutil
|
|
|
|
class DirectoryController(object):
|
|
|
|
def __init__(self,config):
|
|
|
|
assert isinstance(config,configuration.Configuration)
|
|
|
|
self.config = config
|
|
|
|
self.root_dir = self.config.system.get_current_working_directory()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def root_install_directory(self):
|
|
|
|
return self.root_dir + os.sep + "coco" + os.sep + "bin"
|
|
|
|
@property
|
|
|
|
def tmp_directory(self):
|
|
|
|
return self.root_install_directory + os.sep + u"tmp"
|
|
|
|
@property
|
|
|
|
def bin_directory(self):
|
|
|
|
return self.root_install_directory
|
|
|
|
|
|
|
|
def create_directory_in_tmp(self,subdirectory):
|
|
|
|
os.mkdir(self.generate_path_for_directory_in_tmp(subdirectory))
|
|
|
|
|
|
|
|
def generate_path_for_directory_in_tmp(self,subdirectory):
|
|
|
|
return self.tmp_directory + os.sep + subdirectory
|
|
|
|
def create_directory_in_bin(self,subdirectory):
|
|
|
|
full_path = self.bin_directory + os.sep + subdirectory
|
|
|
|
os.mkdir(full_path)
|
|
|
|
|
|
|
|
def create_base_directories(self):
|
2014-01-04 17:53:41 -05:00
|
|
|
shutil.rmtree(self.root_dir + os.sep + "coco" + os.sep + "node_modules",ignore_errors=True) #just in case
|
2014-01-03 13:32:13 -05:00
|
|
|
try:
|
2014-01-04 17:14:18 -05:00
|
|
|
if os.path.exists(self.tmp_directory):
|
2014-01-09 10:11:28 -05:00
|
|
|
self.remove_tmp_directory()
|
2014-01-04 17:14:18 -05:00
|
|
|
os.mkdir(self.tmp_directory)
|
2014-01-03 13:32:13 -05:00
|
|
|
except:
|
2014-01-04 17:14:18 -05:00
|
|
|
raise errors.CoCoError(u"There was an error creating the directory structure, do you have correct permissions? Please remove all and start over.")
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
def remove_directories(self):
|
2014-01-04 17:53:41 -05:00
|
|
|
shutil.rmtree(self.bin_directory + os.sep + "node",ignore_errors=True)
|
|
|
|
shutil.rmtree(self.bin_directory + os.sep + "mongo",ignore_errors=True)
|
2014-01-05 14:01:19 -05:00
|
|
|
def remove_tmp_directory(self):
|
|
|
|
shutil.rmtree(self.tmp_directory)
|
|
|
|
|
|
|
|
|
2014-01-04 17:53:41 -05:00
|
|
|
|