def __init__(self, filepath, mode='rtc'):
        print("FilePath", filepath)
        print("FilePath", mode)
        #self.mode = mode
        #self.filepath = filepath

        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)
        print(self.srv)

        print("FilePath", filepath)
        print("FilePath", mode)

        if self.srv is None:
            raise DFSIOError('Could not find a server that serves :', filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(
            self, _config['max_size'],
            mode.replace('c', ''))  #mode 'c' meaning store in cache

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            print(type(self.srv))
            host, port = utils.get_host_port(self.srv.decode('UTF-8'))
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status
                print(status)

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
示例#2
0
文件: qftpd.py 项目: Qumulo/qftpd
 def __init__(self, path, filename, fs, max_size=WRITE_BUFFER_SIZE):
     """We need the path so we can write the buffered file to the API"""
     SpooledTemporaryFile.__init__(self, max_size=max_size)  # old-style!
     self.path = path
     self.filename = filename
     self.fs = fs
     self.fullpath = ''
     try:
         self.fullpath = self.create_file()
     except RequestError, e:
         SpooledTemporaryFile.close(self)
         raise FilesystemError(str(e))
示例#3
0
    def __init__(self, filepath, mode='rtc'):
        """filepath: the path of the distant file
           mode: take the same argument as mode argument of the global
                 open() + optional flag c (which mean store in cache).
        """

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)

        if self.srv is None:
            raise DFSIOError('Impossible to find a server that serve %s.' %
                             filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'],
                                      mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
示例#4
0
文件: client.py 项目: Alexis-D/DFS
    def __init__(self, filepath, mode='rtc'):
        """filepath: the path of the distant file
           mode: take the same argument as mode argument of the global
                 open() + optional flag c (which mean store in cache).
        """

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)

        if self.srv is None:
            raise DFSIOError('Impossible to find a server that serve %s.'
                    % filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
示例#5
0
	def __init__(self, path, mode = 'rtc'):
		
		self.mode = mode
		self.path = path
		host,port = utils.get_port(_config['nameserver'])
		self.server = utils.getServer(path, host, port)
	
		if self.server is None:
			print('File not found')

		self.modified = None 


		SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c',''))		

		host,port = utils.get_port(_config['lockserver'])
		if utils.Locked(path, host, port):
			print('File is locked')	
	
		if 'w' not in mode:
			host, port = utils.get_port(self.server)
			with closing(HTTPConnection(host,port)) as con:
				con.request('GET', filepath)
				response = con.getresponse()
				self.modified = response.getheader('Last-Modified')
				status = response.status

				if status not in (200,204):
					print('Error occured',status)
			
				if status !=  204:
					self.write(response.read())

				if 'r' in mode:
					self.seek(0)

				self.lockid = ''

		if 'a' in mode or 'w' in mode:
			host,port = utils.get_port(_config['lockserver'])
			self.lockid = int(utils.Locked(path, host, port))

		if 'c' in mode:
			File._cache[path] = self
示例#6
0
    def __init__(self, filepath, mode='rtc'):
        

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)
        
        
        self.last_modified = None
        
        SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c',''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d)while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode: # automatically lock file if appending or writing in file
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self        
    def __init__(self, path, mode='rtc'):

        self.mode = mode
        self.path = path
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(path, host, port)

        if self.srv is None:
            pass

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'],
                                      mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(path, host, port):
            pass

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', path)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(path, host, port))

        if 'c' in mode:
            File._cache[path] = self
示例#8
0
    def __init__(self, filepath, mode='rtc'):
        """filepath: the path of the distant file"""

        self.mode = mode
        self.filepath = filepath
        host, port = get_host_port()
        self.srv = get_server(filepath, host, port)

        if self.srv is None:
            raise Error('Impossible to find a server that serve %s.'
                    % filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c', ''))

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))


        if 'c' in mode:
            File._cache[filepath] = self
示例#9
0
 def __init__(self, file_obj, max_size=50 * 1024 * 1024):
     self._file_obj = file_obj
     SpooledTemporaryFile.__init__(self, max_size)
示例#10
0
文件: save.py 项目: JimmXinu/calibre
 def __init__(self, file_obj, max_size=50*1024*1024):
     self._file_obj = file_obj
     SpooledTemporaryFile.__init__(self, max_size)
示例#11
0
 def __init__(self, threshold=10 * 1024 * 1024, **kw):
     # STF uses >, the old ATF used >= for the max_size check
     SpooledTemporaryFile.__init__(self, max_size=threshold - 1, **kw)
示例#12
0
 def __init__(self, threshold=10 * 1024 * 1024, **kw):
     # STF uses >, the old ATF used >= for the max_size check
     SpooledTemporaryFile.__init__(self, max_size=threshold - 1, **kw)