Python package project
使用 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的更多相关文章
- graphterm 0.40.1 : Python Package Index
graphterm 0.40.1 : Python Package Index graphterm 0.40.1 Downloads ↓ A Graphical Terminal Interface ...
- 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 ...
- 使用NuGet Package Project快速制作NuGet包
今天在visual studio gallery发现了一个插件NuGet Package Project,通过它可以在Visual Studio中建立Nuget Package工程,直接生成Nuget ...
- 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 ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- 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 ...
- bottle-session 0.3 : Python Package Index
bottle-session 0.3 : Python Package Index bottle-session 0.3
- 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 ...
- django-cookieless 0.7 : Python Package Index
django-cookieless 0.7 : Python Package Index django-cookieless 0.7 Download django-cookieless-0.7.ta ...
随机推荐
- python+opencv图像增强——拉普拉斯
img = cv2.imread(r'F:\python\work\cv_learn\clipboard.png',1) cv2.imshow('input',img) kernel = np.arr ...
- 双缓冲显示字幕(卡拉ok字幕)
思路: 1.设置定时器SetTime,在Ontime()里面确定显示矩形的大小,让后用DrawText把字铁道矩形上面: 2. int nTextHei = dc.GetTextExtent( m_s ...
- webpack4.X + react-router 路由跳转
webpack4.X react-router 环境准备工作:windows7.webStorm 2017.1.4.Nodejs 8.7.0.npm 5.4.2 PS:安装的时我们都带上版本,这样即 ...
- JS控制滚动条的位置
转载▼http://blog.sina.com.cn/s/blog_4481a3460100rwwu.html JS控制滚动条的位置:window.scrollTo(x,y); 竖向滚动条置顶 ...
- ibit-mybatis 2.x 介绍
原文链接:ibit-mybatis 2.x 介绍 概述 ibit-mybatis 是一个 Mybatis 的增强工具,在 Mybatis 的基础上增加了新的特性与功能,志在简化开发流程.提高开发效率. ...
- 转载--未看关于移动端Web远程开发调试
移动端Web开发调试之Chrome远程调试(Remote Debugging) http://blog.csdn.net/freshlover/article/details/42528643 移动端 ...
- 洛谷 P3694 邦邦的大合唱站队 状压DP
题目描述 输入输出样例 输入 #1 复制 12 4 1 3 2 4 2 1 2 3 1 1 3 4 输出 #1 复制 7 说明/提示 分析 首先要注意合唱队排好队之后不一定是按\(1.2.3..... ...
- Django---进阶1
目录 静态文件配置 request对象方法初识 pycharm链接数据库(MySQL) django链接数据库(MySQL) Django ORM 字段的增删改查 数据的增删改查 今日作业 静态文件配 ...
- postman 进阶技巧
cookie 清除缓存 code 生成接口自动化测试脚本 响应部分 pretty 响应以json或xml显示 raw 响应以文本显示 preview 以HTML网页行驶显示 断言 断言:用于判断接口请 ...
- SpringBoot2.x入门:应用打包与启动
前提 这篇文章是<SpringBoot2.x入门>专辑的第5篇文章,使用的SpringBoot版本为2.3.1.RELEASE,JDK版本为1.8. 这篇文章分析一个偏向于运维方面的内容: ...