Commit 41f9600f by willmcgugan

Added Windows support to fsmount command

parent 1d8a0006
...@@ -8,9 +8,16 @@ import os ...@@ -8,9 +8,16 @@ import os
import os.path import os.path
import time import time
platform = platform.system()
class FSMount(Command): class FSMount(Command):
usage = """fsmount [FS] [SYSTEM PATH] if platform == "Windows":
usage = """fsmount [OPTIONS]... [FS] [DRIVE LETTER]
or fsmount -u [DRIVER LETTER]
Mounts a filesystem on a drive letter"""
else:
usage = """fsmount [OPTIONS]... [FS] [SYSTEM PATH]
or fsmount -u [SYSTEM PATH] or fsmount -u [SYSTEM PATH]
Mounts a file system on a system path""" Mounts a file system on a system path"""
...@@ -30,14 +37,24 @@ Mounts a file system on a system path""" ...@@ -30,14 +37,24 @@ Mounts a file system on a system path"""
def do_run(self, options, args): def do_run(self, options, args):
windows = platform == "Windows"
if options.unmount: if options.unmount:
try: try:
mount_path = args[0] mount_path = args[0][:1]
except IndexError: except IndexError:
self.error('Mount path required\n') self.error('Mount path required\n')
return 1 return 1
if windows:
from fs.expose import dokan
mount_path = mount_path[:1].upper()
dokan.unmount(mount_path)
self.output('unmounting %s:' % mount_path, True)
return
else:
from fs.expose import fuse from fs.expose import fuse
fuse.unmount(mount_path) fuse.unmount(mount_path)
self.output('unmounting %s' % mount_path, True)
return return
try: try:
...@@ -49,12 +66,13 @@ Mounts a file system on a system path""" ...@@ -49,12 +66,13 @@ Mounts a file system on a system path"""
try: try:
mount_path = args[1] mount_path = args[1]
except IndexError: except IndexError:
if windows:
mount_path = mount_path[:1].upper()
self.error('Drive letter required')
else:
self.error('Mount path required\n') self.error('Mount path required\n')
return 1 return 1
if platform.system() == 'Windows':
pass
else:
fs, path = self.open_fs(fs_url, create_dir=True) fs, path = self.open_fs(fs_url, create_dir=True)
if path: if path:
if not fs.isdir(path): if not fs.isdir(path):
...@@ -64,9 +82,32 @@ Mounts a file system on a system path""" ...@@ -64,9 +82,32 @@ Mounts a file system on a system path"""
path = '/' path = '/'
if not options.nocache: if not options.nocache:
fs.cache_hint(True) fs.cache_hint(True)
if not os.path.exists(mount_path): if windows and not os.path.exists(mount_path):
os.makedirs(mount_path) os.makedirs(mount_path)
if windows:
from fs.expose import dokan
if len(mount_path) > 1:
self.error('Driver letter should be one character')
return 1
self.output("Mounting %s on %s:" % (fs, mount_path), True)
flags = dokan.DOKAN_OPTION_REMOVABLE
if options.debug:
flags |= dokan.DOKAN_OPTION_DEBUG | dokan.DOKAN_OPTION_STDERR
mp = dokan.mount(fs,
mount_path,
numthreads=5,
foreground=options.foreground,
flags=flags,
volname=str(fs))
else:
from fs.expose import fuse from fs.expose import fuse
self.output("Mounting %s on %s" % (fs, mount_path), True)
if options.foreground: if options.foreground:
fuse_process = fuse.mount(fs, fuse_process = fuse.mount(fs,
mount_path, mount_path,
......
...@@ -209,7 +209,7 @@ class FSOperations(object): ...@@ -209,7 +209,7 @@ class FSOperations(object):
def __init__(self, fs, fsname="Dokan FS", volname="Dokan Volume"): def __init__(self, fs, fsname="Dokan FS", volname="Dokan Volume"):
if libdokan is None: if libdokan is None:
raise OSError("dokan library is not available") raise OSError("dokan library (http://dokan-dev.net/en/) is not available")
self.fs = fs self.fs = fs
self.fsname = fsname self.fsname = fsname
self.volname = volname self.volname = volname
......
...@@ -54,12 +54,12 @@ class TempFS(OSFS): ...@@ -54,12 +54,12 @@ class TempFS(OSFS):
def __unicode__(self): def __unicode__(self):
return u'<TempFS: %s>' % self._temp_dir return u'<TempFS: %s>' % self._temp_dir
# def __setstate__(self, state): def __setstate__(self, state):
# state = super(TempFS, self).__setstate__(state) state = super(TempFS, self).__setstate__(state)
# self._temp_dir = tempfile.mkdtemp(self.identifier or "TempFS", dir=self.temp_dir) self._temp_dir = tempfile.mkdtemp(self.identifier or "TempFS", dir=self.temp_dir)
# super(TempFS, self).__init__(self._temp_dir, super(TempFS, self).__init__(self._temp_dir,
# dir_mode=self.dir_mode, dir_mode=self.dir_mode,
# thread_synchronize=self.thread_synchronize) thread_synchronize=self.thread_synchronize)
def close(self): def close(self):
"""Removes the temporary directory. """Removes the temporary directory.
......
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