#encoding=utf-8
import web
import subprocess
import sys
urls = (
    '/', 'Index',
    '/commit', 'Commit',
    '/success','success',
)

render = web.template.render('templates')
app = web.application(urls, globals())

class Index:
    def GET(self):
        return render.login2()
		
class success:
    def GET(self):
	    return "success"

class Commit:
    def POST(self):
        """x = web.input(myfile={})
        web.debug(x['myfile'].filename) 
        #web.debug(x['myfile'].value) 
        #web.debug(x['myfile'].file.read()) 
        raise web.seeother('/')"""
        x = web.input(mytext={})
        if 'mytext' in x:
            print x.mytext
            orgpath = x.mytext+"/"+x.mytext+".pptx"
            print orgpath
            """res = oss.get_object_to_file(bucketname, "ppt/1.pptx", "C:\\11.pptx", headers)
            if (res.status / 100) == 2:
                print "get_object_to_file OK"
            else:
                print "get_object_to_file ERROR"
				"""
        #x = web.input()
        #filepath = "C:\\"+(str)x
		#print filepath
        """filedir = 'E:\\pythonText\\test' # change this to the directory you want to store the file in.
        if 'myfile' in x: # to check if the file-object is created
            filepath=x.myfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones.
            filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension)
            fout = open(filedir +'/'+ filename,'wb') # creates the file where the uploaded file should be stored
            wholepath = filedir+'\\'+filename
            fout.write(x.myfile.file.read()) # writes the uploaded file to the newly created file.
            fout.close() # closes the file, upload complete.
            returnCode = subprocess.call("python pptChange.py %s" %wholepath)
            #returnCode = subprocess.call("python pptChange.py C:\\FindLost.pptx")
            print 'returncode:', returnCode
			"""
        raise web.seeother('/success')
		#return "save successful"

if __name__ == "__main__":
    app.run()