coding=utf-8
import os
import subprocess
from util import Logger,YamlConfig
logging = Logger()
logger = logging.get_logger()
yaml = YamlConfig()
REPO_URL_SNAPSHOTS = yaml.repos[“snapshot”]
REPO_URL_RELEASES = yaml.repos[“release”]
def deploy_jar(file_path,file_name):
if ‘SNAPSHOT.jar’ in file_name:
url = ‘http://nexus-library.lotuscars.com.cn:8081/repository/’+REPO_URL_SNAPSHOTS
repositoryid = REPO_URL_SNAPSHOTS
else:
url = ‘http://nexus-library.lotuscars.com.cn:8081/repository/’+REPO_URL_RELEASES
repositoryid = REPO_URL_RELEASES
group_list = file_path.split(‘/’)
groupid = ‘.’.join(group_list[1:-3])
artifactid = group_list[-3]
version = group_list[-2]
#file = os.path.join(root,file_name)
mvn_command = ["mvn", "deploy:deploy-file", "-DgroupId={}".format(groupid), "-DartifactId={}".format(artifactid),
"-Dversion={}".format(version), "-Dpackaging=jar", "-Dfile={}".format(file_path), "-Durl={}".format(url),
"-DrepositoryId={}".format(repositoryid)]
print(mvn_command)
try:
subprocess.check_call(mvn_command)
logger.info('{} upload success'.format(file_name))
except subprocess.CalledProcessError as e:
logger.info('Failed to upload {}'.format(file_name))
def deploy_pom(file_path,file_name):
if ‘SNAPSHOT.pom’ in file_name:
url = ‘http://nexus-library.lotuscars.com.cn:8081/repository/’+REPO_URL_SNAPSHOTS
repositoryid = REPO_URL_SNAPSHOTS
else:
url = ‘http://nexus-library.lotuscars.com.cn:8081/repository/’+REPO_URL_RELEASES
repositoryid = REPO_URL_RELEASES
group_list = file_path.split(‘/’)
groupid = ‘.’.join(group_list[1:-3])
artifactid = group_list[-3]
version = group_list[-2]
#file = os.path.join(root,file_name)
mvn_command = ["mvn", "deploy:deploy-file", "-DgroupId={}".format(groupid), "-DartifactId={}".format(artifactid),
"-Dversion={}".format(version), "-Dpackaging=pom", "-Dfile={}".format(file_path), "-Durl={}".format(url),
"-DrepositoryId={}".format(repositoryid)]
print(mvn_command)
try:
subprocess.check_call(mvn_command)
logger.info('{} upload success'.format(file_name))
except subprocess.CalledProcessError as e:
logger.info('Failed to upload {}'.format(file_name))
def main():
for root, dirs, filenames in os.walk(‘.’):
for file_name in filenames:
file_path = os.path.join(root,file_name)
if file_name.endswith(‘.jar’):
deploy_jar(file_path,file_name)
elif file_name.endswith(‘.pom’):
deploy_pom(file_path,file_name)
else:
continue
if name == ‘main’:
main()
util.py
import logging
import yaml
import time
import sys
class Logger:
def init(self):
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.INFO)
formatter = logging.Formatter(‘%(asctime)s-%(name)s-%(levelname)s-%(message)s’)
filename_date = time.strftime("%Y-%m-%d-%H-%M",time.localtime())
logfile_name = filename_date+'.log'
fh = logging.FileHandler('./{}'.format(logfile_name),'a','utf-8')
fh.setFormatter(formatter)
fh.setLevel(logging.INFO)
self.logger.addHandler(fh)
sh = logging.StreamHandler(sys.stdout)
sh.setFormatter(formatter)
sh.setLevel(logging.INFO)
self.logger.addHandler(sh)
def get_logger(self):
return self.logger
class YamlConfig:
def init(self):
self.config = yaml.load(open(“./mvn_config.yaml”,“r”,encoding=“utf-8”),Loader=yaml.FullLoader)
self.access = self.config[‘access’]
self.repos = self.config[“repos”]