|
@@ -0,0 +1,48 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+'''
|
|
|
+@Contact : liuyuqi.gov@msn.cn
|
|
|
+@Time : 2023/09/27 14:57:31
|
|
|
+@License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
|
|
|
+@Desc : enter point
|
|
|
+mastergo 保存的sketch文件,解压后,修改json文件,将所有的webp图片转换为png,然后重新打包为sketch文件
|
|
|
+'''
|
|
|
+
|
|
|
+import os,sys,re,json
|
|
|
+
|
|
|
+def fix_sketch(file_name:str, file_path:str):
|
|
|
+ # unzip the sketch
|
|
|
+ tmp_folder=file_path.split('.')[0]
|
|
|
+ if not os.path.exists(tmp_folder):
|
|
|
+ os.mkdir(tmp_folder)
|
|
|
+ os.system('"C:\Program Files\Bandizip\bc.exe" c -target:auto -o:{}'.format(tmp_folder))
|
|
|
+ os.chdir(tmp_folder)
|
|
|
+
|
|
|
+ # fix the sketch
|
|
|
+ for page in os.listdir('pages'):
|
|
|
+ if re.match(r'.*\.json$', page):
|
|
|
+ page=json.load(open('pages/{}'.format(page),'r'))
|
|
|
+ # all image webp to png
|
|
|
+ for layer in page['layers']:
|
|
|
+ if layer['type']=='Image':
|
|
|
+ if 'image' in layer:
|
|
|
+ if 'webp' in layer['image']:
|
|
|
+ layer['image']['webp']=layer['image']['webp'].replace('.webp','.png')
|
|
|
+ for image in os.listdir("images"):
|
|
|
+ if re.match(r'.*\.webp$', image):
|
|
|
+ os.system('dwebp imagmes/{} -o imagmes/{}.png'.format(image,image.split('.')[0]))
|
|
|
+ os.remove('imagmes/{}'.format(image))
|
|
|
+ # "C:\Program Files\Bandizip\bc.exe" c aa -dir mastergo_sketch_fix
|
|
|
+ os.system('zip -r {}.sketch .'.format(file_path.split('.')[0]))
|
|
|
+ # rm -rf tmp dir
|
|
|
+
|
|
|
+def main():
|
|
|
+ current_path=os.getcwd()
|
|
|
+ for file in os.listdir():
|
|
|
+ tmp_path=os.path.join(current_path, file)
|
|
|
+ if os.path.isfile(tmp_path):
|
|
|
+ if re.match(r'.*\.sketch$',file):
|
|
|
+ fix_sketch(file,tmp_path)
|
|
|
+
|
|
|
+if __name__=='__main__':
|
|
|
+ main()
|