def __init__(self, env_string): self.conf = ConfigManager(env_string)
class DeployByEnvService(DeployService): def __init__(self, env_string): self.conf = ConfigManager(env_string) def copy_sources(self, local_output_path): source_path = self.conf.get('SOURCE_PATH', None) source_output_path = self.conf.get('SOURCE_OUTPUT_PATH') if not source_path: raise DeployIOLocalException(u'No source code can be found.') source_output_path = os.path.join(local_output_path, source_output_path) DeploymentToolKit.copy_dirs(source_path, source_output_path) logger.info('Copy source file %s to output path %s.' % (source_path, source_output_path)) def copy_deployment_configs(self, local_output_path): config_path = self.conf.get('CONFIG_PATH', None) % self.conf.get('env') config_path = os.path.join(self.conf.get('PROJECT_ROOT_PATH'), config_path) config_output_path = os.path.join(local_output_path, self.conf.get('CONFIG_OUTPUT_PATH')) DeploymentToolKit.copy_dirs(config_path, config_output_path) logger.info('Copy configuration from %s to output path %s.' % (config_path, config_output_path)) def build_package(self, build_version, meta): local_output_path = self.conf.get('LOCAL_OUTPUT_PATH', None) project_name = self.conf.get('PROJECT_NAME') project_output_path = os.path.join(local_output_path, project_name) self.copy_sources(project_output_path) self.copy_deployment_configs(project_output_path) build_tar_name = '%s_%s' % (project_name, build_version) build_tar_file_name = DeploymentToolKit.tar( input_path=project_output_path, output_path=local_output_path, tar_file_name=build_tar_name, meta_file_name=project_name, meta=meta, ) return local_output_path, build_tar_name, build_tar_file_name def get_package(self, build_version): project_name = self.conf.get('PROJECT_NAME') tar_file_name = '%s_%s.tar.gz' % (project_name, build_version) local_output_path = self.conf.get('LOCAL_OUTPUT_PATH', None) tar_file_path = os.path.join(local_output_path, tar_file_name) return tar_file_name, tar_file_path def get(self, key): return self.conf.get(key, None)