Commit f5c7b0f0 by willmcgugan

Opener fixes

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