Hello,
I had some spare time recently, so I tried to re-implement the Ruby Server
in Python:
#!/usr/bin/python3
from http.server import SimpleHTTPRequestHandler, HTTPServer
import datetime, shutil, os
def makebackup(src):
(srcpath, srcfile) = os.path.split(src)
tstamp=datetime.datetime.now().strftime("%Y%m%d%H%M%S")
dstpath = os.path.join(srcpath,'twBackups')
if not os.path.exists(dstpath):
os.mkdir(dstpath)
shutil.copyfile(src, os.path.join(dstpath, srcfile+'.'+tstamp))
class ExtendedHandler(SimpleHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200, 'OK')
self.send_header('allow','GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav'
)
self.send_header('x-api-access-type','file')
self.send_header('dav','tw5/put')
self.end_headers()
def do_PUT(self):
length = int(self.headers['Content-Length'])
path = self.translate_path(self.path)
makebackup(path)
with open(path, "wb") as dst:
dst.write(self.rfile.read(length))
self.send_response(200, 'OK')
self.send_header('Content-Type', 'text/html')
self.end_headers()
os.chdir(os.path.dirname(os.path.abspath(__file__)))
HTTPServer(('localhost',8080),ExtendedHandler).serve_forever()
It works for me :-)
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/f761a832-cc46-4eda-a198-2ee9e31a4ea5%40googlegroups.com.