|
8 | 8 | timeout = str(sys.argv[3])
|
9 | 9 |
|
10 | 10 |
|
| 11 | +java_file_class_name = str() |
| 12 | + |
| 13 | + |
11 | 14 | # for java
|
12 | 15 | def changing_class_name():
|
13 | 16 |
|
14 |
| - file = open(f"temp/{filename}.java" , 'r') |
| 17 | + grep_syntax = """'(?<=\\n|\A|\\t)\s?(public\s+)*(class|interface)\s+\K([^\\n\s{]+)'""" |
| 18 | + |
| 19 | + fl = subprocess.run(f"cd temp/ && grep -P -m 1 -o {grep_syntax} {filename}.java" ,shell=True , stdout=subprocess.PIPE,stderr=subprocess.STDOUT , timeout=60) |
| 20 | + |
| 21 | + |
| 22 | + global java_file_class_name |
| 23 | + java_file_class_name = fl.stdout.decode().strip() |
| 24 | + |
| 25 | + # for renaming the file |
| 26 | + # subprocess.run(f"cd temp/ && mv {filename}.java {java_file}.java" ,shell=True , stdout=subprocess.PIPE,stderr=subprocess.STDOUT , timeout=60) |
| 27 | + |
| 28 | + |
| 29 | + # file = open(f"temp/{filename}.java" , 'r') |
15 | 30 |
|
16 |
| - newfile = filename |
17 |
| - new_file_content = str() |
| 31 | + # newfile = filename |
| 32 | + # new_file_content = str() |
18 | 33 |
|
19 |
| - for line in file: |
20 |
| - if re.search('^class ',line): |
21 |
| - line = line.strip() |
22 |
| - ls = line.split(" ") |
| 34 | + # for line in file: |
| 35 | + # if re.search('^class ',line): |
| 36 | + # line = line.strip() |
| 37 | + # ls = line.split(" ") |
23 | 38 |
|
24 |
| - # print(ls) |
25 |
| - string = ls[1] |
26 |
| - if(string[-1] == '{'): |
27 |
| - new_line = line.replace(string , newfile+'{') |
28 |
| - new_file_content += new_line + "\n" |
| 39 | + # # print(ls) |
| 40 | + # string = ls[1] |
| 41 | + # if(string[-1] == '{'): |
| 42 | + # new_line = line.replace(string , newfile+'{') |
| 43 | + # new_file_content += new_line + "\n" |
29 | 44 |
|
30 |
| - elif(string[-1]!='{'): |
| 45 | + # elif(string[-1]!='{'): |
31 | 46 |
|
32 |
| - new_line = line.replace(string , newfile) |
33 |
| - new_file_content += new_line + "\n" |
| 47 | + # new_line = line.replace(string , newfile) |
| 48 | + # new_file_content += new_line + "\n" |
34 | 49 |
|
35 |
| - else: |
36 |
| - new_file_content += line |
| 50 | + # else: |
| 51 | + # new_file_content += line |
37 | 52 |
|
38 | 53 |
|
39 |
| - writing_file = open(f"temp/{filename}.java", "w") |
40 |
| - writing_file.write(new_file_content) |
41 |
| - writing_file.close() |
| 54 | + # writing_file = open(f"temp/{filename}.java", "w") |
| 55 | + # writing_file.write(new_file_content) |
| 56 | + # writing_file.close() |
42 | 57 |
|
43 | 58 |
|
44 | 59 |
|
@@ -89,7 +104,7 @@ def changing_class_name():
|
89 | 104 | result = output.stdout.decode()
|
90 | 105 |
|
91 | 106 | elif(extension == "java"):
|
92 |
| - output = subprocess.run(f"cd temp/ && java {filename}" ,shell=True , stdout=subprocess.PIPE,stderr=subprocess.PIPE , input=(inputfile.stdout.decode()).encode() , timeout=int(timeout)) |
| 107 | + output = subprocess.run(f"cd temp/ && java {java_file_class_name}" ,shell=True , stdout=subprocess.PIPE,stderr=subprocess.PIPE , input=(inputfile.stdout.decode()).encode() , timeout=int(timeout)) |
93 | 108 | result = output.stdout.decode()
|
94 | 109 |
|
95 | 110 | # if there is any error we will also add the error
|
|
0 commit comments