Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print
- print "Begin"
- import subprocess
- import os
- def check(needle, haystack):
- if not needle:
- return True
- try:
- offset = haystack.index(needle[0])
- return check(needle[1:], haystack[offset+1:])
- except:
- return False
- def contains_sublist(lst, sublst):
- n = len(sublst)
- return any((sublst == lst[i:i+n]) for i in xrange(len(lst)-n+1))
- def isMain(path):
- """Takes path and searches for the main method"""
- with open(path, 'r') as f:
- lines = f.readlines()
- for line in lines:
- if contains_sublist(line.split(), "public static void main(String[]".split()):
- return True
- return False
- def runjava(path):
- print path
- print "javac", path
- subprocess.call(["javac", path])
- print "java", path[:-5]
- subprocess.call(["java", path[:-5]])
- for d in os.walk('.').next()[1]:
- print "*.java files from ./{}:".format(d)
- javafiles = filter(lambda x: x.endswith(".java"), os.listdir("./" + d))
- for f in javafiles:
- print "\t", f[:-5]
- fullpath = "./" + d + "/" + f
- if isMain(fullpath):
- print "\t\tMain found!"
- runjava(fullpath)
- print
- # clean up and delete class files
- for dirname, dirnames, filenames in os.walk('.'):
- for filename in filenames:
- if filename.endswith(".class"):
- os.remove(os.path.join(dirname, filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement