예제 #1
0
    def _doOperation(self, *args, **kargs):
        # Parse arguments

        if len(args) < 1:
            raise SyntaxException("Incorrect arguments")

        theDir = args[0]
        if not isinstance(theDir, File) and type(theDir) != str:
            raise SyntaxException("Cannot read directory",
                                  "Expected a file object or string")

        if type(theDir) == str:
            theDir = File(theDir)

        if not theDir.isDir():
            raise DriverException("Cannot read directory",
                                  "A file has been provided")

        self._setActionString(
            ACTION_SKIP,
            "Skip reading directory " + repr(theDir) + " and return None")
        self._setActionString(
            ACTION_REPEAT,
            "Try to read the directory " + repr(theDir) + " again")

        # Will do the checks and raise the appropriate exceptions
        result = theDir.read()

        return [False, result, NOTIF_STATUS_OK, ""]
예제 #2
0
    def _doOperation(self, *args, **kargs):
        # Parse arguments

        if len(args) < 1:
            raise SyntaxException("Incorrect arguments")

        theFile = args[0]

        if not isinstance(theFile, File) and type(theFile) != str:
            raise SyntaxException("Cannot delete",
                                  "Expected a file object or string")

        if type(theFile) == str:
            theFile = File(theFile)

        if theFile.isDir():
            raise DriverException("Cannot delete file",
                                  "A directory has been provided")

        self._setActionString(
            ACTION_SKIP,
            "Skip deleting file " + repr(theFile) + " and return None")
        self._setActionString(ACTION_REPEAT,
                              "Try to delete file " + repr(theFile) + " again")

        # Will do the checks and raise the appropriate exceptions
        theFile.delete()

        return [False, True, NOTIF_STATUS_OK, "File deleted"]
예제 #3
0
    def _doOperation(self, *args, **kargs):
        # Parse arguments

        if len(args) == 0:
            raise SyntaxException("No path given")

        filename = args[0]
        if isinstance(filename, File):
            baseName = filename.basename()
            theFile = filename
        elif type(filename) == str:
            baseName = os.path.basename(filename)
            theFile = File(filename)
        else:
            raise SyntaxException("Cannot open",
                                  "Expected a string or a File object")

        if theFile.isDir():
            raise DriverException("Cannot open file",
                                  "A directory has been provided")

        self._setActionString(
            ACTION_SKIP,
            "Skip opening the file " + repr(baseName) + " and return None")
        self._setActionString(
            ACTION_REPEAT, "Try to open the file " + repr(baseName) + " again")

        self._notifyValue("File", repr(baseName), NOTIF_STATUS_PR, "Opening")

        try:
            mode = READ
            if self.hasConfig(Mode):
                mode = self.getConfig(Mode)

            self._write("Opening file " + repr(baseName) + " in mode " + mode,
                        config={Severity: INFORMATION})

            theFile.open(mode)

            self._write("File open")

        except DriverException, ex:
            self._notifyValue("File", repr(baseName), NOTIF_STATUS_FL,
                              "Open failed")
            raise ex
예제 #4
0
    def _doOperation(self, *args, **kargs ):
        # Parse arguments
        
        if len(args)==0:
            raise SyntaxException("No path given")

        filename = args[0]
        if isinstance(filename,File):
            baseName = filename.basename()
            theFile = filename
        elif type(filename)==str:
            baseName = os.path.basename(filename)
            theFile = File(filename)
        else:
            raise SyntaxException("Cannot open", "Expected a string or a File object")

        if theFile.isDir():
            raise DriverException("Cannot open file", "A directory has been provided")

        self._setActionString( ACTION_SKIP   ,  "Skip opening the file " + repr(baseName) + " and return None")
        self._setActionString( ACTION_REPEAT ,  "Try to open the file " + repr(baseName) + " again")

        self._notifyValue( "File", repr(baseName), NOTIF_STATUS_PR, "Opening")
        
        try:
            mode = READ
            if self.hasConfig(Mode):
                mode = self.getConfig(Mode)

            self._write("Opening file " + repr(baseName) + " in mode " + mode, config={Severity:INFORMATION})
            
            theFile.open(mode)

            self._write("File open")
                
        except DriverException,ex:
            self._notifyValue( "File", repr(baseName), NOTIF_STATUS_FL, "Open failed")
            raise ex
예제 #5
0
    def _doOperation(self, *args, **kargs ):
        # Parse arguments
        
        if len(args)<1:
            raise SyntaxException("Incorrect arguments")

        theDir = args[0]
        if not isinstance(theDir,File) and type(theDir)!= str:
            raise SyntaxException("Cannot read directory", "Expected a file object or string")
        
        if type(theDir)==str:
            theDir = File(theDir)
        
        if not theDir.isDir():
            raise DriverException("Cannot read directory", "A file has been provided")
        
        self._setActionString( ACTION_SKIP   ,  "Skip reading directory " + repr(theDir) + " and return None")
        self._setActionString( ACTION_REPEAT ,  "Try to read the directory " + repr(theDir) + " again")

        # Will do the checks and raise the appropriate exceptions
        result = theDir.read()

        return [False,result,NOTIF_STATUS_OK,""]
예제 #6
0
    def _doOperation(self, *args, **kargs ):
        # Parse arguments
        
        if len(args)<1:
            raise SyntaxException("Incorrect arguments")

        theFile = args[0]
        
        if not isinstance(theFile,File) and type(theFile)!= str:
            raise SyntaxException("Cannot delete", "Expected a file object or string")
        
        if type(theFile)==str:
            theFile = File(theFile)
        
        if theFile.isDir():
            raise DriverException("Cannot delete file", "A directory has been provided")
        
        self._setActionString( ACTION_SKIP   ,  "Skip deleting file " + repr(theFile) + " and return None")
        self._setActionString( ACTION_REPEAT ,  "Try to delete file " + repr(theFile) + " again")

        # Will do the checks and raise the appropriate exceptions
        theFile.delete()

        return [False,True,NOTIF_STATUS_OK,"File deleted"]