180 lines
6.8 KiB
Python
Executable File
180 lines
6.8 KiB
Python
Executable File
#!/usr/bin/python2.7
|
|
|
|
# 777$7II7III??+,.......:+~=7$$Z$?$OOZOZ77?$$I+??I$ZOD8DD8DD888O$7$77$Z$$$ZZZZZOOO
|
|
# $$$777$$77II??~.,..,.=?777$ZZ==$OZZ$I?=+?Z+==~=7Z7Z$OO8888DDDD8ZOZ$$$7Z$ZOZ$ZZOO
|
|
# $$$7ZZ$Z$$77II=~:.,.:??+IZZZ+?O$ZI+?+:~+7I~~,:~?Z$88O88D88DDDDD8OZOZ$$$ZZZZZOOZZ
|
|
# $$$$ZZ$$$$777I??:::,:7ZZ8OZ$$$7?=::,:~??~:,.....7$8$IZDDD8DDDNDDOZZO$$ZZZZZOZOOO
|
|
# $$$77$7$7III$II+==+$$$OOO8OZ?=:......~. ........,?ZOI$88DOD8DDN8D888$7$ZZ$$Z$$ZO
|
|
# $$7$$$77I77$ZZ$7,:Z$OZOOOOOI. ...,~:.....:~~+:===$Z$7OOD8DDD88O8D888O$7$Z$$$$OZ
|
|
# $$77$$77I$$ZOZI,.7Z88O88O8?. .,:~~::,,.,,,+?$ZZZZZ8OZZ$8$8NDDDD88ODO8ZZ$$$OZZZOO
|
|
# Z$Z$$$77$Z$$O$~.~?$ZOOOOOZ, ,?7$7II+:..,~+$III777I77I$O8OD8DD8D8DO8D88$77$$$ZZZZ
|
|
# OOOOZc$ZOZOZZ?..+??IZO8NO$I?===+=~~~,...,~II???+~:+~:+ZO8D88DOODDDDD8D88OZ77$ZZZ
|
|
# ZOZOOZZZZZOZ$II.~?I$ZZO8ZO~. ..~?+~~.. .,?$I$ZO888O?~$Z88D888O8888DONDD88Z7777$
|
|
# OZZ8O8OZZOZZZZ7I7I$ZZ7$OZ7:.=7ZDO7?~.. ,::+O7$O8O78O7IOD88N8D8DD88DD8OOOO7$$7Z
|
|
# OOOZ88888OOOOZZI~?I$Z$OZI+?77,?$I?:.. .,:,,~,,~+++~+I$ZZ8DDD8DNDD8DDOOOZ7?$$7$
|
|
# OOOZO88OO8OZ7=:,.?7IZZOZI,~=~. ... . ..,,.. ...=:..~I$Z8DDDD8D8DDOD88a7II777$
|
|
# $OOOOOOO8O+.,.:++:++$ZOO7 .,. .,,,.... ..:~.:$Z8DD8DDD88DDD8O$?????I7
|
|
# OO8O8O8OZ$.,:?=..::?IZZ8Z .. ..,.,=,.. ..:I??7O8DD88D888D8OOI?II77II
|
|
# OOOO8OZZ7=,~7?~,,,~~?$7OZ,. .,:~=:,.,:, ..:=+:~788DDD88Z888OZ$+I?III$7
|
|
# ZOZZO$$$ZZZZ$I:~:~,,7=77$~:.. .:$$==IOO7=,.,....,:,:=+$D8DD8888D887II?7777$$
|
|
# ZOOZZZ$$ZZZZ7+::=:::::II~.:.. ..=+?+IIII:...,,..,,,:==$DDD88888DD8$ZZ$$ZOOOO
|
|
# 7ZO$n7I$$$Z$7I~,,:,,.,=?:,,.. . ,:::~~I?:,......,,:,:=ZO888D88D8DO88O8888888
|
|
# 77777$77$$7I?~,.. .,,,=+~.. ~+=:~+:+II+=~:,:..,,::~?ZODO888D88DD8DDDD8D88N
|
|
# ?77???I?II?~:,.....=.:?+~. ., .:?7I:::~::=+~~...,:~=?$OOOZ888OO8OO8888D8D8D
|
|
# 7II??I+++~:,.. .,==$7+,. .IZ7~~~~,~:++=:..::~++7ZZODDD8D888a8OOD88D88
|
|
# I???+~:,,,... .=:=~I$$+, .$7?+++++=+==+~,,:==+?78DDDDDDDO88OZOO88O888
|
|
# ??+::,,... ... .78Z7IZO=...... ,77:..:::.,~?+~::=++~?$8DDDN8D8O88O88OOOOO88
|
|
# ~=~:,,,.,.... .:OO$Z$7... ?$~ .......,:=~,:++==?$88D88D8ZOZOOZOOOO8DOO
|
|
# :~=+:,,.. . ..,?$$+.. =...::,... ,~::~?===+OD88888OZOOOZO$ZOOZZZ8
|
|
# ,~++++==.. ....~ZZO~. .:~=~,,...:=~~$7?+?$DD8D8OOZZOZOZOOOO8O8O8
|
|
# .:=+==++,. ...,.:+8DZ...I$7:.....,~=:,....+~?I7=?=$O8DDOOZ88OOO8OOOOOZZO88
|
|
# ,:~===?d, .:,:?OD8O...ZOO$$?I,...=~:,,,,~===?+?+77Z8OZ$Z$OOZZOOO8OOOOO8O8
|
|
# ,:~=~~=+.. ..=Z8888$.+OZ8OOZ8O7,.::=:~~=~:+????I$$?7$$ZZZOOOOOOOOO8O8OOOOO
|
|
# ,,:~~~+=.. ~ZO87I7Z,:7OOZOO?OD$~,:~:+?+==+?+=+77$?IOOZZZOOOOO8OOOOOOOOO888
|
|
# ..,,~=+~.. . =$OO:..+?.IZOOZOZ$OZ?=~=~=++=+:?III7$7I=7DD8ZZOO8OO88OO8ZOZ$ZOOO
|
|
# ..... .... . ,~?7OZ7..:~I+ZZOO$OOOZZ$+7++?+??I777$$Z7I?~Z8D8OO$Z888O8888ZOZOZOO8
|
|
# ,.....,~~==:=?$ZOZ7 .,~7IZZOZZZZOOOZO$I$Z$$Z$Z$ZZ7$I+==~DDDN8DDO$O88D8DDZO8OZ888
|
|
# =+=:~::=~~:+$ZZZ$+...I77$OZ$$IIZ$?$Z7=======~=++??==,::=D8D88D8D8ZOODOOOZZ8ZOaOO
|
|
|
|
import os, platform, sys, shutil
|
|
import urllib2
|
|
import zipfile, tarfile
|
|
from StringIO import StringIO
|
|
from optparse import OptionParser
|
|
|
|
teensy_src_url = "https://github.com/PaulStoffregen/cores/archive/master.zip"
|
|
arm_tool_chain_url_mac = "https://launchpad.net/gcc-arm-embedded/4.8/4.8-2013-q4-major/+download/gcc-arm-none-eabi-4_8-2013q4-20131218-mac.tar.bz2"
|
|
arm_tool_chain_url_linux = "https://launchpad.net/gcc-arm-embedded/4.8/4.8-2013-q4-major/+download/gcc-arm-none-eabi-4_8-2013q4-20131204-linux.tar.bz2"
|
|
|
|
basepath = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
def run():
|
|
print "#0 staging"
|
|
|
|
if not os.path.exists("libs"):
|
|
os.mkdir("libs")
|
|
if not os.path.exists("src"):
|
|
os.mkdir("src")
|
|
|
|
# link to gcc and teensy tools
|
|
os.symlink(os.path.join(basepath, "tools"), "tools")
|
|
|
|
#ftech teensy3
|
|
print "#1 fetching teensy3"
|
|
teensy_cores_src = urllib2.urlopen(teensy_src_url)
|
|
teensy_zip_file = zipfile.ZipFile(StringIO(teensy_cores_src.read()))
|
|
|
|
for n in teensy_zip_file.namelist():
|
|
(dirname, filename) = os.path.split(n)
|
|
if "teensy3" in dirname:
|
|
dirname = "libs" + os.sep + dirname.replace("cores-master/", "")
|
|
if filename == '':
|
|
if not os.path.exists(dirname):
|
|
os.mkdir(dirname)
|
|
else:
|
|
fp = open(os.path.join(dirname, filename), 'wr');
|
|
fp.write(teensy_zip_file.read(n))
|
|
fp.close();
|
|
|
|
teensy_zip_file.close()
|
|
|
|
if not os.path.exists("src" + os.sep + "main.cpp"):
|
|
shutil.move("libs" + os.sep + "teensy3" + os.sep + "main.cpp", "src")
|
|
|
|
print "#2 fetching Makefile"
|
|
|
|
shutil.copy(os.path.join(basepath, "t3make00.makefile"), "Makefile")
|
|
|
|
print "done."
|
|
|
|
def sanity():
|
|
if not os.path.exists(os.path.join(basepath, "tools")):
|
|
sys.exit("No valid installation yet. Aborting. \nPlease run t3make00 --install once before creating projects.");
|
|
|
|
def install():
|
|
|
|
print "#0 staging"
|
|
|
|
platform_name = platform.system()
|
|
if platform_name == "Darwin":
|
|
arm_tool_chain_url = arm_tool_chain_url_mac
|
|
elif platform_name == "Linux":
|
|
arm_tool_chain_url = arm_tool_chain_url_linux
|
|
else:
|
|
print "Platform " + platform_name + "not supported. Aborting..."
|
|
sys.exit(0)
|
|
|
|
base_tools = os.path.join(basepath, "tools")
|
|
|
|
if not os.path.exists(base_tools):
|
|
os.mkdir(base_tools)
|
|
|
|
|
|
print "#1 fetching arm toolchain (may take minutes)"
|
|
|
|
arm_tool_chain_src = urllib2.urlopen(arm_tool_chain_url)
|
|
arm_tool_chain_src_io = StringIO(arm_tool_chain_src.read())
|
|
arm_tool_chain_tar = tarfile.open(fileobj=arm_tool_chain_src_io, mode="r:bz2")
|
|
arm_tool_chain_tar.extractall(path=base_tools)
|
|
arm_tool_chain_tar.close()
|
|
|
|
for f in os.listdir(base_tools):
|
|
if f.startswith("gcc"):
|
|
os.rename(os.path.join(base_tools, f), os.path.join(base_tools, "gcc"))
|
|
|
|
print "#2 fetching teensy-tools"
|
|
|
|
teensy_tools_tar = tarfile.open(os.path.join(basepath, "teensy-tools.tar.bz2"), mode="r:bz2")
|
|
teensy_tools_tar.extractall(path=base_tools)
|
|
teensy_tools_tar.close()
|
|
|
|
print "#3 updating PATH"
|
|
|
|
home = os.path.expanduser("~")
|
|
bashrc = os.path.join(home, ".bashrc")
|
|
|
|
if not os.path.exists(bashrc):
|
|
with open(bashrc, "a") as fp:
|
|
fp.write("PATH=$PATH:" + basepath + "\n")
|
|
fp.write("export PATH")
|
|
else:
|
|
print "Please add " + basepath + "to your ~/.bashrc PATH"
|
|
|
|
if __name__ == '__main__':
|
|
|
|
p = OptionParser();
|
|
p.add_option('-i', '--install', action="store_true", help="installs t3make00 (~/.bashrc)")
|
|
p.add_option('-p', '--project', action="store", help="name of the project (defaults to value args[0])")
|
|
|
|
options, args = p.parse_args()
|
|
|
|
if options.install:
|
|
install()
|
|
sys.exit(1)
|
|
|
|
if not options.project and len(args) == 0:
|
|
sys.exit("No project specified. Aborting.\nt3make00 --help for usage information.");
|
|
if len(args) > 1:
|
|
sys.exit("Too many arguments. Aborting.\nt3make00 --help for usage information.");
|
|
|
|
project_path = '.'
|
|
|
|
if options.project:
|
|
project_path = options.project
|
|
else:
|
|
project_path = args[0]
|
|
|
|
if not os.path.exists(project_path):
|
|
os.mkdir(project_path)
|
|
|
|
os.chdir(project_path)
|
|
sanity()
|
|
run()
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|