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 ...
随机推荐
- vue全家桶(3.2)
4.5.创建实例 可以创建一个自定义实例应用于多个请求接口 <template> <div class="page"> </div> </ ...
- 调用微信内置的方法及wx.config的配置问题
首先请看网址: https://www.w3cschool.cn/weixinkaifawendang/h8ap1qe5.html 重点说下怎么配置wx.config(为了安全,所有的参数都在服务端获 ...
- 逻辑式编程语言极简实现(使用C#) - 2. 一道逻辑题:谁是凶手
本系列前面的文章: 逻辑式编程语言极简实现(使用C#) - 1. 逻辑式编程语言介绍 这是一道Prolog经典的练习题,中文翻译版来自阮一峰的文章<Prolog 语言入门教程>. 问题 B ...
- JVM垃圾回收概述
垃圾回收概述 什么是垃圾 什么是垃圾( Garbage) 呢? 垃圾是指在运行程序中没有任何指针指向的对象,这个对象就是需要被回收的垃圾. 如果不及时对内存中的垃圾进行清理,那么,这些垃圾对象所占的内 ...
- 洛谷 P2296 【寻找道路】
这道题真的很女少啊 言归正传: 这道题其实就是考验的思路,读题后,我们发现对于某个点他所连接的点必须连接终点,那么我们直接反向存图,从终点进行bfs,可以找到未连接的点,然后对这些点所连接的点进行标记 ...
- SqueezeNet/SqueezeNext简述 | 轻量级网络
SqueezeNet系列是比较早期且经典的轻量级网络,SqueezeNet使用Fire模块进行参数压缩,而SqueezeNext则在此基础上加入分离卷积进行改进.虽然SqueezeNet系列不如Mob ...
- mybatis关于Criteria的一点小坑。。。
目录 在用Criteria时,相关代码如下: final RolePermissionExample example = new RolePermissionExample(); example.cr ...
- Oracle Solaris 10图文安装
文章目录 1. 虚拟机软件 2. solaris 10镜像 3. 安装OS 4. 允许远程使用root用户登录SSH 5. bash配置 5.1. 修改bash 5.2. 修改提示符 6. CRT连接 ...
- (私人收藏)精美PPT模板
精美PPT模板 https://pan.baidu.com/s/1vsRnX5h7t3MZ7qdrFvuI1wsucr
- Vue中$nextTick的理解
Vue中$nextTick的理解 Vue中$nextTick方法将回调延迟到下次DOM更新循环之后执行,也就是在下次DOM更新循环结束之后执行延迟回调,在修改数据之后立即使用这个方法,能够获取更新后的 ...