Exemplo n.º 1
0
    def list(self, path, keys=()):
        is_allowed = False
        if len(path) == 0:
            is_allowed = True
        else:
            for seg in path:
                if seg in self.allowed_dirs:
                    is_allowed = True
                    break
        results = []
        if is_allowed:
            path = self._path(path)
            if path.isdir():
                entries = path.listdir()
            else:
                entries = [None]

            for fName in entries:
                if not fName or re.search('^\.', str(fName)):
                    continue
                ent = []
                full_path = os.path.join(path.path, fName)
                if not os.path.isdir(full_path) or fName in self.allowed_dirs:
                    results.append((fName, ent))
                if keys:
                    if fName is not None:
                        p = os.path.join(path.path, fName)
                    else:
                        p = path.path
                    try:
                        statResult = os.stat(p)
                    except (IOError, OSError), e:
                        return ftp.errnoToFailure(e.errno, path)
                    except:
                        return defer.fail()
Exemplo n.º 2
0
Arquivo: ftp.py Projeto: SMAC/smaclib
 def openForReading(self, path):
     p = self._path(path)
     
     if p.isdir():
         return defer.fail(ftp.IsADirectoryError(path))
     
     try:
         f = p.open('r')
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 3
0
    def openForWriting(self, path):
        key = self._path(path)
        log.msg('Writing to {}'.format(key))
        object = self._bucket.object(key)

        try:
            fd, path = tempfile.mkstemp()
            os.close(fd)
            fh = open(path, 'w')
        except (IOError, OSError), e:
            return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 4
0
 def openForReading(self, path):
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         f = p.open('rb')
         #print "f seek", self.pos
         if self.pos != 0:
             f.seek(self.pos, 0)
             self.pos = 0
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 5
0
    def ftp_STOR(self, path):
        if self.dtpInstance is None:
            raise BadCmdSequenceError('PORT or PASV required before STOR')
        try:
            newsegs = toSegments(self.workingDirectory, path)
        except InvalidPath:
            return defer.fail(FileNotFoundError(path))

#         parent_path = '/' + ('/'.join(newsegs[:-1]))
#         parent_item = backup_fs.GetByPath(parent_path)
#         if not parent_item:
#             return defer.fail(FileNotFoundError(parent_path))

        # XXX For now, just disable the timeout.  Later we'll want to
        # leave it active and have the DTP connection reset it
        # periodically.
        self.setTimeout(None)
        # Put it back later

        # , prefix=(newsegs[-1] + '_')
        upload_dir = tmpfile.make_dir('backup', extension='.ftp')
        if not upload_dir:
            return defer.fail(FileNotFoundError(path))
        upload_filename = os.path.join(upload_dir, newsegs[-1])
        fp = filepath.FilePath(upload_filename)
        try:
            fObj = fp.open('w')
        except (IOError, OSError) as e:
            return errnoToFailure(e.errno, path)
        except:
            return defer.fail(FileNotFoundError(path))
        # TODO: remove file after all
        # d.addCallback(lambda ignored: file.close(); and remove file)
        # d = Deferred()
        d = Deferred()
        d.addCallback(self._cbWriteOpened, upload_filename, newsegs)
        d.addErrback(self._ebWriteOpened, newsegs)
        d.addBoth(self._enableTimeoutLater)
        d.callback(_FileWriter(fObj))

#         d.addCallbacks(self._cbFileRecevied, self._ebFileReceived)
#         fw = _FileWriter(fObj)
#         receive_defer = fw.receive()
#         receive_defer.addBoth(self._enableTimeoutLater)
#         receive_defer.addCallback(self._prepareConsumer)
#         receive_defer.addCallback(self._startFileBackup, upload_filename, newsegs, d)
#         receive_defer.addErrback(lambda err: d.errback(FileNotFoundError(path)))

        return d
Exemplo n.º 6
0
 def openForWriting(self, path):
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         if self.appe:
             fObj = p.open('ab')
             self.appe = False
             #print "appe writing"
         else:
             fObj = p.open('wb')
             #print "stor writing"
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 7
0
 def openForReading(self, path):
     '''
     Overwrite openForReading of ftp.FTPAnonymousShell,
     make it support ftp_REST
     '''
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         f = p.open('rb')
         if self.pos != 0:
             f.seek(self.pos, 0)
             self.pos = 0
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 8
0
 def openForReading(self, path):
     '''
     Overwrite openForReading of ftp.FTPAnonymousShell,
     make it support ftp_REST
     '''
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         f = p.open('rb')
         if self.pos != 0:
             f.seek(self.pos, 0)
             self.pos = 0
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 9
0
 def openForWriting(self, path):
     '''
     Overwrite openForReading of ftp.FTPShell,
     make it support ftp_APPE
     '''
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         if self.append:
             fObj = p.open('ab')
             self.append = False
         else:
             fObj = p.open('wb')
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)
Exemplo n.º 10
0
 def openForWriting(self, path):
     '''
     Overwrite openForReading of ftp.FTPShell,
     make it support ftp_APPE
     '''
     p = self._path(path)
     if p.isdir():
         # Normally, we would only check for EISDIR in open, but win32
         # returns EACCES in this case, so we check before
         return defer.fail(ftp.IsADirectoryError(path))
     try:
         if self.append:
             fObj = p.open('ab')
             self.append = False
         else:
             fObj = p.open('wb')
     except (IOError, OSError), e:
         return ftp.errnoToFailure(e.errno, path)