def build(self): self.trigger('source-build-before') #ret=run.script_execute(self.script,[],self.cwd) if not self.host or self.host == "127.0.0.1": stdout,stderr=run.execute_helper(self.script,[],self.cwd) else: client = ssh.SSHUtil(self.host,self.username,self.password) stdout,stderr=client.execute_lines([self.script],cwd=self.cwd) self.trigger('source-build-after') if stderr: LOG.error(stderr) if stdout: LOG.log(stdout) return stdout,stderr
def package(self,cwd,env,host=None,user=None,password=None): cmd=['file_name="'+ self.target % env + '"'] self.trigger('result-package-before') if not host or host == "127.0.0.1": stdout,stderr=run.execute_helper(self.script,cmd,cwd=cwd) else: client = ssh.SSHUtil(host,user,password) stdout,stderr=client.execute_lines([" ".join([self.script] + cmd)],cwd=cwd) self.trigger('result-package-after') if stderr: LOG.error(stderr) if stdout: LOG.log(stdout) return stdout,stderr
def checkout(self,cfg,cwd,version,host,user,password): cmd=['svn' , 'checkout', cfg.url if not version else "%s@%s" % (cfg.url,version),cwd, '--username',cfg.username, '--password',cfg.password, '--non-interactive','--no-auth-cache' ] if not host or host == "127.0.0.1": stdout,stderr=run.simple_execute(cmd,return_stderr=True) else: client=ssh.SSHUtil(host,user,password) stdout,stderr=client.execute_lines(["echo 'rm -rf %s'" % cwd," ".join(cmd)],cwd=None) if stderr: LOG.error(stderr) if stdout: LOG.log(stdout) return stdout,stderr
def _do_service(self,source,build,collect): old_version=None while self.state_start: current_version=source.version() if current_version != old_version: #LOG.flush() LOG.enable_log_cache() LOG.log("current version %s,prev version %s" % (current_version,old_version)) source.checkout(build.cwd,version=current_version,host=build.host,user=build.username,password=build.password) build.build() collect.package(build.cwd,env={'version':current_version,'date':time.strftime("%Y%m%d%H%M%S")},host=build.host,user=build.username,password=build.password) log_array=LOG.disable_log_cache() if self.smtp_host and self.sender: result_email=email.EmailNotify(self.sender,self.result_mails,"release result notify %s" % time.strftime("%Y-%m-%d %X")) result_email.set_body(Server.mail_info % "\n".join(log_array)) result_email.send(self.smtp_host,self.smtp_port,self.sender,self.sender_password) old_version = current_version LOG.log("sleep %s" % self.interval) time.sleep(self.interval)
plugin[mod_name] = obj return plugin def __init__(self,cfg): super(SourceManager,self).__init__(cfg) self.plugin=self.load_extends() self.url=self.get_or_raise(cfg,'url') self.username=self.get_or_raise(cfg,'username') self.password=self.get_or_raise(cfg,'password') self.type=self.get_or_raise(cfg,'type') def checkout(self,cwd,version=None,host='127.0.0.1',user=None,password=None): self.trigger('source-checkout-before') ret=self.plugin[self.type].checkout(self,cwd,version,host,user,password) self.trigger('source-checkout-after') return ret def version(self): return self.plugin[self.type].version(self) def update(self,cwd,version=None): return self.plugin[self.type].update(self,cwd,version) if __name__ == "__main__": a = SourceManager({'url':'svn://192.168.150.75','username':'******','password':'******','type':'svn'}) LOG.log(a.version()) LOG.log(a.checkout('/home/along/test1/diff')) LOG.log(a.update('/home/along/test1/diff'))
def trigger(self, event): if event not in self.EVENT_LIST: raise Exception("no find event '%s'" % event) cfg = self.event.get(event, None) if cfg: LOG.log("******trigger %s******" % cfg)
def status(self): LOG.log("release (%d) Running" % os.getpid())
def term_signal_process(signum, stack): LOG.log("wait process die") self.state_start=False