使用 Python 书写项目打包程序(已经存在 shell 的脚本,经过对比 Python 脚本的执行过程更加的可控人性化实现的功能相同)

 #!/usr/bin/env python
# _*_coding:utf-8_*_
# author: 'Edward.Liu'
# dateTime: '15/12/9'
# motto: 'Good memory as bad written'
import datetime, time
import os
import shutil
import subprocess
import tarfile class Packages(object):
def __init__(self):
self.SVN_Checked_Directory = "/install/online/"
self.Project_Directory_F = "%scybershop-front/target" % self.SVN_Checked_Directory
self.Project_Directory_B = "%scybershop-web/target" % self.SVN_Checked_Directory
self.Upload_Directory = "/software/backwar/"
self.Project_Directory_F_Name = "cybershop-front-0.0.1-SNAPSHOT.war"
self.Project_Directory_B_Name = "cybershop-web-0.0.1-SNAPSHOT.war"
self.density_name = ['pro', 'demo', 'ptest']
self.bulid_home = "/install/maven/bin/mvn"
self.date_time = datetime.datetime.now().strftime('%Y-%m-%d-%H') def Subervison_Check(self):
global SVN_NUMBER
try:
while True:
SVN_NUMBER = raw_input("\033[32mPleae Input SVN Update Number:\033[0m").strip()
if SVN_NUMBER.isdigit():
SVN_NUMBER = int(SVN_NUMBER)
if os.path.exists(self.SVN_Checked_Directory):
print "------------------------------"
os.chdir(self.SVN_Checked_Directory)
svn_update = "/usr/bin/svn update -r %s" % SVN_NUMBER
subprocess.call(svn_update, shell=True)
break
else:
print "++++++++++++++++++++++++++++++"
os.makedirs(self.SVN_Checked_Directory)
os.chdir(self.SVN_Checked_Directory)
svn_update = "/usr/bin/svn update -r %s" % SVN_NUMBER
subprocess.call(svn_update, shell=True)
break
else:
print "\033[31mPlease SVN Number\033[0m"
except KeyboardInterrupt:
print 'ctrl+d or z' def Bulid(self):
global env
# 编译项目(分环境)
# 获取生成项目的文件名-- get
bulided_File_Path_F = "%s/%s" % (self.Project_Directory_F, self.Project_Directory_F_Name)
# ---get end
# 编译环境选择--- select---> Maven
for index, value in enumerate(self.density_name):
print index, "Carrefour" + "---->" + value
try:
while True:
Chose_ENV = raw_input("\033[32mChose Density Environment:\033[0m")
if Chose_ENV.isdigit():
Chose_ENV = int(Chose_ENV)
env = self.density_name[Chose_ENV]
try:
if self.density_name[Chose_ENV] == 'pro':
os.chdir(self.SVN_Checked_Directory)
bulid_command = "%s clean install -PcarrefourPro -DskipTests" % self.bulid_home
subprocess.call(bulid_command, shell=True)
if os.path.isfile(bulided_File_Path_F):
print "\033[32mBulid %s SuccessFul\033[0m" % self.density_name[Chose_ENV]
print "\033[32m--------------------Create TarFiles--------------------\033[0m"
self.Files_Handle()
break
elif self.density_name[Chose_ENV] == 'demo':
os.chdir(self.SVN_Checked_Directory)
bulid_command = "%s clean install -Pcarrefour -DskipTests" % self.bulid_home
subprocess.call(bulid_command, shell=True)
if os.path.isfile(bulided_File_Path_F):
print "\033[32mBulid %s SuccessFul\033[0m" % self.density_name[Chose_ENV]
print "\033[32m--------------------Create TarFiles--------------------\033[0m"
self.Files_Handle()
break
elif self.density_name[Chose_ENV] == 'ptest':
os.chdir(self.SVN_Checked_Directory)
bulid_command = "%s clean install -PcarrefourPtest -DskipTests" % self.bulid_home
subprocess.call(bulid_command, shell=True)
if os.path.isfile(bulided_File_Path_F):
print "\033[32mBulid %s SuccessFul\033[0m" % self.density_name[Chose_ENV]
print "\033[32m--------------------Create TarFiles--------------------\033[0m"
self.Files_Handle()
break
except IndexError:
print "\033[31mSelect error\033[0m"
except KeyboardInterrupt:
print "\033[32m Quit\033[0m"
# select----Maven--->END def Files_Handle(self):
# 生成文件处理
# 文件压缩----tar
Tmp_density_dir = "/software/%s%s-%s" % (env, SVN_NUMBER, self.date_time)
os.makedirs(Tmp_density_dir)
source_fiels = ["%s/%s" % (self.Project_Directory_F, self.Project_Directory_F_Name),
"%s/%s" % (self.Project_Directory_B, self.Project_Directory_B_Name)]
for i in range(2):
shutil.move(source_fiels[i], Tmp_density_dir)
# 创建压缩包
os.chdir("/software")
tarfile_name = "%s.tar.gz" % Tmp_density_dir.split('/')[2]
tar = tarfile.open(tarfile_name, "w:gz")
tar.add(Tmp_density_dir.split('/')[2])
tar.close()
# 创建压缩包---end
if os.path.exists(tarfile_name):
print "\033[32m----------Delete Temporary Files%s----------\033[0m" % datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S %f')
shutil.rmtree(Tmp_density_dir)
shutil.move(tarfile_name, self.Upload_Directory)
Upload_Files_Name = "%s%s" % (self.Upload_Directory, tarfile_name)
print "\033[32mSuccessful Download address:URL/%s\033[0m" % tarfile_name
else:
print "\033[31m----------Create archive Is Failed%s----------\033[0m" % datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S %f')
# 删除临时文件
print "\033[32m---------Remove the compiled file%s----------\033[0m" % datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S %f')
if os.path.exists(Upload_Files_Name):
os.chdir("/software")
find_tmp = "find %s -name target" % self.SVN_Checked_Directory
porc = subprocess.Popen(find_tmp, shell=True, stdout=subprocess.PIPE)
export, err = porc.communicate()
out_files = open("path_list.txt", "w")
out_files.write(export)
out_files.close()
fileHandle = open('path_list.txt')
for line in fileHandle.readlines():
print "\033[31mRemove Target\033[0m", line
shutil.rmtree(line.strip('\n'))
fileHandle.close()
os.remove("path_list.txt")
# 删除文件----end def usage(self):
script_name = "packages.py"
print "\033[31m*****************************************\033[0m"
print "\033[31m|------------Packages Useage------------|\033[0m"
print "\033[32m|------------./%s--------------|\033[0m" % script_name
print "\033[32m|------------<path>/%s---------|\033[0m" % script_name
print "\033[32m|----------脚本执行过程2部人工干预------|\033[0m"
print "\033[32m|----------1.收到输入 SVN 版本号--------|\033[0m"
print "\033[32m|----------2.选择需要打包的环境---------|\033[0m"
print "\033[32m|----------3.复制输出下载链接进行下载---|\033[0m"
print "\033[31m******************************************\033[0m" if __name__ == '__main__':
Run_packages = Packages()
Run_packages.usage()
Run_packages.Subervison_Check()
Run_packages.Bulid()

Python package project的更多相关文章

  1. graphterm 0.40.1 : Python Package Index

    graphterm 0.40.1 : Python Package Index graphterm 0.40.1 Downloads ↓ A Graphical Terminal Interface ...

  2. How to using PyPI publish a Python package

    How to using PyPI publish a Python package PyPI & Python package https://pypi.org/ main make a f ...

  3. 使用NuGet Package Project快速制作NuGet包

    今天在visual studio gallery发现了一个插件NuGet Package Project,通过它可以在Visual Studio中建立Nuget Package工程,直接生成Nuget ...

  4. Ghost.py 0.1b3 : Python Package Index

    Ghost.py 0.1b3 : Python Package Index Ghost.py 0.1b3 Download Ghost.py-0.1b3.tar.gz Webkit based web ...

  5. pyrailgun 0.24 : Python Package Index

    pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...

  6. qrcode 4.0.4 : Python Package Index

    qrcode 4.0.4 : Python Package Index qrcode 4.0.4 Download qrcode-4.0.4.tar.gz QR Code image generato ...

  7. bottle-session 0.3 : Python Package Index

    bottle-session 0.3 : Python Package Index bottle-session 0.3

  8. bottle-session 0.2 : Python Package Index

    bottle-session 0.2 : Python Package Index bottle-session 0.2 Download bottle-session-0.2.tar.gz Redi ...

  9. django-cookieless 0.7 : Python Package Index

    django-cookieless 0.7 : Python Package Index django-cookieless 0.7 Download django-cookieless-0.7.ta ...

随机推荐

  1. webpack4.X + react-router 路由跳转

    webpack4.X  react-router 环境准备工作:windows7.webStorm 2017.1.4.Nodejs 8.7.0.npm 5.4.2 PS:安装的时我们都带上版本,这样即 ...

  2. 如何用好 IDEA ,Java 撸码效率至少提升 5 倍?

    以前的Java项目中,充斥着太多不友好的代码:POJO的getter/setter/toString:异常处理:I/O流的关闭操作等等,这些样板代码既没有技术含量,又影响着代码的美观,Lombok应运 ...

  3. 告别传统机房:3D 机房数据可视化实现智能化与VR技术的新碰撞

    前言 随着各行业对计算机依赖性的日益提高,计算机信息系统的发展使得作为其网络设备.主机服务器.数据存储设备.网络安全设备等核心设备存放地的计算机机房日益显现出它的重要地位,而机房的环境和动力设备如供配 ...

  4. css3-pointer-events_demo

    该demo定义了一个菜单,点击了一次之后就不能再点击,另外其中也用到了flex布局,可直接将代码复制运行即可 <html> <head> <meta name=" ...

  5. JZOJ2018提高组-测绘

    测绘 题目大意 为了研究农场的气候, \(Betsy\) 帮助农夫 \(John\) 做了 \(N(1 <= N <= 100)\) 次气压测量并按顺序记录了结果 \(M_1...M_N( ...

  6. PE文件格式详解(一)

    PE文件格式介绍(一) 0x00 前言 PE文件是portable File Format(可移植文件)的简写,我们比较熟悉的DLL和exe文件都是PE文件.了解PE文件格式有助于加深对操作系统的理解 ...

  7. [JAVA]使用字节流拷贝文件

    import java.io.*; /** * @Description: * @projectName:JavaTest * @see:PACKAGE_NAME * @author:郑晓龙 * @c ...

  8. MATLAB GUI之ABC

    GUIDE 属性设置 name 更改名字 logo 在GUI的".m"文件中的OpeningFcn函数或者OutputFcn函数中添加以下代码: % 设置页面左上角的 LogoI ...

  9. SpringBoot执行定时任务@Scheduled

    SpringBoot执行定时任务@Scheduled 在做项目时,需要一个定时任务来接收数据存入数据库,后端再写一个接口来提供该该数据的最新的那一条. 数据保持最新:设计字段sign的值(0,1)来设 ...

  10. 数据可视化之DAX篇(八) DAX学习:使用VAR定义变量

    https://zhuanlan.zhihu.com/p/64414205 前面介绍如何使用DAX生成日期表的时候,使用了VAR,有人留言问这个VAR怎么理解,那么这篇文章就来介绍VAR以及它的用法. ...