Example #1
0
 def do_post_deploy(self, log):
     '''
     检出代码后的工作:如编译
     '''
     if self.result.exited == 0:
         self.sequence = 3
         with open(log, 'a') as f:
             f.write('[INFO]------正在执行代码检出后的工作------%s\n' % (self.sequence))
         commands = self.post_deploy
         if commands:
             for command in commands.split('\n'):
                 if command.strip().startswith('#') or not command.strip():
                     continue
                 with self.localhost.cd(self.local_code_path):
                     if self.result.exited == 0:
                         self.result = self.localhost.local(command,
                                                            write=log)
         # 打包编译后的文件:包含或排除
         self.release_version = self.record_id
         with self.localhost.cd(self.local_code_path):
             if self.is_include:
                 files = includes_format(self.local_code_path,
                                         self.excludes)
                 command = 'tar zcf %s/%s %s' % (
                     self.local_project_path.rstrip('/'),
                     self.release_version + '.tar.gz', files)
             else:
                 files = excludes_format(self.local_code_path,
                                         self.excludes)
                 command = 'tar zcf ../%s %s' % (self.release_version +
                                                 '.tar.gz', files)
             if self.result.exited == 0:
                 self.result = self.localhost.local(command, write=log)
Example #2
0
 def do_post_deploy(self, log):
     """
     检出代码后的工作:如编译
     :param log:
     :return:
     """
     if self.result.exited == 0:
         self.sequence = 3
         with open(log, 'a') as f:
             f.write('[INFO]------正在执行代码检出后的工作[%s]------\n' %
                     (self.sequence))
         commands = self.post_deploy
         if commands:
             for command in commands.split('\n'):
                 if command.strip().startswith('#') or not command.strip():
                     continue
                 with self.localhost.cd(self.local_code_path):
                     if self.result.exited == 0:
                         self.result = self.localhost.local(command,
                                                            write=log)
         # 打包编译后的文件:包含或排除
         if self.result.exited == 0:
             self.release_version = self.record_id
             with self.localhost.cd(self.local_code_path):
                 if self.is_include:
                     files = includes_format(self.local_code_path,
                                             self.excludes)
                     for file in files:
                         dirname = file[0]
                         filename = '.' if file[1] == '*' else file[1]
                         tar_name = self.local_project_path.rstrip(
                             '/') + '/' + self.release_version + '.tar'
                         tar_params = 'tar rf' if os.path.exists(
                             tar_name) else 'tar cf'
                         if dirname:
                             command = '%s %s -C %s %s' % (
                                 tar_params, tar_name, dirname, filename)
                             if self.result.exited == 0:
                                 self.result = self.localhost.local(
                                     command, write=log)
                         else:
                             command = '%s %s %s' % (tar_params, tar_name,
                                                     filename)
                             if self.result.exited == 0:
                                 self.result = self.localhost.local(
                                     command, write=log)
                 else:
                     files = excludes_format(self.local_code_path,
                                             self.excludes)
                     command = 'tar cf ../%s %s' % (self.release_version +
                                                    '.tar', files)
                     if self.result.exited == 0:
                         self.result = self.localhost.local(command,
                                                            write=log)