def execute(self, *args, **kwargs): try: output = subprocess.check_output(["python", "--version"], shell=False) Logger.debug("NodeJs version detected is %s" % output) version = PythonVersionDetector.get_most_relative_version(output) except: version = PYTHON_2 return {"version": version}
def execute(self): try: output = subprocess.check_output(["node", "--version"], shell=False) Logger.debug("NodeJs version detected is %s" % output) version = NodeVersionDetector.get_most_relative_version(output) except: version = NODEJS_8 return {"version": version}
def execute(self, *args, **kwargs): Logger.info("Detecting PHP version ...") version = DEFAULT_VERSION try: output = subprocess.check_output(["php", "-version"], shell=False, stderr=subprocess.STDOUT) version = PhpVersionDetector.get_most_relative_version(output) except Exception as e: Logger.debug("Failed to detect PHP version,because of %s" % e) Logger.debug("Use default PHP version:%s instead ." % DEFAULT_VERSION) return {"version": version}
def execute(self): print("Detecting Java version ...") version = default_version; try: output = subprocess.check_output(["java", "-version"], shell=False, stderr=subprocess.STDOUT) version = JavaVersionDetector.get_most_relative_version(output) except Exception as e: Logger.debug("Failed to detect Java version,because of %s" % e) Logger.debug("Use default Java version:%s instead ." % default_version) return {"version": version}
def load(self): with open(self.config_file, "a+") as f: content = f.read() if content is None or content is "" or len(content) is 0: pass else: try: json_dict = json.loads(content)[0]['datapoints'] self.unmarshal(json_dict) except Exception as e: Logger.debug("Failed to load derrick_conf,because of %s" % e)
def get_most_relative_version(version): try: version_section = version.split(" ")[1] if version_section.startswith("2") is True: return PYTHON_2 if version_section.startswith("3") is True: return PYTHON_3 except Exception as e: Logger.debug("Failed to detect Python version(%s) and use default Python version" % version) Logger.debug("Stacktrace is %s" % e) return PYTHON_2
def load(self): with open(self.config_file, "a+") as f: content = f.read() if content is None or content is "" or len(content) is 0: pass else: try: json_dict = json.loads(content)[0]['datapoints'] self.unmarshal(json_dict) except Exception as e: Logger.error("Failed to load .derrick_application_conf,because of %s" % e) Logger.debug("Stack Information:%s" % traceback.format_exec())
def get_most_relative_version(version): try: version_section = version.split(" ")[1] if version_section.startswith("2") is True: return PYTHON_2 if version_section.startswith("3") is True: return PYTHON_3 except Exception as e: Logger.debug( "Failed to detect Python version(%s) and use default Python version" % version) Logger.debug("Stacktrace is %s" % e) return PYTHON_2
def load(self): if self.config_file is None: raise Exception("You should supply at least one config file.") with open(self.config_file, "r") as f: content = f.read() if content is None or content is "" or len(content) is 0: pass else: try: json_dict = json.loads(content) self.unmarshal(json_dict) except Exception as e: Logger.debug("Failed to load derrick_conf,because of %s" % e)
def render_templates(templates_dir=None, dest_dir=None, compile_dict=None): if templates_dir is None or dest_dir is None or compile_dict is None: raise ParamsShortageException("compile templates need some more params") all_success = True for template_name in os.listdir(templates_dir): template_path = os.path.join(templates_dir, template_name) try: Init.render_template(template_path, dest_dir, compile_dict.get(template_name)) except Exception as e: all_success = False Logger.debug("template_path:%s,dest_dir:%s,content:%s" % (template_path, dest_dir, compile_dict.get(template_name))) Logger.debug("Failed to compile template(%s),because of %s" % (template_name, e)) return all_success
def run_commands(self, context): # if you define a command that has the same name with others # the latest registered command will execute commands = self.all() arguments = context.get_arguments() for command_name in commands.keys(): command_name_lower = command_name.lower() if command_name_lower in arguments.keys() and arguments[command_name_lower] is True: command = commands[command_name] try: command.execute(context) # TODO Add command event listener in here # TODO event listener will fire event in the whole lifecycle except Exception as e: Logger.error("Failed to execute command %s,because of %s" % (command_name, e)) Logger.debug(traceback.format_exc())
def get_most_relative_version(version): version_num = str(version)[1:] version_arr = version_num.split(".") detect_version = NODEJS_8 try: base_version = version_arr[0] if base_version == "4": detect_version = NODEJS_4 if base_version == "6": detect_version = NODEJS_6 if base_version == "8": detect_version = NODEJS_8 except Exception as e: Logger.debug("system version is %s,error message is %s" % (version, e)) return detect_version
def execute(self, context): # TODO add application recorder to record the application platform and other things. rigging_manager = Derrick().get_rigging_manager() all_rigging = rigging_manager.all() detected = False handled_rigging = [] for rigging_name in all_rigging: rigging = all_rigging.get(rigging_name) try: handled, platform = rigging.detect(context) if handled is True: detected = True handled_rigging.append({"rigging_name": rigging_name, "rigging": rigging, "platform": platform}) except Exception as e: Logger.error("Failed to detect your application's platform with rigging(%s),because of %s" % (rigging_name, e)) if detected is True: if len(handled_rigging) > 1: # TODO when more than one rigging can handle your application. Logger.warn("More than one rigging can handle the application.") rigging_dict = Init.choose_rigging(handled_rigging) if rigging_dict is None: Logger.error("The Rigging you chosen maybe broken.") return else: rigging_dict = handled_rigging[0] rigging = rigging_dict.get("rigging") rdi = RiggingDetectInfo(rigging_dict.get("rigging_name"), rigging_dict.get("platform")) try: results = rigging.compile(context) Logger.debug("The platform is %s,the rigging used is %s" % (rigging_dict.get("platform"), rigging_dict.get("rigging_name"))) Logger.debug("The results is %s" % results) except Exception as e: Logger.error("Failed to compile your application.because of %s" % e) return if type(results) is dict: try: template_dir = rigging.get_template_dir() dest_dir = context.get(WORKSPACE_ENV) Logger.debug("Ready to render templates and template_dir:%s,dest_dir:%s,compile_dict:%s" % ( template_dir, dest_dir, results)) Init.render_templates(templates_dir=template_dir, dest_dir=dest_dir, compile_dict=results) Logger.info("Derrick detect your platform is %s and compile successfully." % rigging_dict.get("platform")) except Exception as e: Logger.error("Failed to render template with rigging(%s),because of %s" % (rigging.get_name(), e)) try: ApplicationRecorder().record(rdi) except Exception as e: Logger.debug("Failed to record detected information.because of %s" % e) else: raise RiggingCompileException("compile results is not a dict.") else: Logger.warn( "Failed to detect your application's platform." "Maybe you can upgrade Derrick to get more platforms supported.") return
def __init__(self): super(FileRecorder, self).__init__() try: self.load() except Exception as e: Logger.debug("File may not exists and will create after config creation.")