Commit f5c7b0f0 by willmcgugan

Opener fixes

parent 8ff1c9b1
......@@ -6,6 +6,11 @@ import sys
class FSCat(Command):
usage = """fscat [OPTION]... [FILE]...
Concetanate FILE(s)"""
version = "1.0"
def do_run(self, options, args):
count = 0
for fs, path, is_dir in self.get_resources(args):
......
......@@ -47,6 +47,9 @@ class FSCopy(Command):
DIR, FILE = 0, 1
usage = """fscp [OPTION]... [SOURCE]... [DESTINATION]
Copy SOURCE to DESTINATION"""
def get_action(self):
return copyfile
......
......@@ -8,6 +8,9 @@ from datetime import datetime
class FSInfo(Command):
usage = """fsinfo [OPTION]... [PATH]
Display information regarding an FS resource"""
def get_optparse(self):
optparse = super(FSInfo, self).get_optparse()
optparse.add_option('-k', '--key', dest='keys', action='append', default=[],
......
......@@ -8,6 +8,10 @@ import sys
class FSList(Command):
usage = """fsls [OPTIONS]... [PATH]
List contents of [PATH]"""
def get_optparse(self):
optparse = super(FSList, self).get_optparse()
optparse.add_option('-u', '--full', dest='fullpath', action="store_true", default=False,
......
......@@ -3,6 +3,10 @@ from fs.commands import fscp
import sys
class FSMove(fscp.FSCopy):
usage = """fsmv [OPTION]... [SOURCE] [DESTINATION]
Move files from SOURCE to DESTINATION"""
def get_action(self):
return movefile
......
......@@ -7,6 +7,9 @@ import sys
class FSrm(Command):
usage = """fsrm [OPTION]... [PATH]
Remove a file or directory at PATH"""
def get_optparse(self):
optparse = super(FSrm, self).get_optparse()
optparse.add_option('-f', '--force', dest='force', action='store_true', default=False,
......
......@@ -8,6 +8,9 @@ from fs.utils import print_fs
class FSServe(Command):
"""fsserve [OPTION]... [PATH]
Serves the contents of PATH with one of a number of methods"""
def get_optparse(self):
optparse = super(FSServe, self).get_optparse()
optparse.add_option('-t', '--type', dest='type', type="string", default="http",
......@@ -23,7 +26,7 @@ class FSServe(Command):
try:
fs_url = args[0]
except IndexError:
self.error('FS required\n')
self.error('FS path required\n')
return 1
fs, path = self.open_fs(fs_url)
......@@ -42,7 +45,7 @@ class FSServe(Command):
from fs.expose.xmlrpc import RPCFSServer
if port is None:
port = 80
s = RPCFSServer(fs, (options.addr, options.port))
s = RPCFSServer(fs, (options.addr, port))
s.serve_forever()
elif options.type == 'sftp':
......
......@@ -8,6 +8,9 @@ from fs.utils import print_fs
class FSTree(Command):
usage = """fstree [OPTION]... [PATH]
Recursively display the contents of PATH in an ascii tree"""
def get_optparse(self):
optparse = super(FSTree, self).get_optparse()
optparse.add_option('-d', '--depth', dest='depth', type="int", default=5,
......
......@@ -42,9 +42,10 @@ def _unicode(text):
class Command(object):
usage = ''
version = ''
def __init__(self, usage='', version=''):
self.usage = usage
self.version = version
self.output_file = sys.stdout
self.error_file = sys.stderr
self.encoding = getattr(self.output_file, 'encoding', 'utf-8') or 'utf-8'
......@@ -230,9 +231,9 @@ class Command(object):
return 0
#except IOError:
# return 1
except Exception, e:
self.error(self.wrap_error('Internal Error - %s\n' % unicode(e)))
return 1
#except Exception, e:
# self.error(self.wrap_error('Internal Error - %s\n' % unicode(e)))
# return 1
......
......@@ -65,8 +65,8 @@ class FSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
try:
info = self._fs.getinfo(path)
f = self._fs.open(path, 'r')
except FSError:
self.send_error(404, "File not found")
except FSError, e:
self.send_error(404, str(e))
return None
self.send_response(200)
self.send_header("Content-type", ctype)
......
......@@ -76,13 +76,15 @@ class OpenerRegistry(object):
fs_name, paren_url, fs_url, path = self.split_segments(fs_url)
fs_url = fs_url or paren_url
if fs_name is None and path is None:
fs_url = os.path.expanduser(os.path.expandvars(fs_url))
fs_url = os.path.normpath(os.path.abspath(fs_url))
fs_url, path = pathsplit(fs_url)
if not fs_url:
fs_url = '/'
fs_name = fs_name or self.default_opener
fs_url = fs_url or paren_url
if fs_name is None:
fs_name = fs_default_name
......@@ -190,6 +192,17 @@ class ZipOpener(Opener):
zipfs = ZipFS(zip_file, mode=mode, allow_zip_64=allow_zip_64)
return zipfs
class RPCOpener(Opener):
names = ['rpc']
@classmethod
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create):
from fs.rpcfs import RPCFS
username, password, fs_path = registry.parse_credentials(fs_path)
if not fs_path.startswith('http://'):
fs_path = 'http://' + fs_path
rpcfs = RPCFS(fs_path)
return rpcfs
class FTPOpener(Opener):
names = ['ftp']
......@@ -287,6 +300,7 @@ class TempOpener(Opener):
opener = OpenerRegistry([OSFSOpener,
ZipOpener,
RPCOpener,
FTPOpener,
SFTPOpener,
MemOpener,
......@@ -297,6 +311,7 @@ opener = OpenerRegistry([OSFSOpener,
def main():
fs, path = opener.parse('galleries.zip')
print fs, path
if __name__ == "__main__":
......
......@@ -261,5 +261,6 @@ class ZipFS(FS):
if 'date_time' in zinfo:
info['created_time'] = datetime.datetime(*zinfo['date_time'])
info.update(zinfo)
if 'FileHeader' in info:
del info['FileHeader']
return info
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