bin/medit
#!/usr/bin/python # medit, the metaeditor import re import os import sys import cgi sys.path.append("/hackiki/lib/python") from hackikilogin import loginInfo # Get the file fn = "" if len(sys.argv) == 1 or not sys.argv[1]: fn = "bin/index" else: fn = '/'.join(sys.argv[1:]) # And the template file template = "Failed to open templates/edit.html" try: f = open("templates/edit.html", "r") template = f.read() finally: f.close() message = "" # Perhaps write data if ("REQUEST_chebang" in os.environ) and ("REQUEST_cont" in os.environ): try: f = open(fn,"w") cont = re.sub(r'\r', '', os.environ["REQUEST_cont"]) f.write("%s\n%s"%(os.environ["REQUEST_chebang"], cont)) finally: f.close() os.chmod(fn, 0755) message = "<br/>File %s written.<hr/>" % (fn) # Now read it in chebang = "" text = "" if os.path.isfile(fn): try: f = open(fn,"r") text = f.read() finally: f.close() else: chebang = "#!/usr/bin/env .wiki" if text[:3] == '#!/': nl = text.find('\n') chebang = text[:nl] text = text[nl+1:] # If this isn't a supported type, send it to the regular editor if chebang != "#!/usr/bin/env .wiki": print "headers\nLocation: %s/edit/%s\n\n" % (os.environ["HACKIKI_BASE"], fn) exit(0) # Make them printable name = os.path.basename(fn) chebangh = cgi.escape(chebang) texth = cgi.escape(text) # get the login info login = loginInfo() print "headers\nX-Hackiki-Cached: No\n\n" print template % { 'hackikibase': os.environ["HACKIKI_BASE"], 'login': login, 'name': name, 'fn': fn, 'message': message, 'chebang': chebang, 'chebangh': chebangh, 'text': text, 'texth': texth }
Mode:
View this page
Wiki index