示例#1
0
    def __init__(self):
        self.memory = MemoryFS()

        ## WINDOWS
        if sys.platform == 'win32': 
            from fs.expose import dokan
            letter = random.choice(string.letters) + ":\\"
            
            while os.path.exists(letter):
                letter = random.choice(string.letters) + ":\\"

            self.mount_directory = letter
            if not os.path.exists(letter):
                dokan.mount(self.memory, letter)

        ## LINUX
        else:
            self.mount_directory = os.path.join(os.path.expanduser('~')) +'/mtdecoded/'
示例#2
0
 def setUp(self):
     self.temp_fs = TempFS()
     self.drive = "K"
     while os.path.exists(self.drive+":\\") and self.drive <= "Z":
         self.drive = chr(ord(self.drive) + 1)
     if self.drive > "Z":
         raise RuntimeError("no free drive letters")
     fs_to_mount = OSFS(self.temp_fs.getsyspath("/"))
     self.mount_proc = dokan.mount(fs_to_mount,self.drive)#,flags=dokan.DOKAN_OPTION_DEBUG|dokan.DOKAN_OPTION_STDERR,numthreads=1)
     self.fs = OSFS(self.mount_proc.path)
示例#3
0
 def setUp(self):
     self.temp_fs = TempFS()
     self.drive = "K"
     while os.path.exists(self.drive+":\\") and self.drive <= "Z":
         self.drive = chr(ord(self.drive) + 1)
     if self.drive > "Z":
         raise RuntimeError("no free drive letters")
     fs_to_mount = OSFS(self.temp_fs.getsyspath("/"))
     self.mount_proc = dokan.mount(fs_to_mount,self.drive)#,flags=dokan.DOKAN_OPTION_DEBUG|dokan.DOKAN_OPTION_STDERR,numthreads=1)
     self.fs = OSFS(self.mount_proc.path)
示例#4
0
	def mount(self, mountpoint):
		"""Mount this Directory to a mount point on the actual filesystem.
		
		mountpoint -- The point to mount the Directory on (on Windows, this will be a drive letter).
		"""
		
		global fs_available
		
		if fs_available == False:
			raise DependencyException("Could not mount the directory because the 'fs' module was not found.")
		
		fs = TahoeLAFS(self.uri, webapi=self.filesystem.url)
		
		try:
			return fuse.mount(fs, mountpoint)
		except OSError:
			try:
				return dokan.mount(fs, mountpoint)
			except OSError:
				raise DependencyException("Could not mount the directory because both the FUSE and dokan libraries are unavailable.")
			except RuntimeError, e:
				raise MountException("Could not mount the directory because a dokan error was encountered: %s" % e.message)
示例#5
0
    def do_run(self, options, args):
        
        windows = platform == "Windows"
                
        if options.unmount:

            if windows:
                
                try:                
                    mount_path = args[0][:1]
                except IndexError:
                    self.error('Driver letter required\n')
                    return 1
                
                from fs.expose import dokan
                mount_path = mount_path[:1].upper()
                self.output('unmounting %s:...\n' % mount_path, True)
                dokan.unmount(mount_path)                
                return
            
            else:                
                try:                
                    mount_path = args[0]
                except IndexError:
                    self.error(self.usage + '\n')
                    return 1                                
                
                from fs.expose import fuse
                self.output('unmounting %s...\n' % mount_path, True)
                fuse.unmount(mount_path)                
                return
        
        try:
            fs_url = args[0]
        except IndexError:
            self.error(self.usage + '\n')
            return 1
        
        try:                
            mount_path = args[1]
        except IndexError:
            if windows:
                mount_path = mount_path[:1].upper()
                self.error(self.usage + '\n')
            else:
                self.error(self.usage + '\n')
            return 1                    
            
        fs, path = self.open_fs(fs_url, create_dir=True)
        if path:
            if not fs.isdir(path):
                self.error('%s is not a directory on %s' % (fs_url. fs))
                return 1
            fs = fs.opendir(path)
            path = '/'
        if not options.nocache:
            fs.cache_hint(True)
                
        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:\n" % (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:            
            if not os.path.exists(mount_path):
                try:
                    os.makedirs(mount_path)
                except:
                    pass
            
            from fs.expose import fuse
            self.output("Mounting %s on %s\n" % (fs, mount_path), True)
            
            if options.foreground:
                fuse_process = fuse.mount(fs,
                                          mount_path,                                          
                                          foreground=True)                                                    
            else:
                if not os.fork():
                    mp = fuse.mount(fs,
                                    mount_path,
                                    foreground=True)
                else:
                    fs.close = lambda:None
示例#6
0
import time
from fs.memoryfs import MemoryFS
from fs.expose import dokan
fs = MemoryFS()

mp = dokan.mount(fs, 'Q:\\', fsname='TestFS', volname='TestDrive')
print (mp.path)

try:
    while 1:
        time.sleep(1)
except:

    mp.unmount()
mp.unmount()
示例#7
0
    def do_run(self, options, args):

        windows = platform == "Windows"

        if options.unmount:

            if windows:

                try:
                    mount_path = args[0][:1]
                except IndexError:
                    self.error('Driver letter required\n')
                    return 1

                from fs.expose import dokan
                mount_path = mount_path[:1].upper()
                self.output('unmounting %s:...\n' % mount_path, True)
                dokan.unmount(mount_path)
                return

            else:
                try:
                    mount_path = args[0]
                except IndexError:
                    self.error(self.usage + '\n')
                    return 1

                from fs.expose import fuse
                self.output('unmounting %s...\n' % mount_path, True)
                fuse.unmount(mount_path)
                return

        try:
            fs_url = args[0]
        except IndexError:
            self.error(self.usage + '\n')
            return 1

        try:
            mount_path = args[1]
        except IndexError:
            if windows:
                mount_path = mount_path[:1].upper()
                self.error(self.usage + '\n')
            else:
                self.error(self.usage + '\n')
            return 1

        fs, path = self.open_fs(fs_url, create_dir=True)
        if path:
            if not fs.isdir(path):
                self.error('%s is not a directory on %s' % (fs_url, fs))
                return 1
            fs = fs.opendir(path)
            path = '/'
        if not options.nocache:
            fs.cache_hint(True)

        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:\n" % (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:
            if not os.path.exists(mount_path):
                try:
                    os.makedirs(mount_path)
                except:
                    pass

            from fs.expose import fuse
            self.output("Mounting %s on %s\n" % (fs, mount_path), True)

            if options.foreground:
                fuse_process = fuse.mount(fs, mount_path, foreground=True)
            else:
                if not os.fork():
                    mp = fuse.mount(fs, mount_path, foreground=True)
                else:
                    fs.close = lambda: None
示例#8
0
def create_virtual_filesystem(local, mount):
    repo_fs = OSFS(local)
    mount_point = dokan.mount(repo_fs, mount)
    return mount_point