处理的比较麻烦,一开始是直接用脚本处理的,发现只能处理一级目录,然后不得已,用python来处理,这个没有单独写,用的是flask_appbuilder 原来的项目,直接改了用了,来吧,上代码
@expose('/postNexus', methods=['GET'])
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 = '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'):
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 "3162289690@qq.com"
:: 参数 /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 上传包 )
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
for file in "$MULU"/*;
do
if [ -d "$file" ];
then
if [ -f "$file/$HASFILE" ];then
echo "$file/$HASFILE"
cd "$file"
npm publish --registry "$REPO_URL"
fi;
fi;
done
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
for file in "$MULU"/*;
do
if [ -d "$file" ];
then
if [ -f "$file/$HASFILE" ];then
echo "$file/$HASFILE"
cd "$file"
npm publish --registry "$REPO_URL"
fi;
fi;
done
如果还是报错,缺失包,那没有办法,只能挨个比较找包下载了,没有办法,离线安装缺失比较麻烦
|