import sys
import os
# get a file
# search for classes
# get the class name
#create a directory with the file name
#create a new file with the class names and content
def createdir(dirname):
os.mkdir(dirname)
def main():
args = sys.argv
filename = args[1]
dirname = filename[0:-3]
print "file name:",dirname
if not os.path.isdir(dirname):
createdir(dirname)
f = open(filename,'r')
class_started = False
newfile =False
for text in f.readlines():
print "reading lines"
if text.startswith('class') == True:
print "class found"
if newfile: newfile.close()
class_started = True
newfile = open(''+dirname+"//"+text.replace('class ','').replace('(object):\n','')+".py",'w')
print newfile
if newfile:
print "writing file"
newfile.write(text)
if newfile:
newfile.close()
if __name__=="__main__":
main()
No comments:
Post a Comment