def Test(app): print("Hello " + os.getlogin() + " - (Real user even after sudo / su)") print("Options:") print(app.options) print("Arguments:") print(app.arguments) print("System Configuration:") print(app.configuration) if not app.data is None: print("Data:") print(app.data.dump()) # iterate the configuration keys s = "" for key in app.data: s = s + " " + str(app.data[key]) print(s.strip()) print("") # injected logger app.logger.warning("hello from the injected loggger") # Using explicitely the root logger always logs to the console logging.debug("This is an info of the root logger") # Logging from myapp.lib myapp_cli_logger = logging.getLogger('myapp.cli') myapp_cli_logger.info("This is an info from myapp.cli") # Not recorded myapp_cli_logger.warning("This is a warning from myapp.cli") # -> sample.log myapp_cli_logger.error("This is an error from myapp.cli") # -> sample.log myapp_cli_logger.critical("This is a critical from myapp.cli") # -> sample.log print(call(["echo", ["hi", "$x", "a"]], shell = True)) print(call(["./test.sh", "QXS"], shell = True)) print(call(["./test.sh", "QXS"], shell = False)) print(1/0)
def _handleGitDir(self, appname, appdir, appconfig): rc, stdout, stderr = call(["git", "rev-parse", "--is-inside-work-tree"], cwd=appdir, shell = False) if not (rc == 0 and stdout.strip().lower() == "true"): self.app.logger.debug("App is not a git repository") return None self.app.logger.info("Running git pull ") rc, stdout, stderr = call(["git", "pull"], cwd=appdir, shell = False) if rc != 0: raise RuntimeError("Failed to run git pull with error: " + (stdout.strip() + "\n" + stderr.strip()).strip()) return None
def _runRoleCommand(self, roleconfig, key, ssh, appdir): if not(key in roleconfig and isinstance(roleconfig[key], Configuration)): return True # wrong configuration, nothign done successfully for cmdkey in roleconfig[key]: if isinstance(roleconfig[key][cmdkey].configuration, list): cmd = replaceVars( roleconfig[key][cmdkey].configuration, { "trigger": key, "appdir": appdir } ) if ssh is None: rc, stdout, stderr = call(cmd, shell=True) if rc != 0: self.app.logger.warning(key.upper() + " Command " + str(cmd) + " failed with rc " + str(rc) + ":\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) return False else: self.app.logger.debug(key.upper() + " Command " + str(cmd) + " was successful:\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) else: rc, stdout, stderr = ssh.call(cmd) if rc != 0: self.app.logger.warning(key.upper() + " Command " + str(cmd) + " failed on host \"" + ssh.host + "\" with rc " + str(rc) + ":\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) return False else: self.app.logger.debug(key.upper() + " Command " + str(cmd) + " was successful on host \"" + ssh.host + "\":\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) return True
def _syncLocalAppToRemote(self, ssh, appdir, remoteappdir, srvconfig, excludeList=[]): cmdList = ["rsync", "--delete", "--stats", "--exclude", ".git*"] # built-in excludes for exclude in excludeList: cmdList.extend(["--exclude", exclude]) # configured excludes try: for i in srvconfig["exclude"]: cmdList.extend(["--exclude", srvconfig["exclude"][i]]) except: pass # use rsync if ssh.host == "localhost": cmdList.extend(["-az", appdir + "/", remoteappdir + "/"]) else: cmdList.extend([ "-aze", "ssh", appdir + "/", ssh.host + ":" + remoteappdir + "/" ]) self._logger.debug("Running: " + " ".join(cmdList)) rc, stdout, stderr = call(cmdList) if rc == 0: self._logger.debug("Syncing the app to \"" + ssh.host + ":" + remoteappdir + "\":\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) return True else: self._logger.error("Failed to sync the app to \"" + ssh.host + ":" + remoteappdir + "\":\n" + (stdout.strip() + "\n" + stderr.strip()).strip()) return False