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"""
try:
fs_url = args[0]
except IndexError:
self.error('FS path required\n')
return 1
fs_url = './'
fs, path = self.open_fs(fs_url)
if path and fs.isdir(path):
fs, path = fs.opendir(path), '/'
port = options.port
try:
if options.type == 'http':
from fs.expose.http import serve_fs
if port is None:
......@@ -63,6 +62,13 @@ Serves the contents of PATH with one of a number of methods"""
else:
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():
return FSServe().run()
......
......@@ -226,8 +226,6 @@ class Command(object):
# pass
except SystemExit:
return 0
except IOError:
return 1
except Exception, e:
self.error(self.wrap_error('Internal Error - %s\n' % unicode(e)))
return 1
......
......@@ -131,7 +131,6 @@ def serve_fs(fs, address='', port=8000):
#class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
# pass
httpd = SocketServer.TCPServer((address, port), Handler, bind_and_activate=False)
#httpd = ThreadedTCPServer((address, port), Handler, bind_and_activate=False)
httpd.allow_reuse_address = True
......@@ -139,9 +138,7 @@ def serve_fs(fs, address='', port=8000):
httpd.server_activate()
server_thread = threading.Thread(target=httpd.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
try:
while True:
time.sleep(0.1)
......
......@@ -133,7 +133,6 @@ class OpenerRegistry(object):
return fs, fs_path
def parse_credentials(self, url):
username = None
......@@ -154,7 +153,7 @@ class OpenerRegistry(object):
return fs_name, None
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)
file_object = fs.open(path, mode)
return file_object
......@@ -179,12 +178,11 @@ class OSFSOpener(Opener):
@classmethod
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create):
from fs.osfs import OSFS
username, password, fs_path = registry.parse_credentials(fs_path)
path = _expand_syspath(fs_path)
if create:
sys.makedirs(fs_path)
from fs.osfs import _os_makedirs
_os_makedirs(fs_path)
if os.path.isdir(path):
osfs = OSFS(path)
filepath = None
......@@ -236,6 +234,7 @@ class ZipOpener(Opener):
zipfs = ZipFS(zip_file, mode=mode, allow_zip_64=allow_zip_64)
return zipfs, None
class RPCOpener(Opener):
names = ['rpc']
......@@ -255,6 +254,7 @@ class RPCOpener(Opener):
return rpcfs, path or None
class FTPOpener(Opener):
names = ['ftp']
......@@ -320,9 +320,6 @@ class SFTPOpener(Opener):
else:
host = (addr, port)
#if not username or not password:
# raise OpenerError('SFTP requires authentication')
if create:
sftpfs = SFTPFS(host, root_path='/', **credentials)
if not sftpfs._transport.is_authenticated():
......@@ -350,6 +347,7 @@ class MemOpener(Opener):
memfs = memfs.makeopendir(fs_path)
return memfs, None
class DebugOpener(Opener):
names = ['debug']
......@@ -366,13 +364,14 @@ class DebugOpener(Opener):
from fs.tempfs import TempFS
return DebugFS(TempFS(), identifier=fs_name_params, verbose=False), None
class TempOpener(Opener):
names = ['temp']
@classmethod
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create):
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,
......
......@@ -11,7 +11,8 @@ COMMANDS = ['fscat',
'fscp',
'fsrm',
'fsserve',
'fstree']
'fstree',
'fsmkdir']
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