-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
60 lines (49 loc) · 1.92 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from fnmatch import fnmatch
import zipfile
from shutil import rmtree
QGIS_USER_PROFILE = 'PluginTest'
PKG_NAME = 'SEILAPLAN'
ZIP_EXCLUDES = [
'__pycache__',
'.pro',
'.ts',
'set_german_translation',
'tool_',
'STANDALONE',
'commonPaths.txt',
'help/build',
'help/source',
'help/Makefile',
'help/make.bat',
'templates',
'_pole_symbols.svg'
]
def create_zip(zip_path, folder_path, ignore_patterns):
print('Creating ZIP archive ' + zip_path)
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(folder_path):
for file in files:
path = os.path.join(root, file)
archive_path = os.path.relpath(os.path.join(root, file), os.path.join(folder_path, os.pardir))
if not any(fnmatch(path, '*' + ignore + '*') for ignore in ignore_patterns):
print('Adding ' + archive_path)
zipf.write(path, archive_path)
else:
print('Ignoring ' + archive_path)
print('Created ZIP archive ' + zip_path)
if __name__ == '__main__':
# Deploy to another qgis profile for testing and packing
import subprocess
run_pb_tool = subprocess.check_output(['pbt', 'deploy', '--user-profile', QGIS_USER_PROFILE, '-y'])
# Extract deploy path
outputList = run_pb_tool.split(b'\n')
deployPath = ([line for line in outputList if b'Deploying to ' in line])[0].split(b' ')[-1]
plugin_dir = deployPath.decode('utf-8')
zip_file = os.path.join(os.path.dirname(plugin_dir), PKG_NAME + '.zip')
# Zip content of deployed plugin
create_zip(zip_file, plugin_dir, ZIP_EXCLUDES)
# Now remove deployed plugin folder and extract zip file to have the final "cleaned up" version
rmtree(plugin_dir)
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall(os.path.dirname(plugin_dir))