处理的比较麻烦,一开始是直接用脚本处理的,发现只能处理一级目录,然后不得已,用python来处理,这个没有单独写,用的是flask_appbuilder 原来的项目,直接改了用了,来吧,上代码
@expose('/postNexus', methods=['GET'])
# @protect()
# @safe
def postNexus(self):
label = request.args.get("label", default="M:\\postgres\\yapi\\vendors\\node_modules")
ip = current_app.config.get('NEXUS_IP')
return1 = os.system('ping -n 2 -w 1 %s' % ip)
if return1==0:
# label = 'E:\\vue\\yapi\\vendors\\node_modules'
label = 'C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\cnpm\\node_modules'
r,r1 = file_name(label)
res = {
}
res['cmd'] = r
res['_resolved'] = r1
return jsonify({
'code': 0, "msg": 'success', 'data': res})
def file_name(file_dir):
ip = current_app.config.get('NEXUS_IP')
for root, dirs, files in os.walk(file_dir):
print(root) #当前目录路径
print(dirs) #当前路径下所有子目录
print(files) #当前路径下所有非目录子文件
for i in dirs:
file_name(os.path.join(root,i))
r = []
r1 =[]
if 'package.json' in files:
with open(os.path.join(root,'package.json'), 'r', encoding='UTF-8') as load_f:
load_dict = json.load(load_f)
print(load_dict)
if '_resolved' in load_dict.keys():
r1.append(load_dict['_resolved'])
download_file(load_dict['_resolved'], store_path=None)
else:
# 直接提交
pass
cmd = 'cd {} && npm --registry=http://{}:8081/repository/yapi_npm/ publish'.format(ip, root)
r.append(cmd)
run_cmd(cmd)
res = {
}
res['cmd'] = r
res['_resolved'] = r1
return res
from urllib.request import urlretrieve
def download_file(url, store_path=None):
if store_path is None:
store_path = os.path.normpath(current_app.config.get('STORE_PATH'))
if not Path(store_path).exists():
os.makedirs( store_path, int('0755'))
filename = url.split('/')[-1]
filepath = os.path.join(store_path, filename)
if not Path(filepath).exists():
urlretrieve(url, filepath)
def run_cmd(cmd = 'ls'):
# npm --registry=http://10.33.6.49:8081/repository/yapi_npm/ publish dify-1.0.6.tgz
ip = current_app.config.get('NEXUS_IP')
if ip in cmd:
return1 = os.system('ping -n 2 -w 1 %s' % ip)
if return1 == 0:
os.system(cmd)
else:
os.system(cmd)
postNexusTgz.bat (通过bat 直接上传文件夹下面的包)
echo off & color 0A
::指定起始文件夹
set DIR="%cd%"
cd DIR
cd ..
set DIR="%cd%"
echo DIR=%DIR%
:: npm login --registry=http://10.33.6.49:8081/repository/yapi_npm/
:: echo "admin"
:: echo "admin123"
:: echo "[email protected]"
:: 参数 /R 表示需要遍历子文件夹,去掉表示不遍历子文件夹
:: %%f 是一个变量,类似于迭代器,但是这个变量只能由一个字母组成,前面带上%%
:: 括号中是通配符,可以指定后缀名,*.*表示所有文件
for /R %DIR% %%f in (*.tgz) do (
echo %%f
npm --registry=http://10.33.6.49:8081/repository/yapi_npm/ publish %%f
)
pause
batch_bao.sh(linux 上传包 )
#!/bin/bash
# ./batch_bao.sh -u 用户名-p 密码 -r 本地仓库地址
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
# https://www.jianshu.com/p/c04f1cc65a3d
# nrm use yapi_npm
# npm publish --registry http://10.33.6.49:8081/repository/yapi_npm/
# ./batch_bao.sh -u admin -p admin123 -r http://10.33.6.49:8081/repository/yapi_npm/ -m /home/lizhihua/yapi/vendors/node_modules -f package.json
REPO_URL='http://10.33.6.49:8081/repository/yapi_npm/'
USERNAME='admin'
PASSWORD='admin123'
MULU='.'
HASFILE='package.json'
echo
while getopts ":r:u:p:m:f:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
m) MULU="$OPTARG"
;;
f) HASFILE="$OPTARG"
;;
esac
done
# 先注释了
# find . -type f -not -path './batch_bao\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
# echo curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{}
# 判断目录下是否存在 package.json
for file in "$MULU"/*;
do
if [ -d "$file" ];
then
# echo $file
#这里写上传代码 $file是目录名
if [ -f "$file/$HASFILE" ];then
echo "$file/$HASFILE"
cd "$file"
npm publish --registry "$REPO_URL"
fi;
fi;
done
#!/bin/bash
# ./batch_bao.sh -u 用户名-p 密码 -r 本地仓库地址
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
# https://www.jianshu.com/p/c04f1cc65a3d
# nrm use yapi_npm
# npm publish --registry http://10.33.6.49:8081/repository/yapi_npm/
# ./batch_bao.sh -u admin -p admin123 -r http://10.33.6.49:8081/repository/yapi_npm/ -m /home/lizhihua/yapi/vendors/node_modules -f package.json
REPO_URL='http://10.33.6.49:8081/repository/yapi_npm/'
USERNAME='admin'
PASSWORD='admin123'
MULU='.'
HASFILE='package.json'
echo
while getopts ":r:u:p:m:f:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
m) MULU="$OPTARG"
;;
f) HASFILE="$OPTARG"
;;
esac
done
# 先注释了
# find . -type f -not -path './batch_bao\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
# echo curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{}
# 判断目录下是否存在 package.json
for file in "$MULU"/*;
do
if [ -d "$file" ];
then
# echo $file
#这里写上传代码 $file是目录名
if [ -f "$file/$HASFILE" ];then
echo "$file/$HASFILE"
cd "$file"
npm publish --registry "$REPO_URL"
fi;
fi;
done
如果还是报错,缺失包,那没有办法,只能挨个比较找包下载了,没有办法,离线安装缺失比较麻烦