-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
111 lines (92 loc) · 2.75 KB
/
build.py
File metadata and controls
111 lines (92 loc) · 2.75 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# CODE IS POETRY
# TRADING IS MARTIAL ART
# Kolier.Li <kolier.li@gmail.com> [http://kolier.li]
# Build the Genie Project
# Usage
# build.py <lib> <dep1,dep2,dep3>
from os import listdir
from os import walk
import sys
lib = sys.argv[1]
deps = []
if len(sys.argv) > 2:
deps = sys.argv[2].strip().split(',')
# Header Block
header = """// CODE IS POETRY
// TRADING IS MARTIAL ART
// Kolier.Li <kolier.li@gmail.com> [http://kolier.li]
// Things in Your Dreams that Pop Up When You Wish For it
"""
# ======================================
# Functions
# ======================================
# Dependencies
def depends(deps):
if len(sys.argv) <= 2:
return ''
info = separator('dependencies')
for dep in deps:
info += '#include "../' + dep + '/' + dep + '.mqh' + '"\n'
return info
# Function to Build Package Title
def separator(name):
return """
// =====================================
// {0}
// =====================================
""".format(name.title())
# Function to Print Each Module in Package
# @todo Handle empty file
def package_info(package, modules):
info = ''
for module in modules:
status = test_status(package, module)
if len(status) == 0:
info += '#include "' + module_path(package, module) + '"\n'
else:
info += '//' + status + ' #include "' + module_path(package, module) + '"\n'
return info
def module_path(package, module):
return package + '/' + module
def test_status(package, module):
file = open(lib + '/' + module_path(package, module), "r")
i = 0
for line in file:
i += 1
if i > 20:
return ''
if '@module-notready' in line:
return '@module-notready'
if '@module-deprecated' in line:
return '@module-deprecated'
return ''
def write_deps():
output = header
output += depends(deps)
f = open(lib + '/' + 'lib.mqh', 'w')
print(output.strip(), file=f)
def write_lib():
output = header
#
packages = []
for (dirpath, dirnames, filenames) in walk(lib):
packages.extend(dirnames)
packages.remove('.git')
break
for package in packages:
modules = []
for (dirpath, dirnames, filenames) in walk(lib +'/' + package):
modules.extend(filenames)
break
output += separator(package)
output += package_info(package, modules)
#
f = open(lib + '/' + lib + '.mqh', 'w')
print(output.strip(), file=f)
# ======================================
# Runtime
# ======================================
write_deps()
write_lib()