Commit 8b582582 by btimby

I am about to check in the addition of 'ftp' protocol, I could not help myself…

I am about to check in the addition of 'ftp' protocol, I could not help myself but to clean the extra whitespace.
I committed this first so as not to muddy the waters of my imminent commit. This is ONLY whitespace changes.
parent 5ab847e8
...@@ -8,10 +8,10 @@ from fs.utils import print_fs ...@@ -8,10 +8,10 @@ from fs.utils import print_fs
class FSServe(Command): class FSServe(Command):
usage = """fsserve [OPTION]... [PATH] usage = """fsserve [OPTION]... [PATH]
Serves the contents of PATH with one of a number of methods""" Serves the contents of PATH with one of a number of methods"""
def get_optparse(self): def get_optparse(self):
optparse = super(FSServe, self).get_optparse() optparse = super(FSServe, self).get_optparse()
optparse.add_option('-t', '--type', dest='type', type="string", default="http", optparse.add_option('-t', '--type', dest='type', type="string", default="http",
...@@ -21,42 +21,42 @@ Serves the contents of PATH with one of a number of methods""" ...@@ -21,42 +21,42 @@ Serves the contents of PATH with one of a number of methods"""
optparse.add_option('-p', '--port', dest='port', type="int", optparse.add_option('-p', '--port', dest='port', type="int",
help="Port number", metavar="") help="Port number", metavar="")
return optparse return optparse
def do_run(self, options, args): def do_run(self, options, args):
try: try:
fs_url = args[0] fs_url = args[0]
except IndexError: except IndexError:
fs_url = './' fs_url = './'
fs, path = self.open_fs(fs_url) fs, path = self.open_fs(fs_url)
if fs.isdir(path): if fs.isdir(path):
fs = fs.opendir(path) fs = fs.opendir(path)
path = '/' path = '/'
self.output("Opened %s\n" % fs, verbose=True) self.output("Opened %s\n" % fs, verbose=True)
port = options.port port = options.port
try: try:
if options.type == 'http': if options.type == 'http':
from fs.expose.http import serve_fs from fs.expose.http import serve_fs
if port is None: if port is None:
port = 80 port = 80
self.output("Starting http server on %s:%i\n" % (options.addr, port), verbose=True) self.output("Starting http server on %s:%i\n" % (options.addr, port), verbose=True)
serve_fs(fs, options.addr, port) serve_fs(fs, options.addr, port)
elif options.type == 'rpc': elif options.type == 'rpc':
from fs.expose.xmlrpc import RPCFSServer from fs.expose.xmlrpc import RPCFSServer
if port is None: if port is None:
port = 80 port = 80
s = RPCFSServer(fs, (options.addr, port)) s = RPCFSServer(fs, (options.addr, port))
self.output("Starting rpc server on %s:%i\n" % (options.addr, port), verbose=True) self.output("Starting rpc server on %s:%i\n" % (options.addr, port), verbose=True)
s.serve_forever() s.serve_forever()
elif options.type == 'sftp': elif options.type == 'sftp':
from fs.expose.sftp import BaseSFTPServer from fs.expose.sftp import BaseSFTPServer
import logging import logging
log = logging.getLogger('paramiko') log = logging.getLogger('paramiko')
...@@ -67,7 +67,7 @@ Serves the contents of PATH with one of a number of methods""" ...@@ -67,7 +67,7 @@ Serves the contents of PATH with one of a number of methods"""
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
log.addHandler(ch) log.addHandler(ch)
if port is None: if port is None:
port = 22 port = 22
server = BaseSFTPServer((options.addr, port), fs) server = BaseSFTPServer((options.addr, port), fs)
...@@ -78,20 +78,20 @@ Serves the contents of PATH with one of a number of methods""" ...@@ -78,20 +78,20 @@ Serves the contents of PATH with one of a number of methods"""
pass pass
finally: finally:
server.server_close() server.server_close()
else: else:
self.error("Server type '%s' not recognised\n" % options.type) self.error("Server type '%s' not recognised\n" % options.type)
except IOError, e: except IOError, e:
if e.errno == 13: if e.errno == 13:
self.error('Permission denied\n') self.error('Permission denied\n')
return 1 return 1
else: else:
self.error(e.strerror + '\n') self.error(e.strerror + '\n')
return 1 return 1
def run(): def run():
return FSServe().run() return FSServe().run()
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(run()) sys.exit(run())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment