常用脚本整理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

92 lines
3.2 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#==================
# Author: Alvis Zhao
# Date: 2020-08-14 15:28:10
# LastEditTime: 2020-08-14 15:29:25
# Description: 批量上传gradle缓存到内网nexus3仓库
#==================
import os
import sys
def showUsage():
print("Usage:")
print(" python upload-gradle-cache.py files-2.1")
print(" gradle cache dir is at USER_HOME\.gradle\caches\modules-2\files-2.1")
USERNAME="uploader"
PASSWORD="uploader"
URL="http://nexus3.developer.com/service/rest/v1/components?repository=maven-public"
#
# gradle缓存目录结构
# files-2.1
# |_groupId
# |_artifactId
# |_version
# |_xxx
# | |_artifactId-version.pom // pom配置,一定存在
# |_xxx
# | |_artifactId-version.aar/jar
# |_xxx
# |_artifactId-version-classifier.jar
#
def main():
if len(sys.argv) < 2:
print("用法错误!")
showUsage()
return
uploadDir=sys.argv[1]
if not os.path.isdir(uploadDir):
print("用法错误!")
showUsage()
return
groupList=os.listdir(uploadDir)
for one in groupList:
groupId = one
groupPath = uploadDir + os.sep + groupId
artifactList=os.listdir(groupPath)
for two in artifactList:
artifactId = two
artifactPath = groupPath + os.sep + artifactId
versionList=os.listdir(artifactPath)
for three in versionList:
version = three
versionPath = artifactPath + os.sep + version
hasList = os.listdir(versionPath)
num = 1
cmd = "curl -v -u " + USERNAME + ":" + PASSWORD
cmd = cmd + " -X POST "
cmd = cmd + ' -H "accept:application/json"'
cmd = cmd + ' -H "Content-Type:multipart/form-data"'
cmd = cmd + ' -F maven2.generate-pom=false'
cmd = cmd + ' -F maven2.groupId=' + groupId
cmd = cmd + ' -F maven2.artifactId=' + artifactId
cmd = cmd + ' -F maven2.version=' + version
for hash in hasList:
hashPath = versionPath + os.sep + hash
fileList = os.listdir(hashPath)
file = fileList[0]
cmd = cmd + " -F maven2.asset" + str(num) + "=@" + str(hashPath) + os.sep + file
arr = os.path.splitext(file)
# extension = aar/jar/pom
extension = arr[1].split('.')[1]
cmd = cmd + " -F maven2.asset" + str(num) + ".extension=" + extension
# basename = artifactPath-version-classifier
basename = arr[0]
tmpClassifier = basename.split(artifactId + "-")[1].split(version)[1]
# 可能没有classifier
if len(tmpClassifier) > 0:
classifier = tmpClassifier.split('-')[1]
cmd = cmd + " -F maven2.asset" + str(num) + ".classifier=" + classifier
cmd = cmd + " " + URL
os.system(cmd)
if __name__ == '__main__':
main()