zoukankan      html  css  js  c++  java
  • 线上maven仓库是局域网,无法自动更新jar包,与测试环境jar包对比,再导入nexus种

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    import pymysql
    import os
    import sys
    import time

    path='/data/maven-repository'
    jarlist=[]
    #创建新的jarfilelist Name
    def fileName():
        now=int(time.time())
        timeArray = time.localtime(now)
        otherStyleTime = time.strftime('%Y-%m-%d',timeArray)
        newFileName=otherStyleTime
        if not os.path.exists(otherStyleTime):
            os.makedirs(otherStyleTime)
        return newFileName
    #读取数据库中最新的那个jarfilelist 
    def conn_mysql():
        db=pymysql.connect("10.1.130.46","jarlist","jarlist","jarlist",charset='utf8')
        cursor = db.cursor()
        cursor.execute("select jarlistName from jarInfo where id=(SELECT max(id) FROM jarInfo)")
        oldFileName = cursor.fetchone()
        #print("Database version : %s " % oldFileName)
        db.close()
        return oldFileName

    #生成新的jarfilelist
    def print_files(path):
        
        lsdir = os.listdir(path)
        
        dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))]
        if dirs:
            for i in dirs:
                print_files(os.path.join(path, i))
        files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))]
        for f in files:
           jarlistname=os.path.join(path, f)
           jarlist.append(jarlistname)
        return jarlist

    def write_files(newFileName,jarlist):
        fi=open(newFileName,'w')
        for f in jarlist:
            fi.write(f+' ')

           
    #新的jarfilelist 和 数据库中的jarfilelist 做对比,差异的生产tar包
    def create_tar(oldFileName,newFileName,newDir):
        oldf=open(oldFileName)
        newf=open(newFileName)
        oldlist=[]
        newlist=[]
        differentlist=[]
        for line in oldf.readlines():
            oldlist.append(line)
        for line in newf.readlines():
            newlist.append(line)
        for newline in newlist:
            if newline not in oldlist:
                differentlist.append(newline)
        #print(differentlist)
        for line in differentlist:
            line=line.strip(' ')
            resuLine=line[22:]
            dir=resuLine[0:resuLine.rfind('/')]
            jarpath=newDir+dir
            print('--->',jarpath,line)
            if not os.path.exists(jarpath):
                os.makedirs(newDir+dir)
                os.system('cp  %s %s'%(line,jarpath))
            else:
                os.system('cp  %s %s'%(line,jarpath))
            
    #将生成新的jarlist文件名字存到数据库中
    def store_mysql(newFileName):
        now=int(time.time())
        timeArray = time.localtime(now)
        otherStyleTime = time.strftime('%Y-%m-%d %H:%M:%S',timeArray)
        db=pymysql.connect("10.1.130.46","jarlist","jarlist","jarlist",charset='utf8')
        cursor = db.cursor()
        cursor.execute("INSERT INTO `jarlist`.`jarInfo`(`jarlistName`, `jarlistFilePath`, `createTime`) VALUES ('%s', '/data/liqian/', '%s')"%(newFileName,otherStyleTime))
        oldFileName = db.commit()
        #print("Database version : %s " % oldFileName)
        db.close()
        return oldFileName


    #print_files(sys.argv[1])

    if __name__ == "__main__":
        newFileName=fileName()+'.'+'txt'
        newDir=fileName()
        oldFileName=conn_mysql()[0]
        jarlist=print_files(path)
        write_files(newFileName,jarlist)
        create_tar(oldFileName,newFileName,newDir)
        store_mysql(newFileName)

    #ceshi bat jiaoben 
  • 相关阅读:
    POJ1239
    HDU 2829 四边形不等式优化
    返回数字二进制的最高位位数o(n)
    矩阵快速幂 模板
    HDU4718 The LCIS on the Tree(LCT)
    HDU4010 Query on The Trees(LCT)
    HDU3487 Play With Chains(Splay)
    CF444C DZY Loves Colors
    HDU4836 The Query on the Tree(树状数组&&LCA)
    HDU4831&&4832&&4834
  • 原文地址:https://www.cnblogs.com/i1991/p/13092623.html
Copyright © 2011-2022 走看看