自己写的fabric脚本


功能:使用fabric自动化发版


点击(此处)折叠或打开

  1. #-*-coding:utf8-*-
  2. from fabric.api import *
  3. import subprocess
  4. import os
  5. import sys
  6. import glob
  7. import shutil

  8. env.roledefs = {
  9.         'cz-oms-core':['[email protected]','[email protected]'],
  10.         'cz-oms-core-new':['[email protected]','[email protected]'],
  11.         'cz-oms-core-new1':['[email protected]','[email protected]'],
  12.         'cz':['[email protected]']
  13.     }



  14. env.passwords = {
  15.         '[email protected]:22':'fdfdfsdf',
  16.         '[email protected]:22':'fdfdfsdf',
  17.         '[email protected]:22':'fdfdfsdf',
  18.         '[email protected]:22':'fdfdfsdf',
  19.         '[email protected]:22':'fdfdfsdf',
  20.         '[email protected]:22':'fdfdfsdf',
  21.         '[email protected]:22':'appuser@0630',
  22.     }


  23. #通用函数
  24. def unzip():
  25.     with lcd('patch'):
  26.         local('winrar x *.zip')

  27. #Update SVN
  28. def UpdateSVN(path):
  29.     p = subprocess.Popen(['svn','update',path],shell=True,stdout=subprocess.PIPE)
  30.     print p.stdout.readlines()


  31.     
  32. #根据filelist生成发版目录
  33. def faban_dir():
  34.     count = 0
  35.     with open('filelist.txt','r') as f:
  36.         for line in f:
  37.             if line.startswith('bj-oms-api'):
  38.                 #filelist文件路径预处理
  39.                 classpath_filename = line.replace('bj-oms-api/src/main/java/','../online_svn/bj-oms/bj-oms-api/target/classes/')
  40.                 classpath_filename = classpath_filename.replace('.java','.class')
  41.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  42.                 #构造patch目录结构
  43.                 patchpath_filename = line.replace('bj-oms-api/src/main/java/','')
  44.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  45.                 patchpath_filename = patchpath_filename.replace('\n','')
  46.                 patchpath_filename = 'patch/' + 'bj-oms-api/' + patchpath_filename
  47.                 patchpath = os.path.dirname(patchpath_filename)
  48.                 #如果patch目录不存在,就建立目录
  49.                 try:
  50.                     os.listdir(patchpath)
  51.                 except WindowsError:
  52.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  53.                 #拷贝父类到patch目录下
  54.                 parentclass_path_filename = classpath_filename
  55.                 patchpath_filename = patchpath_filename
  56.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  57.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  58.                 count += 1
  59.                 print "***********第%s个文件拷贝成功***************" % count
  60.                 #用glob寻找子类
  61.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  62.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  63.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  64.                 #把子类拷贝到patch目录下
  65.                 for subclass_path_filename in subclass_path_filenames:
  66.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  67.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-api/target/classes/','patch/bj-oms-api/')
  68.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  69.                     shutil.copy(subclass_path_filename,patchpath_filename)
  70.                     count += 1
  71.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  72.             elif line.startswith('bj-oms-domain'):
  73.                 #filelist文件路径预处理
  74.                 classpath_filename = line.replace('bj-oms-domain/src/main/java/','../online_svn/bj-oms/bj-oms-domain/target/classes/')
  75.                 classpath_filename = classpath_filename.replace('.java','.class')
  76.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  77.                 #构造patch目录结构
  78.                 patchpath_filename = line.replace('bj-oms-domain/src/main/java/','')
  79.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  80.                 patchpath_filename = patchpath_filename.replace('\n','')
  81.                 patchpath_filename = 'patch/' + 'bj-oms-domain/' + patchpath_filename
  82.                 patchpath = os.path.dirname(patchpath_filename)
  83.                 #如果patch目录不存在,就建立目录
  84.                 try:
  85.                     os.listdir(patchpath)
  86.                 except WindowsError:
  87.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  88.                 #拷贝父类到patch目录下
  89.                 parentclass_path_filename = classpath_filename
  90.                 patchpath_filename = patchpath_filename
  91.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  92.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  93.                 count += 1
  94.                 print "***********第%s个文件拷贝成功***************" % count
  95.                 #用glob寻找子类
  96.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  97.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  98.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  99.                 #把子类拷贝到patch目录下
  100.                 for subclass_path_filename in subclass_path_filenames:
  101.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  102.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-domain/target/classes/','patch/bj-oms-domain/')
  103.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  104.                     shutil.copy(subclass_path_filename,patchpath_filename)
  105.                     count += 1
  106.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  107.             elif line.startswith('bj-oms-core-new1'): #位置1,不可调换,因为bj-oms-core包含bj-oms-core-new1
  108.                 #filelist文件路径预处理
  109.                 classpath_filename = line.replace('bj-oms-core-new1/src/main/java/','../online_svn/bj-oms/bj-oms-core-new1/target/classes/')
  110.                 classpath_filename = classpath_filename.replace('.java','.class')
  111.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  112.                 #构造patch目录结构
  113.                 patchpath_filename = line.replace('bj-oms-core-new1/src/main/java/','')
  114.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  115.                 patchpath_filename = patchpath_filename.replace('\n','')
  116.                 patchpath_filename = 'patch/' + 'bj-oms-core-new1/' + patchpath_filename
  117.                 patchpath = os.path.dirname(patchpath_filename)
  118.                 #如果patch目录不存在,就建立目录
  119.                 try:
  120.                     os.listdir(patchpath)
  121.                 except WindowsError:
  122.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  123.                 #拷贝父类到patch目录下
  124.                 parentclass_path_filename = classpath_filename
  125.                 patchpath_filename = patchpath_filename
  126.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  127.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  128.                 count += 1
  129.                 print "***********第%s个文件拷贝成功***************" % count
  130.                 #用glob寻找子类
  131.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  132.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  133.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  134.                 #把子类拷贝到patch目录下
  135.                 for subclass_path_filename in subclass_path_filenames:
  136.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  137.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core-new1/target/classes/','patch/bj-oms-core-new1/')
  138.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  139.                     shutil.copy(subclass_path_filename,patchpath_filename)
  140.                     count += 1
  141.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  142.             elif line.startswith('bj-oms-core'): #位置2,不可调换,因为bj-oms-core包含bj-oms-core-new1
  143.                 #filelist文件路径预处理
  144.                 classpath_filename = line.replace('bj-oms-core/src/main/java/','../online_svn/bj-oms/bj-oms-core/target/classes/')
  145.                 classpath_filename = classpath_filename.replace('.java','.class')
  146.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  147.                 #构造patch目录结构
  148.                 patchpath_filename = line.replace('bj-oms-core/src/main/java/','')
  149.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  150.                 patchpath_filename = patchpath_filename.replace('\n','')
  151.                 patchpath_filename = 'patch/' + 'bj-oms-core/' + patchpath_filename
  152.                 patchpath = os.path.dirname(patchpath_filename)
  153.                 #如果patch目录不存在,就建立目录
  154.                 try:
  155.                     os.listdir(patchpath)
  156.                 except WindowsError:
  157.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  158.                 #拷贝父类到patch目录下
  159.                 parentclass_path_filename = classpath_filename
  160.                 patchpath_filename = patchpath_filename
  161.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  162.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  163.                 count += 1
  164.                 print "***********第%s个文件拷贝成功***************" % count
  165.                 #用glob寻找子类
  166.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  167.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  168.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  169.                 #把子类拷贝到patch目录下
  170.                 for subclass_path_filename in subclass_path_filenames:
  171.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  172.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core/target/classes/','patch/bj-oms-core/')
  173.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  174.                     shutil.copy(subclass_path_filename,patchpath_filename)
  175.                     count += 1
  176.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  177.             elif line.startswith('bj-oms-rest'):
  178.                 #filelist文件路径预处理
  179.                 classpath_filename = line.replace('bj-oms-rest/src/main/java/','../online_svn/bj-oms/bj-oms-rest/target/classes/')
  180.                 classpath_filename = classpath_filename.replace('.java','.class')
  181.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  182.                 #构造patch目录结构
  183.                 patchpath_filename = line.replace('bj-oms-rest/src/main/java/','')
  184.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  185.                 patchpath_filename = patchpath_filename.replace('\n','')
  186.                 patchpath_filename = 'patch/' + 'bj-oms-rest/' + patchpath_filename
  187.                 patchpath = os.path.dirname(patchpath_filename)
  188.                 #如果patch目录不存在,就建立目录
  189.                 try:
  190.                     os.listdir(patchpath)
  191.                 except WindowsError:
  192.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  193.                 #拷贝父类到patch目录下
  194.                 parentclass_path_filename = classpath_filename
  195.                 patchpath_filename = patchpath_filename
  196.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  197.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  198.                 count += 1
  199.                 print "***********第%s个文件拷贝成功***************" % count
  200.                 #用glob寻找子类
  201.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  202.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  203.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  204.                 #把子类拷贝到patch目录下
  205.                 for subclass_path_filename in subclass_path_filenames:
  206.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  207.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-rest/target/classes/','patch/bj-oms-rest/')
  208.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  209.                     shutil.copy(subclass_path_filename,patchpath_filename)
  210.                     count += 1
  211.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  212.             elif line.startswith('bj-oms-jobs'):
  213.                 #filelist文件路径预处理
  214.                 classpath_filename = line.replace('bj-oms-jobs/src/main/java/','../online_svn/bj-oms/bj-oms-jobs/target/classes/')
  215.                 classpath_filename = classpath_filename.replace('.java','.class')
  216.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  217.                 #构造patch目录结构
  218.                 patchpath_filename = line.replace('bj-oms-jobs/src/main/java/','')
  219.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  220.                 patchpath_filename = patchpath_filename.replace('\n','')
  221.                 patchpath_filename = 'patch/' + 'bj-oms-jobs/' + patchpath_filename
  222.                 patchpath = os.path.dirname(patchpath_filename)
  223.                 #如果patch目录不存在,就建立目录
  224.                 try:
  225.                     os.listdir(patchpath)
  226.                 except WindowsError:
  227.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  228.                 #拷贝父类到patch目录下
  229.                 parentclass_path_filename = classpath_filename
  230.                 patchpath_filename = patchpath_filename
  231.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  232.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  233.                 count += 1
  234.                 print "***********第%s个文件拷贝成功***************" % count
  235.                 #用glob寻找子类
  236.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  237.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  238.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  239.                 #把子类拷贝到patch目录下
  240.                 for subclass_path_filename in subclass_path_filenames:
  241.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  242.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-jobs/target/classes/','patch/bj-oms-jobs/')
  243.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  244.                     shutil.copy(subclass_path_filename,patchpath_filename)
  245.                     count += 1
  246.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count

  247.             elif line.startswith('bj-tran'):
  248.                 #filelist文件路径预处理
  249.                 classpath_filename = line.replace('bj-tran/src/main/java/','../online_svn/bj-tran/target/classes/')
  250.                 classpath_filename = classpath_filename.replace('.java','.class')
  251.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  252.                 #构造patch目录结构
  253.                 patchpath_filename = line.replace('bj-tran/src/main/java/','')
  254.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  255.                 patchpath_filename = patchpath_filename.replace('\n','')
  256.                 patchpath_filename = 'patch/' + 'bj-tran/' + patchpath_filename
  257.                 patchpath = os.path.dirname(patchpath_filename)
  258.                 #如果patch目录不存在,就建立目录
  259.                 try:
  260.                     os.listdir(patchpath)
  261.                 except WindowsError:
  262.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  263.                 #拷贝父类到patch目录下
  264.                 parentclass_path_filename = classpath_filename
  265.                 patchpath_filename = patchpath_filename
  266.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  267.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  268.                 count += 1
  269.                 print "***********第%s个文件拷贝成功***************" % count
  270.                 #用glob寻找子类
  271.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  272.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  273.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  274.                 #把子类拷贝到patch目录下
  275.                 for subclass_path_filename in subclass_path_filenames:
  276.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  277.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-tran/target/classes/','patch/bj-tran/')
  278.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  279.                     shutil.copy(subclass_path_filename,patchpath_filename)
  280.                     count += 1
  281.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count


  282.             elif line.startswith('bj-whm-rest'):
  283.                 #filelist文件路径预处理
  284.                 classpath_filename = line.replace('bj-whm-rest/src/main/java/','../online_svn/bj-whm-rest/target/classes/')
  285.                 classpath_filename = classpath_filename.replace('.java','.class')
  286.                 classpath_filename = classpath_filename.replace('\n','') #去掉换行符
  287.                 #构造patch目录结构
  288.                 patchpath_filename = line.replace('bj-whm-rest/src/main/java/','')
  289.                 patchpath_filename = patchpath_filename.replace('.java','.class')
  290.                 patchpath_filename = patchpath_filename.replace('\n','')
  291.                 patchpath_filename = 'patch/' + 'bj-whm-rest/' + patchpath_filename
  292.                 patchpath = os.path.dirname(patchpath_filename)
  293.                 #如果patch目录不存在,就建立目录
  294.                 try:
  295.                     os.listdir(patchpath)
  296.                 except WindowsError:
  297.                     os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
  298.                 #拷贝父类到patch目录下
  299.                 parentclass_path_filename = classpath_filename
  300.                 patchpath_filename = patchpath_filename
  301.                 print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
  302.                 shutil.copy(parentclass_path_filename,patchpath_filename)
  303.                 count += 1
  304.                 print "***********第%s个文件拷贝成功***************" % count
  305.                 #用glob寻找子类
  306.                 path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
  307.                 filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
  308.                 subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
  309.                 #把子类拷贝到patch目录下
  310.                 for subclass_path_filename in subclass_path_filenames:
  311.                     subclass_path_filename = subclass_path_filename.replace('\\',r'/')
  312.                     patchpath_filename = subclass_path_filename.replace('../online_svn/bj-whm-rest/target/classes/','patch/bj-whm-rest/')
  313.                     print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
  314.                     shutil.copy(subclass_path_filename,patchpath_filename)
  315.                     count += 1
  316.                     print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
  317.             
  318.             
  319.             else:
  320.                 print "%s:该项目没有配置,请联系管理员" % line
  321.                 sys.exit()

  322.        
  323. #down jar包
  324. @hosts('[email protected]')
  325. def download_bj_oms_api_jar():
  326.     get('/opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar','patch/bj-oms-api/')

  327. @hosts('[email protected]')
  328. def download_bj_oms_domain_jar():
  329.     get('/opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar','patch/bj-oms-domain/')

  330. @hosts('[email protected]')
  331. def download_bj_oms_core_new1_jar():
  332.     get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core-new1/')

  333. @hosts('[email protected]')
  334. def download_bj_oms_rest_jar():
  335.     get('/opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar','patch/bj-oms-rest/')

  336. @hosts('[email protected]')
  337. def download_bj_oms_job_jar():
  338.     get('/opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar','patch/bj-oms-jobs/')

  339. @hosts('[email protected]')
  340. def download_bj_oms_core_jar():
  341.     get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core/')


  342. #替换jar包里面的文件
  343. def replace_file_to_local_bj_oms_api_jar():
  344.     with lcd('patch/bj-oms-api/'):
  345.         local('jar -uvf bj-oms-api-1.0-SNAPSHOT.jar * ')
  346. '''
  347. def replace_file_to_local_bj_oms_core_new1_jar():
  348.     with lcd('patch/bj-oms-core-new1/'):
  349.         local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')
  350. '''
  351.         
  352. def replace_file_to_local_bj_oms_domain_jar():
  353.     with lcd('patch/bj-oms-domain/'):
  354.         local('jar -uvf bj-oms-domain-1.0-SNAPSHOT.jar * ')
  355.         
  356. def replace_file_to_local_bj_oms_job_jar():
  357.     with lcd('patch/bj-oms-job/'):
  358.         local('jar -uvf bj-oms-job-1.0-SNAPSHOT.jar * ')

  359. def replace_file_to_local_bj_oms_rest_jar():
  360.     with lcd('patch/bj-oms-rest/'):
  361.         local('jar -uvf bj-oms-rest-1.0-SNAPSHOT.jar * ')

  362. def replace_file_to_local_bj_oms_core_jar():
  363.     with lcd('patch/bj-oms-core/'):
  364.         local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')

  365.         


  366. #backup
  367. @hosts('[email protected]')
  368. def backup_bj_oms_api_jar():
  369.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar /backup/$dir1')
  370.     puts('bj-oms-api-1.0-SNAPSHOT.jar包备份到了10.2.88.47的/backup目录下')

  371. @hosts('[email protected]')
  372. def backup_bj_oms_domain_jar():
  373.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar /backup/$dir1')
  374.     puts('bj-oms-domain-1.0-SNAPSHOT.jar包备份到了10.2.88.47的/backup目录下')

  375. @hosts('[email protected]')
  376. def backup_bj_oms_core_new1_jar():
  377.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
  378.     puts('bj-oms-core-1.0-SNAPSHOT.jar包备份到了10.2.88.40的/backup目录下')

  379. @hosts('[email protected]')
  380. def backup_bj_oms_rest_jar():
  381.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar /backup/$dir1')
  382.     puts('bj-oms-rest-1.0-SNAPSHOT.jar包备份到了10.2.88.30的/backup/目录下')

  383. @hosts('[email protected]')
  384. def backup_bj_oms_job_jar():
  385.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/bj-oms-job/$dir1 && cp -a /opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar /backup/bj-oms-job/$dir1')
  386.     puts('bj-oms-job-1.0-SNAPSHOT.jar包备份到了10.2.88.30的/backup/目录下')

  387. @hosts('[email protected]')
  388. def backup_bj_web():
  389.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/tomcat-oms/webapps/bj-web /backup/$dir1')
  390.     puts('bj-web包备份到了10.2.88.30的/backup/目录下')

  391. @hosts('[email protected]')
  392. def backup_bj_oms_core_jar():
  393.     run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
  394.     puts('bj_oms_core包备份到了10.2.88.30的/backup/目录下')

  395.     
  396. #发版,上传jar包
  397. @hosts('[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]')
  398. def put_bj_oms_api_jar_4748_3746_4041():
  399.     with lcd ('patch/bj-oms-api/'):
  400.         put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib/')

  401. @hosts('[email protected]')
  402. def put_bj_oms_api_jar_30():
  403.     with lcd ('patch/bj-oms-api/'):
  404.         put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
  405.         put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
  406.         put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
  407.         

  408. @hosts('[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]')
  409. def put_bj_oms_domain_jar_4748_3746_4041():
  410.     with lcd ('patch/bj-oms-domain/'):
  411.         put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')

  412. @hosts('[email protected]')
  413. def put_bj_oms_domain_jar_30():
  414.     with lcd ('patch/bj-oms-domain/'):
  415.         put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
  416.         put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
  417.         put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
  418.         

  419. @roles('cz-oms-core-new1')
  420. def put_bj_oms_core_new1_jar():
  421.     with lcd ('patch/bj-oms-core-new1/'):
  422.         put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')

  423. @roles('cz')
  424. def put_bj_oms_rest_jar():
  425.     with lcd ('patch/bj-oms-rest/'):
  426.         put('bj-oms-rest-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')

  427. @roles('cz')
  428. def put_bj_oms_job_jar():
  429.     with lcd ('patch/bj-oms-jobs/'):
  430.         put('bj-oms-job-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')

  431. @roles('cz')
  432. def put_bj_web():
  433.     with lcd ('patch/'):
  434.         put('bj-web.zip','/opt/tomcat-oms/webapps')
  435.         run('cd /opt/tomcat-oms/webapps && unzip -o bj-web.zip && rm -rf bj-web.zip')

  436. @roles('cz-oms-core')
  437. def put_bj_oms_core_jar():
  438.     with lcd ('patch/bj-oms-core'):
  439.         put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')


  440. #重启服务
  441. @roles('cz-oms-core')
  442. def stop_cz_oms_core_4748():
  443.     sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)

  444. @roles('cz-oms-core')
  445. def start_cz_oms_core_4748():
  446.     sudo('/opt/bj-oms-core/bin/start.sh',pty=False)

  447.     

  448. @roles('cz-oms-core-new')
  449. def stop_cz_oms_core__new_3746():
  450.     sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)

  451. @roles('cz-oms-core-new')
  452. def start_cz_oms_core__new_3746():
  453.     sudo('nohup /opt/bj-oms-core/bin/start.sh &',pty=False)



  454. @roles('cz-oms-core-new1')
  455. def stop_cz_oms_core__new1_4041():
  456.     sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)

  457. @roles('cz-oms-core-new1')
  458. def start_cz_oms_core__new1_4041():
  459.     sudo('/opt/bj-oms-core/bin/start.sh',pty=False)


  460.     

  461. @roles('cz')
  462. def stop_cz_bj_oms_rest_30():
  463.     sudo('/opt/bj-oms-rest/bin/stop.sh',pty=False)
  464.     
  465. @roles('cz')
  466. def start_cz_bj_oms_rest_30():
  467.     sudo('nohup /opt/bj-oms-rest/bin/start.sh &',pty=False)

  468.     

  469. @roles('cz')
  470. def stop_cz_bj_oms_job_30():
  471.     sudo('/opt/bj-oms-job/bin/stop.sh',pty=False)

  472. @roles('cz')
  473. def start_cz_bj_oms_job_30():
  474.     sudo('/opt/bj-oms-job/bin/start.sh',pty=False)


  475.     
  476. @roles('cz')
  477. def stop_cz_tomcat_oms_30():
  478.     sudo('/opt/tomcat-oms/bin/shutdown.sh',pty=False)
  479.     
  480. @roles('cz')
  481. def start_cz_tomcat_oms_30():
  482.     sudo('/opt/tomcat-oms/bin/start.sh',pty=False)



  483.     

  484.         


  485. #主程序
  486. if __name__ == '__main__':
  487.     #Update SVN
  488.     while True:
  489.         temp = str(raw_input('1) 请问你要Update SVN吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  490.         tips = temp.strip().lower()
  491.         if tips == 'yes':
  492.             print "Now begin Update SVN..."
  493.             UpdateSVN('../online_svn/bj-oms/bj-oms-api')
  494.             UpdateSVN('../online_svn/bj-oms/bj-oms-core')
  495.             UpdateSVN('../online_svn/bj-oms/bj-oms-core-new')
  496.             UpdateSVN('../online_svn/bj-oms/bj-oms-core-new1')
  497.             UpdateSVN('../online_svn/bj-oms/bj-oms-domain')
  498.             UpdateSVN('../online_svn/bj-oms/bj-oms-jobs')
  499.             UpdateSVN('../online_svn/bj-oms/bj-oms-rest')
  500.             UpdateSVN('../online_svn/bj-tran')
  501.             UpdateSVN('../online_svn/bj-whm')
  502.             break
  503.         elif tips == 'no':
  504.             break
  505.     #删除patch目录下所有内容
  506.     while True:
  507.         temp = str(raw_input('2)删除patch目录下所有目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  508.         tips = temp.strip().lower()
  509.         if tips == 'yes':
  510.             for line in os.listdir('patch'):
  511.                 shutil.rmtree('patch/%s' % line)
  512.             break
  513.         elif tips == 'no':
  514.             break

  515.  #提示是否eclipse编译代码
  516.     while True:
  517.         temp = str(raw_input('3) 提示:请问你手工通过eclse编译css代码了吗[yes/no]:'))
  518.         tips = temp.strip().lower()
  519.         if tips == 'yes':
  520.             break
  521.         elif tips == 'no':
  522.             break
  523.         

  524.     #根据filelist生成发版目录
  525.     while True:
  526.         temp = str(raw_input('4)根据filelist生成发版目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  527.         tips = temp.strip().lower()
  528.         if tips == 'yes':
  529.             print "Now begin generate faban dir..."
  530.             faban_dir()
  531.             break
  532.         elif tips == 'no':
  533.             break
  534.          

  535.     #unzip
  536.     while True:
  537.         temp = str(raw_input('5)解压zip包到本地patch目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  538.         tips = temp.strip().lower()
  539.         if tips == 'yes':
  540.             print "Now begin unzip jar to patch dir..."
  541.             output = subprocess.check_output(['fab','unzip'],shell=True,stderr = subprocess.STDOUT)
  542.             print output
  543.             break
  544.         elif tips == 'no':
  545.             break
  546.     
  547.     #download jar to localpath
  548.     while True:
  549.         temp = str(raw_input('6)把jar包下载到本地的patch目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  550.         tips = temp.strip().lower()
  551.         if tips == 'yes':
  552.             print "Now begin download jar to patch dir..."
  553.             dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
  554.             for index,item in enumerate(dirs,1):
  555.                 if item == 'bj-oms-api':
  556.                     print "%d: %s is downoading..." % (index,item)
  557.                     output = subprocess.check_output(['fab','download_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
  558.                     print output
  559.                 elif item == "bj-oms-core-new1":
  560.                     print "%d: %s is downoading..." % (index,item)
  561.                     output = subprocess.check_output(['fab','download_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
  562.                     print output
  563.                 elif item == "bj-oms-rest":
  564.                     print "%d: %s is downoading..." % (index,item)
  565.                     output = subprocess.check_output(['fab','download_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
  566.                     print output
  567.                 elif item == "bj-oms-jobs":
  568.                     print "%d: %s is downoading..." % (index,item)
  569.                     output = subprocess.check_output(['fab','download_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
  570.                     print output
  571.                 elif item == "bj-oms-domain":
  572.                     print "%d: %s is downoading..." % (index,item)
  573.                     output = subprocess.check_output(['fab','download_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
  574.                     print output
  575.                 elif item == "bj-oms-core":
  576.                     print "%d: %s is downoading..." % (index,item)
  577.                     output = subprocess.check_output(['fab','download_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
  578.                     print output
  579.                 elif item == "bj-web":
  580.                     pass
  581.                 else:
  582.                     print('%s下载失败,因为该文件没有在发版程序里面配置,请联系管理员') % item
  583.                     sys.exit()
  584.             break
  585.         elif tips == 'no':
  586.             break



  587.     #replace file to jar
  588.     while True:
  589.         temp = str(raw_input('7)替换jar包里面的配置文件吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  590.         tips = temp.strip().lower()
  591.         if tips == 'yes':
  592.             print "Now begin replace class file from jar ..."
  593.             dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
  594.             for index,item in enumerate(dirs,1):
  595.                 if item == 'bj-oms-api':
  596.                     print "%d: %s is replacing jar now..." % (index,item)
  597.                     output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT)
  598.                     print output
  599.                 elif item == "bj-oms-core-new1":
  600.                     while True:
  601.                         temp = str(raw_input('注意:因bj-oms-core-new1包里面有重复文件,所以需要手工更新jar包里面的内容,你更新了吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  602.                         tips = temp.strip().lower()
  603.                         if tips == 'yes':
  604.                             break
  605.                         elif tips == 'no':
  606.                             break
  607.                 elif item == 'bj-oms-domain':
  608.                     print "%d: %s is replacing jar now..." % (index,item)
  609.                     output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
  610.                     print output
  611.                 elif item == 'bj-oms-job':
  612.                     print "%d: %s is replacing jar now..." % (index,item)
  613.                     output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
  614.                     print output
  615.                 elif item == 'bj-oms-rest':
  616.                     print "%d: %s is replacing jar now..." % (index,item)
  617.                     output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
  618.                     print output
  619.                 elif item == 'bj-oms-core':
  620.                     print "%d: %s is replacing jar now..." % (index,item)
  621.                     output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
  622.                     print output
  623.             break
  624.         elif tips == 'no':
  625.             break




  626.     #backup jar
  627.     while True:
  628.         temp = str(raw_input('8)在正式发版前希望备份远程服务器的jar包吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  629.         tips = temp.strip().lower()
  630.         if tips == 'yes':
  631.             print "Now begin backup jar to /backup..."
  632.             dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
  633.             for index,item in enumerate(dirs,1):
  634.                 if item == 'bj-oms-api':
  635.                     print "%d: %s is backuping..." % (index,item)
  636.                     output = subprocess.check_output(['fab','backup_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
  637.                     print output
  638.                     print
  639.                 elif item == 'bj-oms-domain':
  640.                     print "%d: %s is backuping..." % (index,item)
  641.                     output = subprocess.check_output(['fab','backup_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
  642.                     print output
  643.                 elif item == 'bj-oms-core-new1':
  644.                     print "%d: %s is backuping..." % (index,item)
  645.                     output = subprocess.check_output(['fab','backup_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
  646.                     print output
  647.                 elif item == 'bj-oms-rest':
  648.                     print "%d: %s is backuping..." % (index,item)
  649.                     output = subprocess.check_output(['fab','backup_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
  650.                     print output
  651.                 elif item == 'bj-oms-jobs':
  652.                     print "%d: %s is backuping..." % (index,item)
  653.                     output = subprocess.check_output(['fab','backup_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
  654.                     print output
  655.                 elif item == 'bj-web':
  656.                     print "%d: %s is backuping..." % (index,item)
  657.                     output = subprocess.check_output(['fab','backup_bj_web'],shell=True,stderr = subprocess.STDOUT)
  658.                     print output
  659.                 elif item == 'bj-oms-core':
  660.                     print "%d: %s is backuping..." % (index,item)
  661.                     output = subprocess.check_output(['fab','backup_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
  662.                     print output
  663.             break
  664.         elif tips == 'no':
  665.             break

  666.     #发版,上传jar包到生产服务器
  667.     while True:
  668.         temp = str(raw_input('9)请问开始向生产服务器发版吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
  669.         tips = temp.strip().lower()
  670.         if tips == 'yes':
  671.             print "Now begin publish..."
  672.             dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
  673.             for index,item in enumerate(dirs,1):
  674.                 if item == 'bj-oms-api':
  675.                     print "%d: %s is publishing..." % (index,item)
  676.                     output = subprocess.check_output(['fab','put_bj_oms_api_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
  677.                     print output
  678.                     output = subprocess.check_output(['fab','put_bj_oms_api_jar_30'],shell=True,stderr = subprocess.STDOUT)
  679.                     print output
  680.                     print
  681.                 elif item == 'bj-oms-domain':
  682.                     print "%d: %s is publishing..." % (index,item)
  683.                     output = subprocess.check_output(['fab','put_bj_oms_domain_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT)
  684.                     print output
  685.                     output = subprocess.check_output(['fab','put_bj_oms_domain_jar_30'],shell=True,stderr = subprocess.STDOUT)
  686.                     print output
  687.                 elif item == 'bj-oms-core-new1':
  688.                     print "%d: %s is publishing..." % (index,item)
  689.                     output = subprocess.check_output(['fab','put_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
  690.                     print output
  691.                 elif item == 'bj-oms-rest':
  692.                     print "%d: %s is publishing..." % (index,item)
  693.                     output = subprocess.check_output(['fab','put_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
  694.                     print output
  695.                 elif item == 'bj-oms-jobs':
  696.                     print "%d: %s is publishing..." % (index,item)
  697.                     output = subprocess.check_output(['fab','put_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
  698.                     print output
  699.                 elif item == 'bj-web':
  700.                     print "%d: %s is publishing..." % (index,item)
  701.                     output = subprocess.check_output(['fab','put_bj_web'],shell=True,stderr = subprocess.STDOUT)
  702.                     print output
  703.                 elif item == 'bj-oms-core':
  704.                     print "%d: %s is publishing..." % (index,item)
  705.                     output = subprocess.check_output(['fab','put_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
  706.                     print output
  707.             break
  708.         elif tips == 'no':
  709.             break

  710.     #关闭服务
  711.     while True:
  712.         temp = str(raw_input('10)请问开始关闭服务吗,包含服务tomcat、rest、job、core?[yes/no]:'.decode('utf-8').encode('gb2312')))
  713.         tips = temp.strip().lower()
  714.         if tips == 'yes':
  715.             print "Now begin stop service..."
  716.             output = subprocess.check_output(['fab','stop_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
  717.             print output
  718.             output = subprocess.check_output(['fab','stop_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
  719.             print output
  720.             output = subprocess.check_output(['fab','stop_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
  721.             print output
  722.             output = subprocess.check_output(['fab','stop_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
  723.             print output
  724.             output = subprocess.check_output(['fab','stop_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
  725.             print output
  726.             output = subprocess.check_output(['fab','stop_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
  727.             print output
  728.         
  729.         elif tips == 'no':
  730.             break

  731.     #开启服务
  732.     while True:
  733.         temp = str(raw_input('11)请问开始启动服务吗,包含服务core、tomcat、rest、job?[yes/no]:'.decode('utf-8').encode('gb2312')))
  734.         tips = temp.strip().lower()
  735.         if tips == 'yes':
  736.             print "Now begin stop service..."
  737.             output = subprocess.check_output(['fab','start_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
  738.             print output
  739.             output = subprocess.check_output(['fab','start_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
  740.             print output
  741.             output = subprocess.check_output(['fab','start_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
  742.             print output
  743.             output = subprocess.check_output(['fab','start_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
  744.             print output
  745.             output = subprocess.check_output(['fab','start_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
  746.             print output
  747.             output = subprocess.check_output(['fab','start_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
  748.             print output
  749.         elif tips == 'no':
  750.             break

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28916011/viewspace-2153243/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28916011/viewspace-2153243/

你可能感兴趣的:(自己写的fabric脚本)