Пример #1
0
 def setUp(self):
     self.temp_fs = TempFS()            
     self.temp_fs.makedir("root")
     self.temp_fs.makedir("mount")
     self.mounted_fs = self.temp_fs.opendir("root")
     self.mount_point = self.temp_fs.getsyspath("mount")
     self.fs = OSFS(self.temp_fs.getsyspath("mount"))
     self.mount_proc = fuse.mount(self.mounted_fs,self.mount_point)
Пример #2
0
 def setUp(self):
     self.temp_fs = TempFS()
     self.temp_fs.makedir("root")
     self.temp_fs.makedir("mount")
     self.mounted_fs = self.temp_fs.opendir("root")
     self.mount_point = self.temp_fs.getsyspath("mount")
     self.fs = OSFS(self.temp_fs.getsyspath("mount"))
     self.mount_proc = fuse.mount(self.mounted_fs, self.mount_point)
Пример #3
0
def mount_ftp(ftpaddress, mountpoint, login=None, password=None):
"""Mount the FTP space "ftpaddress" into "mountpoint", using login and password if they're provided.

Keyword arguments:
ftpaddress -- the address of the FTP space
mountpoint -- the path of the mountpoint
login -- the login of the user account (optionnal)
passwd -- the password of the user account (optionnal)

If the connection & mount are successful, spawn a new thread to handle the mount"""
    try:
        ftp_fs = ftpfs.FTPFS(ftpaddress, user=login, passwd=password)
    except RemoteConnectionError:
        logging.error( 'Unable to connect: %s is not reachable' % ftpaddress)
        sys.exit(1)
    except PermissionDeniedError:
        logging.error( 'Unable to connect: credentials are not correct')
        sys.exit(1)
    logging.info('Connected to %s' % ftpaddress)
    logging.info('Mounting in %s ... ' % mountpoint)
    fs_thread = fuse.mount(ftp_fs, mountpoint)
Пример #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
from fs.memoryfs import MemoryFS
from fs.expose import fuse
from os import system
mem_fs = MemoryFS()
mnt_pt = fuse.mount("mem_fs", "/home/todor/workspace/myRam/tst", True, True, True)
system("unzip sublime.zip -d /home/todor/workspace/myRam/tst/")
system("chown -R todor /home/todor/workspace/myRam/tst")
system("chmod -r 775 /home/todor/workspace/myRam/tst")
system("./home/todor/workspace/myRam/tst/sublime_text")
Пример #7
0
def start(path, mountpoint):
    myfs = SRFPFSDsStorage(path)
    from fs.expose import fuse
    fuse.mount(myfs, mountpoint.encode('utf8'), foreground=True)
Пример #8
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
Пример #9
0
def start(path, mountpoint):
    myfs = SRFPFSDsStorage(path)
    from fs.expose import fuse
    fuse.mount(myfs, mountpoint.encode('utf8'), foreground=True)
Пример #10
0
import time
from fs.memoryfs import MemoryFS
from fs.expose import fuse
fs = MemoryFS()

mp = fuse.mount(fs, '/home/merlink/fusemount/'.encode())
print (mp.path)

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

    mp.unmount()
mp.unmount()
Пример #11
0
	if opts.bg:
		sys.stdout.flush()
		sys.stderr.flush()
		_out, _err = os.dup(sys.stdout.fileno()), os.dup(sys.stderr.fileno())
		temp_fd, temp_path = tempfile.mkstemp(prefix='putka.',suffix='.tmp',text=True)
		temp_file = os.fdopen(temp_fd, 'a+', 0);
		os.dup2(temp_file.fileno(), sys.stdout.fileno())
		os.dup2(temp_file.fileno(), sys.stderr.fileno())

	# perform the mount (starts a background process)
	mount_ok = False
	try:
		if not opts.bg:
			print 'Mount process started in foreground. If no error messages appear, everything is in order.'
			print 'Do NOT put this process in the background. To unmount, run putkafs.py FROM ANOTHER CONSOLE.'
		mp = fuse.mount(putkafs, opts.mountpoint, foreground=not opts.bg)
		mount_ok = True
	except:
		traceback.print_exc()

	if opts.bg:
		# Restore stdout, stderr. The mount process branched away and inherited the temp file as stdout/err.
		os.dup2(_out, sys.stdout.fileno())
		os.dup2(_err, sys.stderr.fileno())

		# Print status
		if mount_ok:
			print 'Mounted putkafs at %s' % opts.mountpoint
		else:
			print 'Error mounting putkafs.'
			print open(temp_path).read().rstrip()
Пример #12
0
            data = png_to_data(ff.read())
            ft.write(data)
    elif sys.argv[1] == 'upload':
        filefrom = sys.argv[2]
        with open(filefrom) as ff, tempfile.NamedTemporaryFile() as tf:
            img = data_to_png(ff.read())
            img.save(tf, 'png')
            print flickr.upload(filename=tf.name, format='bs4').photoid.text
    elif sys.argv[1] == 'download':
        imageid, fileto = sys.argv[2], sys.argv[3]
        with open(fileto, 'w') as ft:
            url = flickr.get_sizes(photo_id=imageid, format='bs4').sizes.find(
                'size', label='Original')['source']
            ft.write(png_to_data(requests.get(url).content))
    elif len(sys.argv) == 2:
        mp = fuse.mount(FlickrFS(), sys.argv[1])
        print 'mounted your filckr account on', mp.path, 'pid', mp.pid, '.'
    else:
        print "Usage:"
        print "python runflickrfs.py <mntpoint> - mount your flickr account as a FUSE filesystem"
        print "python runflickrfs.py encode <from> <to> - encode the contents of a file as a png"
        print "python runflickrfs.py decode <from> <to> - decode the .png from into it's original contents"
        print "python runflickrfs.py upload <from> - upload the file to flickr and print the photo id"
        print "python runflickrfs.py download <photoid> - download a photo and decode it to it's original contents"

########NEW FILE########
__FILENAME__ = sampleconfig
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
api_secret = 'yyyyyyyyyyyyyyyy'
user_id = 'zzzzzzzzzzzz'
########NEW FILE########
Пример #13
0
        sys.stderr.flush()
        _out, _err = os.dup(sys.stdout.fileno()), os.dup(sys.stderr.fileno())
        temp_fd, temp_path = tempfile.mkstemp(prefix='putka.',
                                              suffix='.tmp',
                                              text=True)
        temp_file = os.fdopen(temp_fd, 'a+', 0)
        os.dup2(temp_file.fileno(), sys.stdout.fileno())
        os.dup2(temp_file.fileno(), sys.stderr.fileno())

    # perform the mount (starts a background process)
    mount_ok = False
    try:
        if not opts.bg:
            print 'Mount process started in foreground. If no error messages appear, everything is in order.'
            print 'Do NOT put this process in the background. To unmount, run putkafs.py FROM ANOTHER CONSOLE.'
        mp = fuse.mount(putkafs, opts.mountpoint, foreground=not opts.bg)
        mount_ok = True
    except:
        traceback.print_exc()

    if opts.bg:
        # Restore stdout, stderr. The mount process branched away and inherited the temp file as stdout/err.
        os.dup2(_out, sys.stdout.fileno())
        os.dup2(_err, sys.stderr.fileno())

        # Print status
        if mount_ok:
            print 'Mounted putkafs at %s' % opts.mountpoint
        else:
            print 'Error mounting putkafs.'
            print open(temp_path).read().rstrip()
Пример #14
0
from fs.memoryfs import MemoryFS
from fs.expose import fuse
fs = MemoryFS()  # create an in memory file system
fs.createfile('filename.txt')  # creating an empty file
fs.setcontents('filename.txt',
               'contents of file')  # putting content into the file.
from fs.osfs import OSFS
home_fs = OSFS('/')  #
home_fs.makedir(
    '/home/dave/scratch/ramdrive', allow_recreate=True
)  # have to make a directory for us to mount our memory file system on.
mp = fuse.mount(
    fs, '/home/dave/scratch/ramdrive'
)  # exposes fs to everything else on machine. (ie: other system calls can see these files)
mp.path  # in case you need the path to the files created.
mp.unmount()  # files are no longer being exposed via fuse
home_fs.removedir('/home/dave/scratch/ramdrive/'
                  )  #remove the real file system directory when done.

fs.remove('filename.txt')

home_fs.close()
fs.close()

# creating a ramdrive like this wont work for my desired task, as other external applications cannot write to the directory. They only have read access.
Пример #15
0
        filefrom, fileto = sys.argv[2], sys.argv[3]
        with open(filefrom) as ff, open(fileto, "w") as ft:
            img = data_to_png(ff.read())
            img.save(ft, "png")
    elif sys.argv[1] == "decode":
        filefrom, fileto = sys.argv[2], sys.argv[3]
        with open(filefrom) as ff, open(fileto, "w") as ft:
            data = png_to_data(ff.read())
            ft.write(data)
    elif sys.argv[1] == "upload":
        filefrom = sys.argv[2]
        with open(filefrom) as ff, tempfile.NamedTemporaryFile() as tf:
            img = data_to_png(ff.read())
            img.save(tf, "png")
            print flickr.upload(filename=tf.name, format="bs4").photoid.text
    elif sys.argv[1] == "download":
        imageid, fileto = sys.argv[2], sys.argv[3]
        with open(fileto, "w") as ft:
            url = flickr.get_sizes(photo_id=imageid, format="bs4").sizes.find("size", label="Original")["source"]
            ft.write(png_to_data(requests.get(url).content))
    elif len(sys.argv) == 2:
        mp = fuse.mount(FlickrFS(), sys.argv[1])
        print "mounted your filckr account on", mp.path, "pid", mp.pid, "."
    else:
        print "Usage:"
        print "python runflickrfs.py <mntpoint> - mount your flickr account as a FUSE filesystem"
        print "python runflickrfs.py encode <from> <to> - encode the contents of a file as a png"
        print "python runflickrfs.py decode <from> <to> - decode the .png from into it's original contents"
        print "python runflickrfs.py upload <from> - upload the file to flickr and print the photo id"
        print "python runflickrfs.py download <photoid> - download a photo and decode it to it's original contents"
Пример #16
0
'''
2015 John Ko
This mounts a CCASFS with FUSE
'''

from ccasfs import CCASFS
from logging import DEBUG, INFO, ERROR, CRITICAL
import fs
from fs.expose import fuse

logger = fs.getLogger('fs.ccasfs')
logger.setLevel(DEBUG)

ccasfs = CCASFS( [
            "/scratch/ccasfs/chunks/"
        ],
        "/scratch/ccasfs/meta/manifest",
        "/scratch/ccasfs/meta/index",
        "/scratch/ccasfs/meta/catalog",
        "/scratch/ccasfs/tmp",
        write_algorithm="mirror",
        debug=2)

mountpoint = fuse.mount(ccasfs, "/mnt", foreground=True, fsname="ccasfs")