import os

import paramiko

baseconfig = {
"ip": "121.4.38.187",
"port": 22,
"username": "",
"password": "",
"localdir": "E:\\javawork\\moodapi\\target\\classes",
"remotedir": "/www/wwwroot/zshapi",
"startsplit": "target",
"exclude": [],
"include": ["Info"],
"fielExt": ".class",
"succExec": "",
"skipDircheck": False
} # 遍历所有文件夹下的文件
def walkFiles(path, endpoint=None):
file_list = []
for root, dirs, files in os.walk(path):
for file in files:
file_path = os.path.join(root, file)
if endpoint:
if file_path.endswith(endpoint):
file_list.append(file_path)
else:
file_list.append(file_path)
return file_list def getRemotedir(f):
if baseconfig["startsplit"] != "":
p = f.split(baseconfig["startsplit"])[1].replace("\\", "/")
return p def checkExclude(file):
filename = os.path.split(file)[1]
filename = filename.lower()
for regstr in baseconfig["exclude"]:
if filename.__contains__(regstr.lower()):
return True
return False def checkInclude(file):
filename = os.path.split(file)[1]
filename = filename.lower()
for regstr in baseconfig["include"]:
if filename.__contains__(regstr.lower()):
return True
return False def upload(files):
if len(files) == 0:
return
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=baseconfig["ip"], port=baseconfig["port"], username=baseconfig["username"],
password=baseconfig["password"])
ssh.get_transport()
sftp = paramiko.SFTPClient.from_transport(ssh.get_transport())
for f in files:
if checkExclude(f):
print("跳过:%s" % f)
continue
if len(baseconfig["include"]) > 0:
if checkInclude(f) == False:
continue
p = baseconfig["remotedir"] + getRemotedir(f)
if baseconfig["skipDircheck"] == False:
remotedir = os.path.split(p)[0]
stdin, stdout, stderr = ssh.exec_command("ls " + remotedir)
if stdout.readline() == '':
stdin, stdout, stderr = ssh.exec_command("mkdir -p " + remotedir)
stdout.readline()
print("上传:%s至%s" % (f, p))
sftp.put(f, p)
if baseconfig["succExec"] != "":
stdin, stdout, stderr = ssh.exec_command(baseconfig["succExec"])
stdout.readline()
ssh.close() if __name__ == '__main__':
files = walkFiles(baseconfig["localdir"], endpoint=baseconfig["fielExt"])
upload(files)

python自动发布的更多相关文章

  1. Python自动发布Image service的实现

    使用Python自动发布地图服务已经在上一篇博客中讲到,使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务,下面是利用Python自动发布Image service的实现. -- ...

  2. 测试开发Python培训:自动发布新浪微博-技术篇

    测试开发Python培训:自动发布新浪微博-技术篇   在前面我们教大家如何登陆,大家需要先看自动登陆新浪微博(http://www.cnblogs.com/laoli0201/articles/48 ...

  3. gitlab+jenkins自动发布Python包到私有仓储

    背景 有个私有仓储,地址为https://your.repo.com/pypi/ 代码存储在gitlab, 地址为https://gitlab.company.com/software.git CI为 ...

  4. Python + Selenium 自动发布文章(一):开源中国

    https://blog.csdn.net/qq_28804275/article/details/80891949 https://blog.csdn.net/qq_28804275/article ...

  5. jenkins结合supervisor进行python程序发布后的自动重启

    jenkins结合supervisor进行python程序发布后的自动重启 项目背景: 通过jenkins发布kvaccount.chinasoft.com站点的python服务端程序,业务部门同事需 ...

  6. 自动发布工具版本从python2升级成python3后遇到的种种问题(涉及paramiko,Crypto,zipfile等等)

    从在公司实习到正式入职,一直还在被同事使用的是我写的一个自动发布工具.该工具的主要功能是:开发人员给出需要更新的代码包(zip格式),测试人员将该代码包部署到测服,这些代码包和JIRA数据库里的项目信 ...

  7. 解决GP服务产生的结果无法自动发布为地图服务的问题

    在ArcGIS for Javascript API或REST API调用GP服务时,常常会遇到这样一种情况:GP服务运行以后,执行成功,也能够生成结果,然而结果并没有直接产生动态的地图服务供API调 ...

  8. fabric自动发布tomcat线上项目

    现在公司的每个tomcat项目都有测试和生产两个环境,对于经常需要上线的tomcat项目,如用手工更新就非常耗费时间和人力.现用fabric开发了一个自动发布tomcat项目的脚本,该脚本已经在公司使 ...

  9. GeoServer自动发布地图服务

    1 NetCDF气象文件自动发布案例 GeoServer是一个地理服务器,提供了管理页面进行服务发布,样式,切片,图层预览等一系列操作,但是手动进行页面配置有时并不满足业务需求,所以GeoServer ...

  10. Django实现自动发布(1数据模型)

    公司成立之初,业务量较小,一个程序包揽了所有的业务逻辑,此时服务器数量少,上线简单,基本开发-测试-上线都是由开发人员完成. 随着业务量逐渐上升,功能增多,代码量增大,而单一功能上线需要重新编译整个程 ...

随机推荐

  1. 用于数据科学的顶级 C/C++ 机器学习库整理

    用于数据科学的顶级 C/C++ 机器学习库整理 介绍和动机--为什么选择 C++ C++ 非常适合 动态负载平衡. 自适应缓存以及开发大型大数据框架 和库.Google 的MapReduce.Mong ...

  2. 2022春每日一题:Day 17

    今天打CF去了,但是很菜,只做了三题.赛后一分钟做出了第四题,wa了,改了一下下,过了 第一题就是对应的小写字母在大写字母前出现. 第二题直接dfs. 第三题dp,f[i][j]表示以第i个数开始加了 ...

  3. 顺序表代码总结——SqList

    在C++编译器下可直接运行 #include <stdio.h> #include <stdlib.h> #include <malloc.h> //顺序表存储结构 ...

  4. kubernetes_CoreDNS全解析

    一.前言 kubernetes CoreDNS 是 kube-system 命令空间里面的一个Pod,用于域名解析. kubernetes自带三个命名空间(用kubeadm安装的Kubernetes集 ...

  5. 【RocketMQ】顺序消息实现原理

    全局有序 在RocketMQ中,如果使消息全局有序,可以为Topic设置一个消息队列,使用一个生产者单线程发送数据,消费者端也使用单线程进行消费,从而保证消息的全局有序,但是这种方式效率低,一般不使用 ...

  6. Vue使用axios请求接口返回成功200但是进入到catch中

    发生这个问题时查阅了许多资料,没有一个是对得上的.最后发现原来是在请求拦截器中的错误 错误代码如下 // 添加响应拦截器 axios.interceptors.response.use(functio ...

  7. os sys json模块

    Day19 os sys json 今日内容概要 os模块 sys模块 json模块 json模块实践 今日内容详细 一.os模块 os模块主要与代码运行所在的操作系统打交道 import os 1. ...

  8. vba 数组判断与转换

    Private Function CountArr(arr)'*****************************'计算数组是几维数组'***************************** ...

  9. 多种方法实现单例模式 pickle模块

    目录 单例模式 类方法@classmethod实现 元类实现 模块实现 装饰器实现 双下call.反射实现 pickle序列化模块 单例模式 比如系统调用打印机,不管你要打印几次,都是调用同一个打印机 ...

  10. React报错之Element type is invalid

    总览 产生"Element type is invalid -- expected a string (for built-in components) or a class/functio ...