Commit 155f51dc by willmcgugan

Added fsmkdir command

parent 99ddb4ec
#!/usr/bin/env python
import sys
from fs.commands.fsmkdir import run
sys.exit(run())
#!/usr/bin/env python
from fs.opener import opener
from fs.commands.runner import Command
import sys
class FSMkdir(Command):
usage = """fsmkdir [PATH]
Make a directory"""
version = "1.0"
def do_run(self, options, args):
for fs_url in args:
fs, path = self.open_fs(fs_url, create=True)
def run():
return FSMkdir().run()
if __name__ == "__main__":
sys.exit(run())
\ No newline at end of file
...@@ -26,15 +26,14 @@ Serves the contents of PATH with one of a number of methods""" ...@@ -26,15 +26,14 @@ Serves the contents of PATH with one of a number of methods"""
try: try:
fs_url = args[0] fs_url = args[0]
except IndexError: except IndexError:
self.error('FS path required\n') fs_url = './'
return 1
fs, path = self.open_fs(fs_url) fs, path = self.open_fs(fs_url)
if path and fs.isdir(path):
fs, path = fs.opendir(path), '/'
port = options.port port = options.port
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:
...@@ -63,6 +62,13 @@ Serves the contents of PATH with one of a number of methods""" ...@@ -63,6 +62,13 @@ Serves the contents of PATH with one of a number of methods"""
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:
if e.errno == 13:
self.error('Permission denied\n')
return 1
else:
self.error(e.strerror + '\n')
return 1
def run(): def run():
return FSServe().run() return FSServe().run()
......
...@@ -226,8 +226,6 @@ class Command(object): ...@@ -226,8 +226,6 @@ class Command(object):
# pass # pass
except SystemExit: except SystemExit:
return 0 return 0
except IOError:
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
......
...@@ -131,7 +131,6 @@ def serve_fs(fs, address='', port=8000): ...@@ -131,7 +131,6 @@ def serve_fs(fs, address='', port=8000):
#class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): #class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
# pass # pass
httpd = SocketServer.TCPServer((address, port), Handler, bind_and_activate=False) httpd = SocketServer.TCPServer((address, port), Handler, bind_and_activate=False)
#httpd = ThreadedTCPServer((address, port), Handler, bind_and_activate=False) #httpd = ThreadedTCPServer((address, port), Handler, bind_and_activate=False)
httpd.allow_reuse_address = True httpd.allow_reuse_address = True
...@@ -139,9 +138,7 @@ def serve_fs(fs, address='', port=8000): ...@@ -139,9 +138,7 @@ def serve_fs(fs, address='', port=8000):
httpd.server_activate() httpd.server_activate()
server_thread = threading.Thread(target=httpd.serve_forever) server_thread = threading.Thread(target=httpd.serve_forever)
server_thread.setDaemon(True)
server_thread.start() server_thread.start()
try: try:
while True: while True:
time.sleep(0.1) time.sleep(0.1)
......
...@@ -133,7 +133,6 @@ class OpenerRegistry(object): ...@@ -133,7 +133,6 @@ class OpenerRegistry(object):
return fs, fs_path return fs, fs_path
def parse_credentials(self, url): def parse_credentials(self, url):
username = None username = None
...@@ -154,7 +153,7 @@ class OpenerRegistry(object): ...@@ -154,7 +153,7 @@ class OpenerRegistry(object):
return fs_name, None return fs_name, None
def open(self, fs_url, mode='r'): def open(self, fs_url, mode='r'):
writeable = 'w' in mode or 'a' in mode writeable = 'w' in mode or 'a' in mode or '+' in mode
fs, path = self.parse(fs_url, writeable=writeable) fs, path = self.parse(fs_url, writeable=writeable)
file_object = fs.open(path, mode) file_object = fs.open(path, mode)
return file_object return file_object
...@@ -179,12 +178,11 @@ class OSFSOpener(Opener): ...@@ -179,12 +178,11 @@ class OSFSOpener(Opener):
@classmethod @classmethod
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create): def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create):
from fs.osfs import OSFS from fs.osfs import OSFS
username, password, fs_path = registry.parse_credentials(fs_path)
path = _expand_syspath(fs_path) path = _expand_syspath(fs_path)
if create: if create:
sys.makedirs(fs_path) from fs.osfs import _os_makedirs
_os_makedirs(fs_path)
if os.path.isdir(path): if os.path.isdir(path):
osfs = OSFS(path) osfs = OSFS(path)
filepath = None filepath = None
...@@ -236,6 +234,7 @@ class ZipOpener(Opener): ...@@ -236,6 +234,7 @@ 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, None return zipfs, None
class RPCOpener(Opener): class RPCOpener(Opener):
names = ['rpc'] names = ['rpc']
...@@ -255,6 +254,7 @@ class RPCOpener(Opener): ...@@ -255,6 +254,7 @@ class RPCOpener(Opener):
return rpcfs, path or None return rpcfs, path or None
class FTPOpener(Opener): class FTPOpener(Opener):
names = ['ftp'] names = ['ftp']
...@@ -320,9 +320,6 @@ class SFTPOpener(Opener): ...@@ -320,9 +320,6 @@ class SFTPOpener(Opener):
else: else:
host = (addr, port) host = (addr, port)
#if not username or not password:
# raise OpenerError('SFTP requires authentication')
if create: if create:
sftpfs = SFTPFS(host, root_path='/', **credentials) sftpfs = SFTPFS(host, root_path='/', **credentials)
if not sftpfs._transport.is_authenticated(): if not sftpfs._transport.is_authenticated():
...@@ -350,6 +347,7 @@ class MemOpener(Opener): ...@@ -350,6 +347,7 @@ class MemOpener(Opener):
memfs = memfs.makeopendir(fs_path) memfs = memfs.makeopendir(fs_path)
return memfs, None return memfs, None
class DebugOpener(Opener): class DebugOpener(Opener):
names = ['debug'] names = ['debug']
...@@ -366,13 +364,14 @@ class DebugOpener(Opener): ...@@ -366,13 +364,14 @@ class DebugOpener(Opener):
from fs.tempfs import TempFS from fs.tempfs import TempFS
return DebugFS(TempFS(), identifier=fs_name_params, verbose=False), None return DebugFS(TempFS(), identifier=fs_name_params, verbose=False), None
class TempOpener(Opener): class TempOpener(Opener):
names = ['temp'] names = ['temp']
@classmethod @classmethod
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create): def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create):
from fs.tempfs import TempFS from fs.tempfs import TempFS
return TempFS(identifier=fs_name_params, temp_dir=fs_path), None return TempFS(identifier=fs_name_params, temp_dir=fs_path, create=create), None
opener = OpenerRegistry([OSFSOpener, opener = OpenerRegistry([OSFSOpener,
......
...@@ -11,7 +11,8 @@ COMMANDS = ['fscat', ...@@ -11,7 +11,8 @@ COMMANDS = ['fscat',
'fscp', 'fscp',
'fsrm', 'fsrm',
'fsserve', 'fsserve',
'fstree'] 'fstree',
'fsmkdir']
classifiers = [ classifiers = [
......
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