| 1 |
|
|---|
| 2 |
import os, sys |
|---|
| 3 |
import preproc,subprocess |
|---|
| 4 |
|
|---|
| 5 |
phpast="" |
|---|
| 6 |
phporacle="" |
|---|
| 7 |
phpfiles = [] |
|---|
| 8 |
|
|---|
| 9 |
def my_sys(cmd): |
|---|
| 10 |
subprocess.Popen(cmd).wait() |
|---|
| 11 |
|
|---|
| 12 |
def register(): |
|---|
| 13 |
global phpast,phporacle |
|---|
| 14 |
phpast = os.path.join(os.path.abspath(os.curdir), "php-ast") |
|---|
| 15 |
phporacle = os.path.join(os.path.abspath(os.curdir), "php-oracle") |
|---|
| 16 |
|
|---|
| 17 |
def populate_PROJ(dirname): |
|---|
| 18 |
global phpfiles |
|---|
| 19 |
all = {} |
|---|
| 20 |
all = [f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, f)) or os.path.isfile(os.path.join(dirname, f))] |
|---|
| 21 |
for f in all: |
|---|
| 22 |
if os.path.isdir(dirname + '/' + f): |
|---|
| 23 |
populate_PROJ(dirname + '/' + f) |
|---|
| 24 |
else: |
|---|
| 25 |
if f.find(".php") > -1 or f.find('.inc') > -1: |
|---|
| 26 |
if '.study.' not in f and '.php.xml' not in f: |
|---|
| 27 |
phpfiles.append(os.path.join(dirname, f)) |
|---|
| 28 |
|
|---|
| 29 |
def generate_AST(): |
|---|
| 30 |
for fname in phpfiles: |
|---|
| 31 |
preproc.pp_file(fname) |
|---|
| 32 |
sname = fname + '.study.php' |
|---|
| 33 |
xml_name = sname[:sname.find('.study.php')] + '.xml' |
|---|
| 34 |
print "### ", sname |
|---|
| 35 |
my_sys("php-ast " + sname + " " + xml_name) |
|---|
| 36 |
print "" |
|---|
| 37 |
|
|---|
| 38 |
def generate_RESULTS(): |
|---|
| 39 |
for fname in phpfiles: |
|---|
| 40 |
sname = fname + '.study.php' |
|---|
| 41 |
xml_name = sname[:sname.find('.study.php')] + '.xml' |
|---|
| 42 |
res_name = xml_name[:xml_name.find('.xml')] + '.res.txt' |
|---|
| 43 |
if os.path.isfile(xml_name): |
|---|
| 44 |
my_sys("php-oracle " + xml_name + " " + res_name) |
|---|
| 45 |
|
|---|
| 46 |
def generate_M1(outfile): |
|---|
| 47 |
f = outfile |
|---|
| 48 |
for fname in phpfiles: |
|---|
| 49 |
sname = fname + '.study.php' |
|---|
| 50 |
xml_name = sname[:sname.find('.study.php')] + '.xml' |
|---|
| 51 |
res_name = xml_name[:xml_name.find('.xml')] + '.res.txt' |
|---|
| 52 |
if os.path.isfile(xml_name): |
|---|
| 53 |
my_sys("php-oracle -foo " + xml_name + " " + f) |
|---|
| 54 |
|
|---|
| 55 |
if __name__ == "__main__": |
|---|
| 56 |
phpfiles = [] |
|---|
| 57 |
register() |
|---|
| 58 |
phpfiles = [] |
|---|
| 59 |
populate_PROJ("./study/cms/kelev") |
|---|
| 60 |
print "Total Number of Files = ", len(phpfiles) |
|---|
| 61 |
generate_AST() |
|---|
| 62 |
|
|---|
| 63 |
generate_M1("kelev.xml") |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|