def __init__(self): self.client_list = [] self.remove_structure("logs") wize_mkdir("logs") self.business_objects = [] self.service_objects = [] self.config = Config() self.log = Log(log_file=os.path.join(self.config.repo_dir, "logs/status.log"), logger_name="definitions").get_logger()
def __pre_init__(self, config=None): """ Initialization executed on first instantiation. """ project_path = os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), "../../") project_path = os.path.realpath(project_path) __config_dir__ = os.path.realpath( os.path.join(project_path, "thrift_medusa/config/")) self.config_dir = __config_dir__ if config is None: config = os.path.join(__config_dir__, "appConfig.yaml") else: config = os.path.join(project_path, config) stream = open(config, 'r') self.__meta_data__ = yaml.load(stream) if len(self.__meta_data__) <= 0: print "Error: could not load configuration yaml file {config}".format( config=config) sys.exit(1) self.config_file = config log_dir = os.path.realpath(os.path.join(config, "../../../logs")) wize_mkdir(log_dir) logger = Log(log_file=os.path.join(log_dir, "status.log"), logger_name="definitions").get_logger() self.log = logger.info
def __init__(self, services, thrift_compiler): self.compiler = thrift_compiler self.config = Config() self.sandbox_work = self.config.work_dir self.status = Status() self.thrift_helper = Thrift(self.compiler) self.log = Log(log_file="status.log", logger_name="status").log self.services = services
class PublishClient(): """ The purpose of this class is to setup the environment for processing various service objects """ def __init__(self): self.client_list = [] self.remove_structure("logs") wize_mkdir("logs") self.business_objects = [] self.service_objects = [] self.config = Config() self.log = Log(log_file=os.path.join(self.config.repo_dir, "logs/status.log"), logger_name="definitions").get_logger() def remove_structure(self, dir): """ Simple method that deletes a directory """ cmd = ['rm', '-fr', dir] self.local_assert(subprocess.call(cmd), "failed to run command: {cmd}".format(cmd=str(cmd))) return 0 def local_assert(self, exit_code, message): """ Defines a cleaner version of an assert that is probably more helpful. """ if exit_code != 0: self.log.error(message) sys.exit(exit_code) def create_structure(self): """ Remove old directory structure and re-copy all the files and dependencies from the appropriate repos. """ self.remove_structure(self.config.work_dir) os.mkdir(self.config.work_dir) self.business_objects = build_file_list(self.config.get_path(type="business_object"), ".thrift") self.service_objects = build_file_list(self.config.get_path(type="service_object"), ".thrift") self.enum_objects = build_file_list(self.config.get_path(type="enum_object"), ".thrift") self.exception_objects = build_file_list(self.config.get_path(type="exception_object"), ".thrift") def update_client_list(self, thrift_objects, compilers): """ Build a list of all clients for each language and compiler type. Note: Multiple thrift compilers not currently supported. """ self.client_list = [] for item in compilers: if self.config.is_java and item.is_language_supported("java"): self.client_list.append(JavaClient(thrift_objects, item)) if self.config.is_ruby and item.is_language_supported("ruby"): self.client_list.append(RubyClient(thrift_objects, item)) if self.config.is_doc_enabled and item.is_language_supported("doc"): self.client_list.append(Documentation(thrift_objects, item)) def process_thrift_services(self): """ This method will iterate through all the service and business object thrift files, and deploy the maven artifacts and its dependencies """ compiler_list = [] for item in self.config.get_thrift_option("compilers"): t = ThriftCompiler(item) compiler_list.append(t) #ensure that vcs is enabled, and thrift-file override hasn't been passed in. thrift_objects = [] if self.config.is_local() and self.config.get_service_override() is not None: pass elif not self.config.is_vcs or self.config.is_local(): #flatten list thrift_objects = self.service_objects + self.business_objects + self.enum_objects + self.exception_objects else: vcs = self.config.get_vcs_instance() file_objects = vcs.get_modified_files() if file_objects is None or len(file_objects) == 0: self.config.is_vcs = False thrift_objects = self.service_objects + self.business_objects + self.enum_objects + self.exception_objects else: self.log.info("Using list of objects from VCS") thrift_objects = map(lambda current_file: os.path.basename(current_file), file_objects) self.log.info("VCS object list is: " + str(thrift_objects)) if self.config.is_local() and self.config.get_service_override() is not None: self.service_objects = [] thrift_objects = [self.config.get_service_override()] self.update_client_list(thrift_objects, compiler_list) process_list = [] for client in self.client_list: p = Process(target=client.run) p.start() process_list.append(p) #wait for all threads that have been started to terminate. map(lambda proc: proc.join(), process_list) # #Check exit codes for proc in process_list: self.local_assert(proc.exitcode, str(proc))