windows上几个快捷脚本


目录
  • 1、phantomjs_echarts图表绘制服务启动脚本
  • 2、基于若依微服务框架魔改服务的快速部署cmd脚本

1、phantomjs_echarts图表绘制服务启动脚本

@echo off

title 曲线绘制服务

::应用路径
set phantomjs_path=D:\xxx-myworkspace\env\phantomjs_echarts\phantomjs-2.1.1-windows\bin\phantomjs.exe
set echarts_js_path=D:\xxx-myworkspace\env\phantomjs_echarts\echarts-convert\echarts-convert\echarts-convert.js

::start cmd /k "%phantomjs_path% %echarts_js_path% -s -p 6666" 
%phantomjs_path% %echarts_js_path% -s -p 6666

2、基于若依微服务框架魔改服务的快速部署cmd脚本

@echo off
title 智慧高速公路服务部署工具

::设置工程根路径
set base_project_path=D:\jtzl-myworkspace\code\zhgsgl
::设置脚本路径
set py_script_path=.\script\zhgsgl_deploy.py

echo --------------------------------------------
echo 智慧高速公路服务部署功能菜单
echo [1]  编译打包服务
echo [2]  清空docker镜像构建目录
echo [3]  移动服务到部署目录
echo [4]  退出,再见!
echo --------------------------------------------

:menu
choice /c 1234 /m 请选择功能码:
echo 您的功能选项为:%errorlevel%

if %errorlevel% == 1 goto 1
if %errorlevel% == 2 goto 2
if %errorlevel% == 3 goto 3
if %errorlevel% == 4 goto 4

:1
echo 开始maven清除、编译、打包、安装
:: 编译的逻辑
start cmd /c  " title maven构建中 && cd /d %base_project_path% && mvn clean compile package install -DskipTests=true&& echo 执行成功.... && pause"
goto next_action

:2
echo 开始清空docker镜像构建目录
start cmd /c  " title 正在清空 && py %py_script_path% %base_project_path% del && echo 执行成功.... && pause"
goto next_action

:3
echo 正在移动jar包
start cmd /c  " title 正在移动 && py %py_script_path% %base_project_path% && echo 执行成功.... && pause"
echo 移动成功....
goto next_action

:4
exit

:next_action
choice /N /C y /T 1 /D y>nul
goto menu
#!/usr/bin/python
# -*- coding:utf-8 -*-

import sys
import os
import re
import shutil

def copy_jar_to_docker_context(project_base_path, del_docker_jar_path_flag):
    service_name_list = [
        "zhgsgl-auth.jar",
        "zhgsgl-gateway.jar",
        "zhgsgl-visual-monitor.jar",
        "zhgsgl-modules-device.jar",
        "zhgsgl-modules-file.jar",
        "zhgsgl-modules-gen.jar",
        "zhgsgl-modules-job.jar",
        "zhgsgl-modules-system.jar",
        "zhgsgl-modules-warning.jar"
    ]
    handle_path_list = list()
    for item in service_name_list:
        tmp = item.replace(".jar", "")
        i = re.split("-", tmp)
        deploy_path = project_base_path + os.path.sep + "docker" + os.path.sep + "\\".join(i) + os.path.sep + "jar"
        handle_path_list.append((item, deploy_path))
    tmp = os.walk(project_base_path)

    for a, b, c in tmp:
        if c.__len__() > 1:
            for i in c:
                if i.endswith(".jar"):
                    if service_name_list.__contains__(i):
                        service_target_path = a + os.path.sep + i
                        for jar_name, docker_path in handle_path_list:
                            if jar_name.__eq__(i):
                                service_docker_jar_path = docker_path + os.path.sep + jar_name
                                if del_docker_jar_path_flag is not None and "del".__eq__(del_docker_jar_path_flag):
                                    if os.path.exists(service_docker_jar_path):
                                        os.remove(service_docker_jar_path)
                                        print("删除:%s" % service_docker_jar_path)
                                if "del".__eq__(del_docker_jar_path_flag) != True and os.path.exists(
                                        service_target_path) and os.path.exists(docker_path + os.path.sep):
                                    if os.path.exists(docker_path + os.path.sep + jar_name):
                                        os.remove(docker_path + os.path.sep + jar_name)
                                    print("文件[%s]\n拷贝至目标位置[%s]\n" % (service_target_path, service_docker_jar_path))
                                    shutil.copy(service_target_path, service_docker_jar_path)


def handle(project_path, del_docker_jar_path_flag):
    os.chdir(project_path)
    project_base_path = os.getcwd()
    print("目标工程根路径:%s\n" % project_base_path)
    copy_jar_to_docker_context(project_base_path, del_docker_jar_path_flag)


if __name__ == '__main__':
    BASE_DIR = "D:\jtzl-myworkspace\code\zhgsgl"
    argv = str()
    is_del = str()
    print(sys.argv.__len__())
    if sys.argv.__len__() == 1:
        argv = BASE_DIR
        is_del = None
    elif sys.argv.__len__() == 2:
        if os.path.exists(sys.argv[1]) != True:
            argv = BASE_DIR
            is_del = sys.argv[1]
        else:
            argv = sys.argv[1]
            is_del = None
    elif sys.argv.__len__() >= 3:
        argv = sys.argv[1]
        is_del = sys.argv[2]

    flag = os.path.exists(argv)
    if flag == False:
        print("目标工程不存在:%s" % argv)
        print("即将退出....")
        sys.exit(1)
    handle(argv, is_del)