2017-06-07 15:42:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding=utf-8
|
2017-05-02 15:37:55 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
# List of files which must be loaded first
|
2017-06-07 15:42:09 +00:00
|
|
|
PRELOAD = (
|
2017-05-02 15:37:55 +00:00
|
|
|
'random/random.js',
|
|
|
|
'random/mersennetwister.js',
|
|
|
|
'utils/init.js',
|
|
|
|
'utils/platform.js',
|
|
|
|
'logging/console.js',
|
|
|
|
'make/init.js'
|
2017-06-07 15:42:09 +00:00
|
|
|
)
|
2017-05-02 15:37:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def argparser():
|
|
|
|
parser = argparse.ArgumentParser()
|
2017-06-07 15:42:09 +00:00
|
|
|
parser.add_argument('-l', '--libs', required=True,
|
|
|
|
help='Directory containing the octo libraries.')
|
|
|
|
parser.add_argument('-d', '--deploy', required=True,
|
|
|
|
help='Directory where the combined octo library will be built.')
|
2017-05-02 15:37:55 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if not os.path.isdir(args.libs):
|
|
|
|
parser.error("Lib directory doesn't exist!")
|
|
|
|
if not os.path.isdir(args.deploy):
|
|
|
|
parser.error("Deploy directory doesn't exist!")
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = argparser()
|
|
|
|
|
|
|
|
data = []
|
2017-06-07 15:42:09 +00:00
|
|
|
loaded = set()
|
2017-05-02 15:37:55 +00:00
|
|
|
|
2017-06-07 15:42:09 +00:00
|
|
|
for filename in PRELOAD:
|
2017-05-02 15:37:55 +00:00
|
|
|
path = os.path.join(args.libs, filename)
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
raise Exception("Unable to find file in preload: {0}".format(path))
|
|
|
|
print("Adding path: {0}".format(path))
|
2017-06-07 15:42:09 +00:00
|
|
|
with open(path, 'rb') as f:
|
2017-05-02 15:37:55 +00:00
|
|
|
data.append(f.read())
|
2017-06-07 15:42:09 +00:00
|
|
|
loaded.add(path)
|
2017-05-02 15:37:55 +00:00
|
|
|
|
2017-06-07 15:42:09 +00:00
|
|
|
for root, _, files in os.walk(args.libs):
|
2017-05-02 15:37:55 +00:00
|
|
|
for filename in files:
|
|
|
|
path = os.path.join(root, filename)
|
|
|
|
if path.endswith('.js') and path not in loaded:
|
|
|
|
print("Adding path: {0}".format(path))
|
2017-06-07 15:42:09 +00:00
|
|
|
with open(path, 'rb') as f:
|
2017-05-02 15:37:55 +00:00
|
|
|
data.append(f.read())
|
2017-06-07 15:42:09 +00:00
|
|
|
|
2017-05-02 15:37:55 +00:00
|
|
|
octo_path = os.path.join(args.deploy, 'octo.js')
|
2017-06-07 15:42:09 +00:00
|
|
|
with open(octo_path, 'wb') as f:
|
|
|
|
f.write(b'\n\n'.join(data))
|
2017-05-02 15:37:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|