From e1ac771f1e84b9b2d8428488360599a07add3a88 Mon Sep 17 00:00:00 2001 From: kipply Date: Sun, 26 Aug 2018 05:25:36 -0400 Subject: [PATCH] Running shit skeleton (no actual translate) --- client/venv/polycode.py | 48 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/client/venv/polycode.py b/client/venv/polycode.py index 06b2295..f5792c8 100644 --- a/client/venv/polycode.py +++ b/client/venv/polycode.py @@ -43,6 +43,7 @@ def help(): polycode --f targetfile ES -> Translates file 'targetfile' into Spanish polycode define -w word -d newDef -l LANG -> Changes definition 'word' to 'newDef' for language 'LANG'. Language is optional and will default to your preferred output languages. polycode definition -w word -l LANG -> Returns definition for 'word' for language 'LANG'. Language is optional and will default to your preferred output languages. + polycode python -f file -> Run the translated file. """ print(helptext) @@ -162,7 +163,7 @@ def translate_all(config, DEST_LANG, additional_ignores=[]): parser = argparse.ArgumentParser() parser.add_argument('command', choices=['translate', 'untranslate', - 'commit', 'pull', 'define', 'definition', 'run', 'watch']) + 'commit', 'pull', 'define', 'definition', 'python', 'flask', 'node']) parser.add_argument('-s', '--single-file', type=str, help='Translate a single file instead of the whole project') parser.add_argument('-l', '--language', type=str, @@ -389,8 +390,49 @@ def translate_all(config, DEST_LANG, additional_ignores=[]): print("Word '%s' in '%s' is '%s'" % (word, to_lang, entry[to_lang_idx])) found = True - if args.command == 'run': - pass + if args.command == 'python': + # with open('target_file') as f: + # source = f.read() + + translated_code = "print('wew')" + os.system('python -c """' + translated_code + "\"\"\"") + + if args.command == 'flask': + # with open('target_file') as f: + # source = f.read() + + translated_code = """ +from flask import Flask +app = Flask(__name__) + + +@app.route('/') +def hello_world(): + return 'Hello, World!' + """ + with open('tmp.py', 'w') as f: + f.write(translated_code) + os.system('export FLASK_APP=tmp.py && flask run') + os.remove("tmp.py") + + if args.command == 'node': + # with open('target_file') as f: + # source = f.read() + + translated_code = """ +var http = require('http'); + +var server = http.createServer((req, res) => { + res.writeHead(200); + res.end('Hi everybody!'); +}); +server.listen(8080); + """ + with open('tmp.js', 'w') as f: + f.write(translated_code) + os.system('node tmp.js') + os.remove("tmp.js") + if args.command == 'watch': pass