From 1050582e911ce17272c5d399bdd3f4f32964e5d0 Mon Sep 17 00:00:00 2001 From: Alvis Date: Fri, 14 Aug 2020 15:31:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=85=A5=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload-apt.py | 41 +++++++++++++++++++++ upload-gradle.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ upload-npm.py | 48 +++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 upload-apt.py create mode 100644 upload-gradle.py create mode 100644 upload-npm.py diff --git a/upload-apt.py b/upload-apt.py new file mode 100644 index 0000000..1526550 --- /dev/null +++ b/upload-apt.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +#================== +# Author: Alvis Zhao +# Date: 2020-08-14 15:27:05 +# LastEditTime: 2020-08-14 15:27:57 +# Description: 批量上传deb包到内网nexus源 +#================== + +import os +import sys + +def showUsage(): + print("Usage:") + print(" python upload-apt.py dir-to-upload") + +USERNAME="uploader" +PASSWORD="uploader" +URL="http://nexus3.developer.com/service/rest/v1/components?repository=bionic" + +def main(): + if len(sys.argv) < 2: + print("用法错误!") + showUsage() + return + + uploadDir=sys.argv[1] + if not os.path.isdir(uploadDir): + print("用法错误!") + showUsage() + return + + fileList=os.listdir(uploadDir) + for file in fileList: + filepath = uploadDir + os.sep + file + print(filepath) + cmd = "curl POST -u " + USERNAME + ":" + PASSWORD + " " + URL + ' -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "apt.asset=@' + filepath + '"' + os.popen(cmd) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/upload-gradle.py b/upload-gradle.py new file mode 100644 index 0000000..66c8ceb --- /dev/null +++ b/upload-gradle.py @@ -0,0 +1,92 @@ +#!/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() \ No newline at end of file diff --git a/upload-npm.py b/upload-npm.py new file mode 100644 index 0000000..da26aaf --- /dev/null +++ b/upload-npm.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +#================== +# Author: Alvis Zhao +# Date: 2020-08-14 15:27:05 +# LastEditTime: 2020-08-14 15:30:46 +# Description: 批量上传npm包到内网nexus源 +#================== + +import os +import sys + +def showUsage(): + print("Usage:") + print(" npm adduser --register http://nexus3.developer.com/repository/npm-public") + print(" python upload-npm.py dir-to-upload") + +USERNAME="uploader" +PASSWORD="uploader" +URL="http://nexus3.developer.com/repository/npm-public" + +def loginNpmRepo(): + pipeline = os.popen('npm config set registry ' + URL) + cmd = 'npm-cli-login -u "' + USERNAME + '" -p "' + PASSWORD + '" -e test@example.com -r ' + URL + pipeline = os.popen(cmd) + print(pipeline) + +def main(): + if len(sys.argv) < 2: + print("用法错误!") + showUsage() + return + + uploadDir=sys.argv[1] + if not os.path.isdir(uploadDir): + print("用法错误!") + showUsage() + return + + fileList=os.listdir(uploadDir) + for file in fileList: + filepath = os.getcwd() + os.sep + uploadDir + os.sep + file + cmd = "npm publish " + filepath + os.system(cmd) + +if __name__ == '__main__': + main() \ No newline at end of file