Esempio n. 1
0
 def empty_user(self):
     strRootDir = request.getServletContext().getRealPath("/")
     strUserHtmlDir = strRootDir + "html" + File.separator + "user" + File.separator
     dirFile = File(strUserHtmlDir)
     if dirFile.exists() == False or dirFile.isDirectory() == False:
         request.setAttribute("errorMessage", u"用户缓存文件夹不存在!")
         return
     
     FileUtils.deleteQuietly(dirFile)
     request.setAttribute("errorMessage", u"删除所有用户缓存完毕!")
Esempio n. 2
0
    def getToken(self, tokenId):
        self.resetErrors()
        index = "resumptionTokens-GET"
        sql = """
SELECT *
FROM   resumptionTokens
WHERE  token = ?
"""
        fields = [tokenId]
        try:
            result = self.db.select(self.dbName, index, sql, fields)
            # Make sure we got a response
            if result is None or result.isEmpty():
                return None
            # Create the new token to return
            metadataPrefix = result.get(0).get("METADATAPREFIX")
            expiryStr = result.get(0).get("EXPIRY")
            # Jython does not support %f microseconds in time parsing, makes
            # this more awkward then it should be in 2.6+ Python
            # 1: split into basic time + micro seconds
            (basicTime, mSecs) = expiryStr.strip().split(".")
            # 2: Parse the basic time
            expiryDt = datetime.strptime(basicTime, "%Y-%m-%d %H:%M:%S")
            # 3: Convert into a 'epoch' long and then to a string (has an extra ".0" on the end)
            epoch = "%s" % time.mktime(expiryDt.timetuple())
            # 4: Remove the extraneous trailing zero and re-attach microseconds
            expiry = "%s%s" % (epoch.replace(".0", ""), mSecs)

            nextToken = result.get(0).get("NEXTTOKEN")
            file = File(
                FascinatorHome.getPath("oaipmh-results") + "/" + tokenId)
            resultJson = FileUtils.readFileToString(file)
            FileUtils.deleteQuietly(file)
            token = ResumptionToken(tokenId, metadataPrefix, nextToken,
                                    resultJson)
            token.setExpiry(expiry)

            return token
        except Exception, e:
            # Something is wrong
            self.log.error("ERROR: ", e)
            self.error = True
            self.errorMsg = self.parseError(e)
            return None
Esempio n. 3
0
    def getToken(self, tokenId):
        self.resetErrors()
        index = "resumptionTokens-GET"
        sql = """
SELECT *
FROM   resumptionTokens
WHERE  token = ?
"""
        fields = [tokenId]
        try:
            result = self.db.select(self.dbName, index, sql, fields)
            # Make sure we got a response
            if result is None or result.isEmpty():
                return None
            # Create the new token to return
            metadataPrefix = result.get(0).get("METADATAPREFIX")
            expiryStr = result.get(0).get("EXPIRY")
            # Jython does not support %f microseconds in time parsing, makes
            # this more awkward then it should be in 2.6+ Python
            # 1: split into basic time + micro seconds
            (basicTime, mSecs) = expiryStr.strip().split(".")
            # 2: Parse the basic time
            expiryDt = datetime.strptime(basicTime, "%Y-%m-%d %H:%M:%S")
            # 3: Convert into a 'epoch' long and then to a string (has an extra ".0" on the end)
            epoch = "%s" % time.mktime(expiryDt.timetuple())
            # 4: Remove the extraneous trailing zero and re-attach microseconds
            expiry = "%s%s" % (epoch.replace(".0", ""), mSecs)

            nextToken = result.get(0).get("NEXTTOKEN")
            file = File(FascinatorHome.getPath("oaipmh-results")+ "/"+tokenId)
            resultJson = FileUtils.readFileToString(file)
            FileUtils.deleteQuietly(file)
            token = ResumptionToken(tokenId, metadataPrefix,nextToken,resultJson)
            token.setExpiry(expiry)
            
            return token
        except Exception, e:
            # Something is wrong
            self.log.error("ERROR: ", e)
            self.error = True
            self.errorMsg = self.parseError(e)
            return None
Esempio n. 4
0
 def removeToken(self, tokenObject):
     self.resetErrors()
     index = "resumptionTokens-DELETE"
     table = "resumptionTokens"
     fields = {
         "token": tokenObject.getToken()
     }
     try:
         self.db.delete(self.dbName, index, table, fields)
         file = File(FascinatorHome.getPath("oaipmh-results")+ "/"+tokenObject.getToken())
         FileUtils.deleteQuietly(file)
         self.log.info("Delete successful! TOKEN='{}'", tokenObject.getToken())
         return True
     except Exception, e:
         # Something is wrong
         self.log.error("Delete failed! TOKEN='{}'", tokenObject.getToken())
         self.log.error("ERROR: ", e)
         self.error = True
         self.errorMsg = self.parseError(e)
         return False
Esempio n. 5
0
 def removeToken(self, tokenObject):
     self.resetErrors()
     index = "resumptionTokens-DELETE"
     table = "resumptionTokens"
     fields = {"token": tokenObject.getToken()}
     try:
         self.db.delete(self.dbName, index, table, fields)
         file = File(
             FascinatorHome.getPath("oaipmh-results") + "/" +
             tokenObject.getToken())
         FileUtils.deleteQuietly(file)
         self.log.info("Delete successful! TOKEN='{}'",
                       tokenObject.getToken())
         return True
     except Exception, e:
         # Something is wrong
         self.log.error("Delete failed! TOKEN='{}'", tokenObject.getToken())
         self.log.error("ERROR: ", e)
         self.error = True
         self.errorMsg = self.parseError(e)
         return False
Esempio n. 6
0
    def deleteDirectory(self, sPath):
        # 如果sPath不以文件分隔符结尾,自动添加文件分隔符
        dirFile = File(sPath)
        # 如果dir对应的文件不存在,或者不是一个目录,则退出
        if dirFile.exists() == False or dirFile.isDirectory() == False:
            return

        FileUtils.deleteQuietly(dirFile)
        return
        """
        换一种新的方法,以下代码不用了
        """
        # 删除文件夹下的所有文件(包括子目录)
        files = dirFile.listFiles()
        if files == None or len(files) == 0: return
        for f in files:
            # 删除子文件
            if f.isFile():
                f.delete()
            else:
                self.deleteDirectory(f.getAbsolutePath())
        #/删除当前目录
        dirFile.delete()
        dirFile = None