Created
December 25, 2013 04:42
-
-
Save timothyclemans/8120210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil, errno | |
import os | |
def copyanything(src, dst): | |
try: | |
shutil.copytree(src, dst) | |
except OSError as exc: # python >2.5 | |
if exc.errno == errno.ENOTDIR: | |
shutil.copy(src, dst) | |
else: pass | |
scriptname = 'FlipACoin2' | |
voice_trigger = 'flip a coin' | |
script = """ | |
<h1>Heads</h1> | |
""" | |
copyanything('wearscript/glass/WearScript', scriptname) | |
print 'replace ' | |
os.system("find . -name \"*\" -print | xargs sed -i 's/dappervision.wearscript/weariverse.%s/g'" % (scriptname.lower())) | |
os.system("find . -name \"*\" -print | xargs sed -i 's/dappervision/weariverse/g'") | |
os.rename('%s/src/main/java/com/dappervision' % (scriptname), '%s/src/main/java/com/weariverse' % (scriptname)) | |
os.rename('%s/src/main/java/com/weariverse/wearscript' % (scriptname), '%s/src/main/java/com/weariverse/%s' % (scriptname, scriptname.lower())) | |
# set the voice trigger | |
f = open('%s/src/main/res/xml/voice_trigger_launcher.xml' % (scriptname), 'r') | |
old = f.read() | |
f = open('%s/src/main/res/xml/voice_trigger_launcher.xml' % (scriptname), 'w') | |
f.write(old.replace('start wear script', voice_trigger)) | |
f.close() | |
os.system('rm %s/build/apk/WearScript-debug-unaligned.apk' % (scriptname)) | |
# set the script | |
default = "<script>function s() {WS.say('Server connected')};window.onload=function () {WS.serverConnect('{{WSUrl}}', 's')}</script>" | |
f = open('%s/src/main/java/com/weariverse/%s/activities/MainActivity.java' % (scriptname, scriptname.lower()), 'r') | |
old = f.read() | |
f = open('%s/src/main/java/com/weariverse/%s/activities/MainActivity.java' % (scriptname, scriptname.lower()), 'w') | |
f.write(old.replace(default, script.replace('\n', ''))) | |
f.close() | |
# build script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment