Browse Source

Hooked up cli and made Stage superclass

master
Raphael Roberts 6 years ago
parent
commit
a71731ad85
  1. 19
      android_java/__init__.py
  2. 14
      android_java/compile.py
  3. 8
      android_java/execute.py
  4. 10
      android_java/stage.py

19
android_java/__init__.py

@ -1,12 +1,18 @@
import argparse
import os
from android_java.compile import CompilerStage
from android_java.execute import ExecutionStatge
def do_compile(args):
pass
stage = CompilerStage(os.getcwd())
stage.compile(args.source_file)
def do_run(args):
pass
stage = ExecutionStatge(os.getcwd())
stage.execute_main_class(args.main_class)
def main():
@ -14,15 +20,18 @@ def main():
subparsers: argparse._SubParsersAction = parser.add_subparsers(dest="mode")
compile_parser = subparsers.add_parser("compile", help="Compile source file")
compile_parser.add_argument(
"SourceFile.java", help="The source file to compile/create dex for"
"SourceFile.java",
dest="source_file",
help="The source file to compile/create dex for",
)
java_parser = subparsers.add_parser(
run_parser = subparsers.add_parser(
"run",
help="Run main method of class. Ensure you are in the same directory as the source file",
)
java_parser.add_argument("MainClass", help="The class to run.")
run_parser.add_argument("MainClass", help="The class to run.", dest="main_class")
args = parser.parse_args()
if args.mode == "compile":
do_compile(args)
elif args.mode == "run":

14
android_java/compile.py

@ -1,19 +1,13 @@
import os
import subprocess
os.mkdir
from android_java.stage import Stage
def make_droid_dir(root):
droid_dir = os.path.join(root, ".droid")
os.makedirs(droid_dir, exist_ok=True)
return droid_dir
class CompilerStage:
class CompilerStage(Stage):
def __init__(self, source_root):
self.source_root = source_root
self.droid_dir = make_droid_dir(source_root)
super().__init__(source_root)
self.make_droid_dir()
def create_ecj_command(self):
cmdline = ["ecj"]

8
android_java/execute.py

@ -1,13 +1,11 @@
import os
import subprocess
from android_java.exceptions import NoClassesFoundError
from android_java.exceptions import NoClassesFoundError
from android_java.stage import Stage
class ExecutionStatge:
def __init__(self, source_root):
self.source_root = source_root
self.droid_dir = os.path.join(source_root, ".droid")
class ExecutionStatge(Stage):
def execute_main_class(self, classname):
classes_dex_file = os.path.join(self.droid_dir, "classes.dex")
if not os.path.exists(classes_dex_file):

10
android_java/stage.py

@ -0,0 +1,10 @@
import os
class Stage:
def __init__(self, source_root):
self.source_root = source_root
self.droid_dir = os.path.join(self.source_root, ".droid")
def make_droid_dir(self):
os.makedirs(self.droid_dir, exist_ok=True)
Loading…
Cancel
Save