#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
import os.path
import sys
import socket
import md5
import json
import zipfile
# nginx服務(wù)器的路徑
nginxServePath = "/usr/local/var/www/"
# weex.json文件目錄
nginxWeexJsonFilePath = nginxServePath + "weex.json"
# js文件夾的路徑流部,即bundle文件夾路徑
jsFileInNginxPath = nginxServePath + "bundle"
# js的zip壓縮包路徑,即bundle.zip文件夾路徑
jsZipFileInNginxPath = nginxServePath + "bundle.zip"
# 圖片所有文件夾路徑
imgFileInNginxPath = nginxServePath + "imgs"
# 圖片壓縮包所有文件夾路徑
imgZipFileInNginxPath = nginxServePath + "imgs.zip"
# 另一種命名,js文件夾的路徑弦叶,即bundle文件夾路徑
jsFileInNginxPath2 = nginxServePath + "dist"
# 另一種命名,js的zip壓縮包路徑,即bundle.zip文件夾路徑
jsZipFileInNginxPath2 = nginxServePath + "dist.zip"
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
def zip_dir(dirname,zipfilename):
filelist = []
if os.path.isfile(dirname):
filelist.append(dirname)
else :
for root, dirs, files in os.walk(dirname):
for name in files:
filelist.append(os.path.join(root, name))
zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED)
for tar in filelist:
arcname = tar[len(dirname):]
zf.write(tar,arcname)
zf.close()
# 刪除之前存在的相關(guān)文件
filePaths = [nginxWeexJsonFilePath, jsFileInNginxPath, jsZipFileInNginxPath, imgFileInNginxPath, imgZipFileInNginxPath, jsFileInNginxPath2, jsZipFileInNginxPath2]
for filePath in filePaths:
if os.path.exists(filePath):
os.system('rm -rf ' + filePath)
# reload(sys)
# sys.setdefaultencoding("utf-8")
pageDicts = []
weexJsonDict={}
jsFileInNginxPaths = []
os.system('weex compile src/ /usr/local/var/www/bundle')
os.system('echo .......... processing ..........')
#檢查incluce文件夾
includeFolderPath = os.path.abspath(os.curdir)+'/src/include'
if os.path.exists(includeFolderPath):
if os.path.exists(jsFileInNginxPath+'/include'):
#檢查遺漏的js文件
f_list = os.listdir(includeFolderPath)
for i in f_list:
if os.path.splitext(i)[1] == '.js':
os.system('cp -r ' + includeFolderPath +'/'+i +' '+ jsFileInNginxPath+'/include/'+i)
else:
#include文件里不包含vue文件
os.system('cp -r ' + includeFolderPath +' '+ jsFileInNginxPath+'/include')
imgsPath = os.path.abspath(os.curdir)+'/src/imgs'
if os.path.exists(imgsPath):
os.system('cp -r ' + imgsPath +' '+ imgFileInNginxPath)
zip_dir(imgsPath,imgZipFileInNginxPath)
for parent,dirnames,filenames in os.walk(jsFileInNginxPath):
for filename in filenames:
path = os.path.join(parent, filename)
if path.endswith('.js'):
jsFileInNginxPaths.append(path)
# 壓縮bundle文件夾為bundle.zip
zip_dir(jsFileInNginxPath,jsFileInNginxPath+'.zip')
#寫入weex.json
if jsFileInNginxPaths.count > 0:
localIP = get_host_ip()
baseUrl = "http://" + localIP + ":8080/"
for jsFileInNginxPath in jsFileInNginxPaths:
jsFileInNginxPaths = jsFileInNginxPath.replace(nginxServePath, baseUrl)
jsFileName = os.path.basename(jsFileInNginxPath)
m = md5.new()
m.update(jsFileInNginxPath)
jsFileMD5 = m.hexdigest()
pageDicts.append({"md5":jsFileMD5,"page":jsFileName,"url":jsFileInNginxPaths})
weexJsonDict["pages"] = pageDicts
weexJsonDict["patch"] = {}
m = md5.new()
m.update(jsFileInNginxPath+'.zip')
bundleZipFileMD5 = m.hexdigest()
weexJsonDict["zip"] = {"md5":bundleZipFileMD5,"url":baseUrl+'bundle.zip'}
jsonStr = json.dumps( weexJsonDict, ensure_ascii=False, encoding='UTF-8')
with open(nginxWeexJsonFilePath, 'wt') as f:
f.write(jsonStr)
os.system('echo .......... done ..........')
快速處理weex相關(guān)的python腳本
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門冀偶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人渔嚷,你說我怎么就攤上這事进鸠。” “怎么了形病?”我有些...
- 文/不壞的土叔 我叫張陵客年,是天一觀的道長霞幅。 經(jīng)常有香客問我,道長量瓜,這世上最難降的妖魔是什么司恳? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮绍傲,結(jié)果婚禮上扔傅,老公的妹妹穿的比我還像新娘。我一直安慰自己烫饼,他們只是感情好猎塞,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著杠纵,像睡著了一般邢享。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上淡诗,一...
- 文/蒼蘭香墨 我猛地睜開眼哄辣,長吁一口氣:“原來是場噩夢啊……” “哼请梢!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起力穗,我...
- 序言:老撾萬榮一對情侶失蹤毅弧,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后当窗,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體够坐,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年崖面,在試婚紗的時候發(fā)現(xiàn)自己被綠了元咙。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布感猛,位于F島的核電站,受9級特大地震影響倘零,放射性物質(zhì)發(fā)生泄漏唱遭。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一呈驶、第九天 我趴在偏房一處隱蔽的房頂上張望拷泽。 院中可真熱鬧,春花似錦袖瞻、人聲如沸司致。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽脂矫。三九已至,卻和暖如春霉晕,著一層夾襖步出監(jiān)牢的瞬間庭再,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓伟葫,卻偏偏與公主長得像恨搓,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子筏养,可洞房花燭夜當(dāng)晚...