forked from ladybug-tools/ladybug-blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist_runner.py
74 lines (56 loc) · 2.06 KB
/
dist_runner.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import shutil
import zipfile
from datetime import datetime
from generate_icons import IconsGenerator
from generate_init import InitGenerator
from generate_nodes import NodesGenerator
from package_manager import PackageManager
# TODO: Maybe refactor(Config/Util/Build)?
class Runner:
def __init__(self,
base_path=f'{os.getcwd()}{os.path.sep}dist{os.path.sep}',
version=datetime.today().strftime("%y%m%d")):
# Version to Build and Path for Outputs
self.version = version
self.base_path = base_path
# Module Output Target
target_dir = 'ladybug_tools'
# Working Directory
tmp_dir = 'working'
# Paths for Build and Working Directories
self.build_path = f'{base_path}{target_dir}{os.path.sep}'
self.work_path = f'{base_path}{tmp_dir}{os.path.sep}'
# Create the Package Downloader for the Runtime
self.package = PackageManager(runtime=self)
def destroy(self):
if os.path.isdir(self.base_path):
shutil.rmtree(self.base_path)
def bootstrap(self):
self.destroy()
shutil.copytree('ladybug_tools', self.build_path)
def clean(self):
shutil.rmtree(self.work_path)
def run(self):
# Clean the directory on every run
self.bootstrap()
# Code Generation of Files
InitGenerator(runtime=self).generate()
# TODO: Add more packages
# for pkgname in ['ladybug-grasshopper']:
# Download Grasshopper and Load Schemas
self.package.download(target='ladybug-grasshopper')
self.package.load()
IconsGenerator(runtime=self).generate()
NodesGenerator(runtime=self).generate()
self.clean()
def package(self):
# TODO: Replace __init__ Version Number
z = zipfile.ZipFile(f'{self.build_path}ladybug-blender-{self.version}.zip', 'w')
z.write(f"{self.build_path}ladybug_tools/")
z.close()
# Run only if called from CLI
if __name__ == '__main__':
rt = Runner()
rt.run()
# rt.package()