一、需求

app打包需要打入一些H5进去,以便更快的加载页面。这些H5文件是散落在各个文件夹中的【如下列所示】,偶尔各个文件夹还需新增文件,每次新增一个文件,需要改动jenkins上job脚本,比较麻烦,所以换一种思路来解决这个问题。

tmp/
├── c
│   ├── cmd.js.d
│   ├── TZT2..js.d
│   ├── TZT.js.d
│   └── TZT\\\\\\\\\\\\.json.d
├── c_modules
│   ├── config.js.d
│   ├── css
│   │   ├── base-min2..css.d
│   │   ├── base-min.css.d
│   │   ├── base-min-white.css.d
│   │   ├── images
│   │   │   └── arrow.png.d
│   │   ├── jskj-elementUI.css.d
│   │   ├── scroller.css.d
│   │   ├── skin
│   │   │   └── bg.css.d
│   │   └── skin01
│   │   └── bg.css.d
│   ├── debuggap.js.d
│   ├── fastclick.js.d
│   ├── heatmap.min.js.d
│   ├── jquery-1.7..min.js.d
│   ├── jquery.min.js.d
│   ├── loadData.js.d
│   ├── loadSel.js.d
│   ├── onscroll.js.d
│   ├── pop
│   │   ├── images
│   │   │   └── icon_closeBtn.png.d
│   │   ├── pop.css.d
│   │   ├── pop.js.d
│   │   ├── pop-zdycx.css.d
│   │   └── pop-zdycx.js.d
│   ├── proint.js.d
│   ├── sea.js.d
│   └── sensorsdata.min.js.d
├── config
│   └── index.js.d
├── dist
│   ├── src
│   │   ├── common
│   │   │   ├── iconClick.js.d
│   │   │   └── md5.js.d
│   │   ├── home
│   │   │   ├── app.js.d
│   │   │   ├── images
│   │   │   │   ├── close.png.d
│   │   │   │   ├── default.png.d
│   │   │   │   ├── down.png.d
│   │   │   │   ├── dxsq.png.d
│   │   │   │   ├── fxng.png.d
│   │   │   │   ├── gpcc.png.d
│   │   │   │   ├── gpkh.png.d
│   │   │   │   ├── guide1.png.d
│   │   │   │   ├── guide2.png.d
│   │   │   │   ├── guide3.png.d
│   │   │   │   ├── guide4.png.d
│   │   │   │   ├── header_bg.png.d
│   │   │   │   ├── jftoast.png.d
│   │   │   │   ├── mid_xgsgts.png.d
│   │   │   │   ├── myzc.png.d
│   │   │   │   ├── new.png.d
│   │   │   │   ├── news.png.d
│   │   │   │   ├── nodata.png.d
│   │   │   │   ├── oper_activity_pop.png.d
│   │   │   │   ├── register_tel.png.d
│   │   │   │   ├── right.png.d
│   │   │   │   ├── rmzt_one.png.d
│   │   │   │   ├── rmzt_three.png.d
│   │   │   │   ├── rmzt_two.png.d
│   │   │   │   ├── selected.png.d
│   │   │   │   ├── select.png.d
│   │   │   │   ├── shadow.png.d
│   │   │   │   ├── tougu_bg.png.d
│   │   │   │   ├── up.png.d
│   │   │   │   ├── user.png.d
│   │   │   │   ├── voice.gif.d
│   │   │   │   ├── yszb.png.d
│   │   │   │   └── ywbl.png.d
│   │   │   ├── index.html.d
│   │   │   ├── js
│   │   │   │   ├── home_index.js.d
│   │   │   │   └── Sortable.js.d
│   │   │   ├── routes
│   │   │   │   └── routes.js.d
│   │   │   ├── skin01
│   │   │   │   └── home_index.css.d
│   │   │   └── template
│   │   │   └── home_index.html.d
│   │   ├── mine
│   │   │   ├── api
│   │   │   │   └── function.js.d
│   │   │   ├── app.js.d
│   │   │   ├── css
│   │   │   │   └── index.css.d
│   │   │   ├── img
│   │   │   │   ├── arrow_account.png.d
│   │   │   │   ├── cao.png.d
│   │   │   │   ├── common_used.png.d
│   │   │   │   ├── crown.png.d
│   │   │   │   ├── detail.png.d
│   │   │   │   ├── dui.png.d
│   │   │   │   ├── flow.png.d
│   │   │   │   ├── guide1.png.d
│   │   │   │   ├── guide2.png.d
│   │   │   │   ├── guide3.png.d
│   │   │   │   ├── guide4.png.d
│   │   │   │   ├── guide5.png.d
│   │   │   │   ├── hide_assets.png.d
│   │   │   │   ├── jcsc.png.d
│   │   │   │   ├── ka.png.d
│   │   │   │   ├── not_login.png.d
│   │   │   │   ├── show_assets.png.d
│   │   │   │   ├── sign.png.d
│   │   │   │   ├── transfer_accounts.png.d
│   │   │   │   ├── tui.png.d
│   │   │   │   ├── vip_arrow.png.d
│   │   │   │   ├── vip.png.d
│   │   │   │   ├── wei.png.d
│   │   │   │   └── wen.png.d
│   │   │   ├── index.html.d
│   │   │   ├── js
│   │   │   │   └── index.js.d
│   │   │   ├── routes
│   │   │   │   └── routes.js.d
│   │   │   ├── skin
│   │   │   │   └── index.css.d
│   │   │   ├── skin01
│   │   │   │   └── index.css.d
│   │   │   └── template
│   │   │   └── index.html.d
│   │   └── public-images
│   │   ├── cccb.png.d
│   │   ├── dkxh.png.d
│   │   ├── dpjl.png.d
│   │   ├── dtzq.png.d
│   │   ├── dxsq.png.d
│   │   ├── dzjy.png.d
│   │   ├── fhsp.png.d
│   │   ├── fxng.png.d
│   │   ├── fxspg.png.d
│   │   ├── gdrs.png.d
│   │   ├── ggcg.png.d
│   │   ├── ggtjy.png.d
│   │   ├── ggt.png.d
│   │   ├── gpcc.png.d
│   │   ├── gpkh.png.d
│   │   ├── gpqq.png.d
│   │   ├── gsrl.png.d
│   │   ├── gszx.png.d
│   │   ├── gznhg.png.d
│   │   ├── jcsc.png.d
│   │   ├── jfsc.png.d
│   │   ├── jgdy.png.d
│   │   ├── jjzt.png.d
│   │   ├── lcsc_new.png.d
│   │   ├── lhb.png.d
│   │   ├── mfjg.png.d
│   │   ├── myzc.png.d
│   │   ├── nrzt.png.d
│   │   ├── qbfw.png.d
│   │   ├── rmzt.png.d
│   │   ├── rzrq.png.d
│   │   ├── sczd.png.d
│   │   ├── sjjj.png.d
│   │   ├── ssnc.png.d
│   │   ├── tfp.png.d
│   │   ├── tgsq.png.d
│   │   ├── xsjj.png.d
│   │   ├── xskx.png.d
│   │   ├── xyjy.png.d
│   │   ├── yjyg.png.d
│   │   ├── ywbl_old.png.d
│   │   ├── ywbl.png.d
│   │   ├── yzzz.png.d
│   │   ├── zlcc.png.d
│   │   ├── znxg.png.d
│   │   ├── znyj.png.d
│   │   └── znzg.png.d
│   └── static
│   ├── css
│   │   ├── base.css.d
│   │   ├── base-min.css.d
│   │   ├── base-min-sea-vue.css.d
│   │   ├── mobiscroll.custom-2.6..min.css.d
│   │   └── swiper.css.d
│   ├── jquery
│   │   ├── jquery-1.11..min.js.d
│   │   ├── jquery-1.8..min.js.d
│   │   └── jquery-range.js.d
│   ├── lib
│   │   ├── action.js.d
│   │   ├── flexible.js.d
│   │   ├── mobiscroll.custom-2.6..min.js.d
│   │   └── swiper.js.d
│   ├── sea
│   │   ├── sea.js.d
│   │   └── seajs-text.js.d
│   └── vue
│   ├── vue.js.d
│   ├── vue-router.min.js.d
│   ├── vue-scroller.min.js.d
│   └── vue-scroller.min.js.map.d
├── frontend_7_06_js_test_0303.7z
└── jy
└── ggqq
├── function
│   └── function.js.d
├── ggqq_index.html.d
├── image
│   ├── add.png.d
│   ├── delete.png.d
│   ├── drcj.png.d
│   ├── fall.png.d
│   ├── ggqq_chicang.png.d
│   ├── ggqq_cljy.png.d
│   ├── ggqq_index_b.png.d
│   ├── ggqq_index.png.d
│   ├── ggqq_kcwt.png.d
│   ├── ggqq_ksxd.png.d
│   ├── ggqq_minus.png.d
│   ├── ggqq_nologin.png.d
│   ├── ggqq_plus.png.d
│   ├── ggqq_sybg.png.d
│   ├── ggqq_xq.png.d
│   ├── gou.png.d
│   ├── kcwt.png.d
│   ├── loading.gif.d
│   ├── minus.png.d
│   ├── mymoney.png.d
│   ├── notselect.png.d
│   ├── others@2x.png.d
│   ├── reset.png.d
│   ├── right2.png.d
│   ├── right.png.d
│   ├── rise.png.d
│   ├── select.png.d
│   ├── shoppingcar.png.d
│   └── zhcl@2x.png.d
├── js
│   └── ggqq_index.js.d
├── skin
│   ├── bdq.css.d
│   ├── chedan.css.d
│   ├── ggqq_bdsx.css.d
│   ├── ggqq_chicang.css.d
│   ├── ggqq_edcx.css.d
│   ├── ggqq_hylist.css.d
│   ├── ggqq_hysx.css.d
│   ├── ggqq_index.css.d
│   ├── ggqq_notice.css.d
│   ├── ggqq_qindex.css.d
│   ├── ggqq_xq.css.d
│   ├── ggqq_xycx.css.d
│   ├── ggqq_xyxq.css.d
│   ├── jsd.css.d
│   ├── login_mesg.css.d
│   ├── qchicang.css.d
│   ├── revisepassword.css.d
│   └── zjcc.css.d
└── skin01
├── bdq.css.d
├── ggqq_bankcr.css.d
├── ggqq_bdsx.css.d
├── ggqq_chicang.css.d
├── ggqq_edcx.css.d
├── ggqq_hylist.css.d
├── ggqq_hysx.css.d
├── ggqq_index.css.d
├── ggqq_notice.css.d
├── ggqq_qindex.css.d
├── ggqq_xq.css.d
├── ggqq_xycx.css.d
├── ggqq_xyxq.css.d
├── jsd.css.d
├── login_mesg.css.d
├── revisepassword.css.d
└── zjcc.css.d

二、思路

让前端开发把需要打入app的H5文件放入D:\scripts\src目录上  --->  读取该目录下文件的绝对路径  --->  在workspace中寻找对应的文件 ---> 并将这些文件复制到新的目录中,进行7za打包

python代码如下:

 #!/usr/bin/env python3
#-*- coding:GBK -*-
# author by Michael Ho
# contact:rui.he@geekthings.com.cn
import os, shutil def copy_app_H5_file(x_root, x_dir, src_dir, dst_dir):
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
for root, dirs, files in os.walk(x_root):
for d_name in dirs:
d_name = os.path.join(root, d_name).rstrip()
d_dir = d_name.replace(x_dir, dst_dir)
if not os.path.exists(d_dir):
os.makedirs(d_dir)
for f_name in files:
f_name = os.path.join(root, f_name).rstrip()
if(os.path.splitext(f_name)[1] == ".d"):
s_file = f_name.replace(x_dir, src_dir)
d_file = f_name.replace(x_dir, dst_dir)
shutil.copyfile(s_file, d_file)
# 判断复制是否成功
if(s_file.replace(src_dir, "") == d_file.replace(dst_dir, "")):
print(d_file + "->" + "拷贝成功")
else:
print("拷贝过程发生错误,请检查...") if __name__ == '__main__':
# 上传的小包根目录,默认是d:\scripts,不要去动它!!!
x_root = "d:\\scripts" # 小包目录,默认是src,需要把小包的文件放在一个叫src目录里面!!!
x_dir = "d:\\scripts\\src" # 从gitlab上获取的目录
src_dir = "d:\\Jenkins\\frontend_encrypt" # 需要复制到目标目录,一般对其目录进行打包
dst_dir = "d:\\Jenkins\\H5_APP" copy_app_H5_file(x_root, x_dir, src_dir, dst_dir)

三、说明

1.在Jenkins客户端在Windows上,python编码格式要设定成    # -*- coding:GBK -*-  (笔者当时写的是 # -*- coding: utf-8 -*-)不然Jenkins会报以下错误

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xbf in position 0: invalid start byte

2.python调系统级的接口不算太友好,个人认为没有批处理方便。如果整个文件夹复制的话,还是 xcopy  src_dir dst_dir /s /e /f方便,所以Jenkins上打包的脚本,笔者为了打包速度,Windows打包机采用batch+python【以上个人见解、水平有限】

python复制多层目录下的文件至其他盘符对应的目录中的更多相关文章

  1. rsync+inotify 实现资源服务器的同步目录下的文件变化时,备份服务器的同步目录更新,以资源服务器为准,去同步其他客户端

    测试环境: 资源服务器(主服务器):192.168.200.95 备份服务器(客户端):192.168.200.89 同步目录:/etc/test 同步时使用的用户名hadoop密码12345 实验目 ...

  2. PHP 批量获取指定目录下的文件列表(递归,穿透所有子目录)

    //调用 $dir = '/Users/xxx/www'; $exceptFolders = array('view','test'); $exceptFiles = array('BaseContr ...

  3. python统计目录和目录下的文件,并写入excel表

    运营那边提出需求,有些媒体文件需要统计下 目录结构大概是这样的 每个目录下面都有很多文件,目录下面没子目录 我这里是模拟下创建的目录和文件,和运营那边说的目录结构都是一致的 想最终统计结果如下格式 我 ...

  4. Python递归遍历目录下所有文件

    #自定义函数: import ospath="D:\\Temp_del\\a"def gci (path): """this is a stateme ...

  5. Python开发【笔记】:获取目录下所有文件

    获取文件 import os def sub_dirs(rdir): li = os.listdir(rdir) return li def main(rdir): content = sub_dir ...

  6. python实现指定目录下批量文件的单词计数:并发版本

    在 文章 <python实现指定目录下批量文件的单词计数:串行版本>中, 总体思路是: A. 一次性获取指定目录下的所有符合条件的文件 -> B. 一次性获取所有文件的所有文件行 - ...

  7. Python打开目录下所有文件

    用Python打开指定目录下所有文件,统计文件里特定的字段信息. 这里是先进入2017-02-25到2017-03-03目录,然后进入特定IP段目录下,最后打开文件进行统计 import os, gl ...

  8. Python遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例

    遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例: #-*- encoding: utf-8 -*- __author__ = 'liudong' import linecache,sys ...

  9. Python 读取某个目录下的文件

    读取某个目录下的文件,如'/Users/test/test_kmls'目录下有test1.txt.test2.txt. 第一种方法读出的all_files是test1.txt.test2.txt im ...

随机推荐

  1. 【转】Linux虚拟终端命令Screen用法详解

    转自 http://www.linuxidc.com/Linux/2013-07/87415.htm 在使用ssh或者telnet登录远程主机后,执行一些耗时的命令,如果此时ssh或者telnet中断 ...

  2. StartDT AI Lab | 视觉智能引擎之算法模型加速

    通过StartDT AI Lab专栏之前多篇文章叙述,相信大家已经对计算机视觉技术及人工智能算法在奇点云AIOT战略中的支撑作用有了很好的理解.同样,这种业务牵引,技术覆盖的模式也收获了市场的良好反响 ...

  3. mysql绿色版安装及授权连接

    --安装包官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads --安装教程参见:https://www.cnblogs.co ...

  4. Hibernate/JPA中@Where使用时注意

    在使用Hibernate或者JPA时,我们经常会使用@Where注解实现查询过滤,在实体类上.实体属性上.查询语句上都有应用. 例如: @Where(clause = "status != ...

  5. 常见字体图标库——font-awesome

    1.简介 FontAwesome一种带有网页功能的象形文字语言,并收集在一个集合里.字库中有675个图标,只支持英文搜索,中文地址:http://www.fontawesome.com.cn/ 2.使 ...

  6. 75)PHP,session在使用时的一些语法问题

    (1)cookie仅能存字符串类型,但是session能存任何数据类型,比如: 然后我在session_2.php中输出这个session_1.php的数据: 结果展示: 我得在浏览器的地址栏中先请求 ...

  7. mycat(读写分离、负载均衡、主从切换)

    博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽 1.环境准备 1.1新增两台虚拟机 mycat01:192.168.247.81 mycat02:192.168.247 ...

  8. 在CentOS安装CMake (CentOS7 64位适用)

    在CentOS安装CMake 转自:http://www.cnblogs.com/mophee/archive/2013/03/19/2969456.html 一.环境描述 1.系统:CentOS 6 ...

  9. [LC] 28. Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  10. 【待填坑】LG_4996_咕咕咕

    正解思路和[AHOI]的中国象棋非常相似,同样是利用状态不一定一定要表示出来,利用组合数学递推节省枚举时间.