-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyGenerator.py
executable file
·122 lines (101 loc) · 2.77 KB
/
pyGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python
import sys
JavaData = {
'Lang_id' : 'JAVA',
'Source Extension':'.java',
'Single-Line Comment' : '//',
'Multi-Line Comment' : ['/*','*/'],
'Libraries' : [],
'Constants' : []
}
CPPData = {
'Lang_id' : 'C++11',
'Single-Line Comment' : '//',
'Multi-Line Comment' : ['/*','*/'],
'Source Extension' : '.cpp',
'Library Get' : '#include',
'Constant Def' : '#define',
'Functions' : {
'Main' : 'int main(int argc, char* argv[])'
},
'Libraries' : ['<iostream>','<vector>','<cmath>','<fstream>','<deque>','<string>','<algorithm>','<cstdio>','<cstdlib>','<ctime>'],
'Constants' : [['BUFFER','1024'],['PI','3.14159265359']]
}
PythonData = {
}
FortranData = {
}
PascalData = {
}
class Impresion(object):
def generateUserData(self):
file = open(self.filename,'a')
file.write(self.data['Multi-Line Comment'][0]+'\n')
file.write('ID: '+self.id+'\n')
file.write('PROG: '+self.prog+'\n')
file.write('LANG: '+self.data['Lang_id']+'\n')
file.write(self.data['Multi-Line Comment'][1]+'\n')
file.close()
def generateLibraries(self):
file = open(self.filename,'a')
file.write(self.data['Single-Line Comment']+' Libraries\n')
for library in self.data['Libraries']:
file.write(self.data['Library Get']+' '+library+'\n')
file.close()
def generateConstants(self):
pass
def generatefile(self):
# Fill USACO user Data
self.generateUserData()
# Generate Libraries
self.generateLibraries()
# Generate Constants
self.generateConstants()
def __init__(self, idprog, prog, filename,lang):
self.id = idprog
self.prog = prog
if (
lang == 'c++' or lang == 'C++' or
lang == 'cpp' or lang == 'CPP' or
lang == 'c' or lang == 'C' or
lang == 'c++11' or lang == 'C++11' or
lang == 'cpp11' or lang == 'CPP11'
):
self.data = CPPData
elif (
lang == 'java' or lang == 'JAVA' or
lang == 'Java'
):
self.data = JavaData
elif (
lang == 'Python' or lang == 'PYTHON' or
lang == 'python'
):
self.data = PythonData
elif (
lang == 'Fortran' or lang == 'fortran'
):
self.data = FortranData
elif (
lang == 'Pascal' or lang == 'PASCAL'
):
self.data = PascalData
else:
raise 'Language error.'
self.filename = filename+self.data['Source Extension']
def main(argv):
if len(argv) == 4:
print 'ID: ' + argv[0]
print 'PROG: ' + argv[1]
print 'LANGUAGE: ' + argv[3]
print 'Output code file: ' + argv[2]
file = Impresion(argv[0],argv[1],argv[2],argv[3])
file.generatefile()
else:
print 'Error: Not enough arguments!'
print 'Usage: (program) ID PROGRAM FILENAME'
print 'ID - The ID USACO Training Gate gave you.'
print 'PROGRAM - The Program you\'re solving.'
print 'FILENAME - The Filename you wish to be generated WITHOUT EXTENSION.'
if __name__ == '__main__':
main(sys.argv[1:])