当前位置: 首页>>代码示例>>Python>>正文


Python JsonConfigHelper.store方法代码示例

本文整理汇总了Python中au.edu.usq.fascinator.common.JsonConfigHelper.store方法的典型用法代码示例。如果您正苦于以下问题:Python JsonConfigHelper.store方法的具体用法?Python JsonConfigHelper.store怎么用?Python JsonConfigHelper.store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在au.edu.usq.fascinator.common.JsonConfigHelper的用法示例。


在下文中一共展示了JsonConfigHelper.store方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from au.edu.usq.fascinator.common import JsonConfigHelper [as 别名]
# 或者: from au.edu.usq.fascinator.common.JsonConfigHelper import store [as 别名]
    def process(self):
        print " * settings.py: formData=%s" % self.vc("formData")

        result = "{}"
        portalManager = Services.getPortalManager()
        portal = portalManager.get(self.vc("portalId"))
        func = self.vc("formData").get("func")

        if func == "view-update":
            portal.setDescription(self.vc("formData").get("view-description"))
            portal.setQuery(self.vc("formData").get("view-query"))
            portal.setSearchQuery(self.vc("formData").get("view-search-query"))
            portal.setRecordsPerPage(int(self.vc("formData").get("view-records-per-page")))
            portal.setFacetCount(int(self.vc("formData").get("view-facet-count")))
            portal.setFacetDisplay(int(self.vc("formData").get("view-facet-display")))
            portal.setFacetSort(self.vc("formData").get("view-facet-sort") is not None)
            portalManager.save(portal)

        elif func == "general-update":
            config = JsonConfig()
            email = StringUtils.trimToEmpty(self.vc("formData").get("general-email"))
            systemEmail = StringUtils.trimToEmpty(config.get("email"))
            print email, systemEmail
            if systemEmail != email:
                config.set("email", self.vc("formData").get("general-email"), True)
                config.set("configured", "true", True)
                config.store(NullWriter(), True)
                # mark restart
                Services.getHouseKeepingManager().requestUrgentRestart()
            else:
                print " * settings.py: email not updated: did not change"
                self.throw_error("Email address is the same! No change saved.")

        elif func == "facets-update":
            portal.removePath("portal/facet-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            displays = self.vc("formData").getValues("display")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    portal.set("portal/facet-fields/%s/label" % field, labels[i])
                    portal.set("portal/facet-fields/%s/display" % field, displays[i])
            portalManager.save(portal)

        elif func == "sort-update":
            portal.removePath("portal/sort-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    portal.set("portal/sort-fields/%s" % field, labels[i])
            portalManager.save(portal)

        elif func == "watcher-update":
            configFile = self.getWatcherFile()
            if configFile is not None:
                pathIds = self.vc("formData").get("pathIds").split(",")
                actives = self.vc("formData").getValues("watcher-active")
                if actives is None:
                    actives = []
                deletes = self.vc("formData").getValues("watcher-delete")
                if deletes is None:
                    deletes = []
                watchDirs = HashMap()
                for pathId in pathIds:
                    if pathId not in deletes:
                        path = self.vc("formData").get("%s-path" % pathId)
                        stopped = str(pathId not in actives).lower()
                        watchDir = HashMap()
                        watchDir.put("ignoreFileFilter", self.vc("formData").get("%s-file" % pathId))
                        watchDir.put("ignoreDirectories", self.vc("formData").get("%s-dir" % pathId))
                        watchDir.put("cxtTags", [])
                        watchDir.put("stopped", stopped)
                        watchDirs.put(path, watchDir)
                json = JsonConfigHelper(self.getWatcherFile())
                json.setMap("watcher/watchDirs", watchDirs)
                json.store(FileWriter(configFile), True)
            else:
                result = "The Watcher is not installed properly."

        elif func == "restore-default-config":
            # backup the file
            JsonConfig.backupSystemFile()
            # delete the file
            JsonConfig.getSystemFile().delete()
            # restore default
            JsonConfig.getSystemFile()
            # mark restart
            Services.getHouseKeepingManager().requestUrgentRestart()

        elif func == "housekeeping-update":
            config = JsonConfig()
            freq = StringUtils.trimToEmpty(self.vc("formData").get("housekeeping-timeout"))
            systemFreq = StringUtils.trimToEmpty(config.get("portal/houseKeeping/config/frequency"))
            result = "House Keeper refreshed"
            if systemFreq != freq:
#.........这里部分代码省略.........
开发者ID:kiranba,项目名称:the-fascinator,代码行数:103,代码来源:settings.py

示例2: __processRequest

# 需要导入模块: from au.edu.usq.fascinator.common import JsonConfigHelper [as 别名]
# 或者: from au.edu.usq.fascinator.common.JsonConfigHelper import store [as 别名]
    def __processRequest(self):
        baseUrl = "http://%s:%s%s/%s" % (request.serverName, serverPort, contextPath, portalId)
        depositUrl = "%s/sword/deposit.post" % baseUrl
        sword = SwordSimpleServer(depositUrl)
        try:
            p =  request.path.split(portalId+"/"+pageName+"/")[1]  # portalPath
        except:
            p = ""
        if p=="post":
            print "\n--- post ---"
            c = sword.getClient()
            c.clearProxy()
            c.clearCredentials()
            postMsg = sword.getPostMessage();
            postMsg.filetype = "application/zip"
            postMsg.filepath = "/home/ward/Desktop/Test.zip"
            depositResponse = c.postFile(postMsg)
            return str(depositResponse)
        elif p=="servicedocument":
            #print "\n--- servicedocument ---"
            sdr = sword.getServiceDocumentRequest()
            sdr.username = formData.get("username", "test")
            sdr.password = formData.get("password", "test")
            if formData.get("test"):
                depositUrl += "?test=1"
            sd = sword.doServiceDocument(sdr)  # get a serviceDocument
            out = response.getPrintWriter("text/xml")
            out.println(str(sd))
            out.close()
            bindings["pageName"] = "-noTemplate-"
            return sd
        elif p=="deposit.post":
            #print "\n--- deposit ---  formData='%s'" % str(formData)
            inputStream = formData.getInputStream()
            headers = {}
            for x in formData.getHeaders().entrySet():
                headers[x.getKey()] = x.getValue()
            deposit = sword.getDeposit()
            noOp = headers.get("X-No-Op") or "false"
            deposit.noOp = (noOp.lower()=="true") or \
                (formData.get("test") is not None)
            contentDisposition = headers.get("Content-Disposition", "")
            filename = ""
            if contentDisposition!="":
                try:
                    filename = contentDisposition.split("filename=")[1]
                    deposit.filename = filename
                except: pass
            slug = headers.get("Slug")
            if slug is not None and slug!="":
                deposit.slug = slug
            #elif filename!="":
            #    deposit.slug = filename

            deposit.username = "SwordUser"
            deposit.password = deposit.username
            try:
                file = File.createTempFile("tmptf", ".zip")
                file.deleteOnExit()
                fos = FileOutputStream(file.getAbsolutePath())
                IOUtils.copy(inputStream, fos)
                fos.close()
                print "copied posted data to '%s'" % file.getAbsolutePath()
            except Exception, e:
                print "--- Exception - '%s'" % str(e)
            deposit.contentDisposition = file.getAbsolutePath()         #????
            deposit.file = inputStream
            depositResponse = sword.doDeposit(deposit)
            id = str(depositResponse.getEntry().id)
            try:
                print
                #imsPlugin = PluginManager.getTransformer("ims")
                jsonConfig = JsonConfig()
                #imsPlugin.init(jsonConfig.getSystemFile())
                #harvestClient = HarvestClient(jsonConfig.getSystemFile());
                storagePlugin = PluginManager.getStorage(jsonConfig.get("storage/type"))
                #storagePlugin.init(jsonConfig.getSystemFile())

                setConfigUri = self.__getPortal().getClass().getResource("/swordRule.json").toURI()
                configFile = File(setConfigUri)
                harvestConfig = JsonConfigHelper(configFile);
                tFile = File.createTempFile("harvest", ".json")
                tFile.deleteOnExit()
                harvestConfig.set("configDir", configFile.getParent())
                harvestConfig.set("sourceFile", file.getAbsolutePath())
                harvestConfig.store(FileWriter(tFile))

                zipObject = GenericDigitalObject(id)
                zipObject.addPayload(FilePayload(file, id))
                #digitalObject = imsPlugin.transform(zipObject, file)
                qStorage = QueueStorage(storagePlugin, tFile)
                qStorage.init(jsonConfig.getSystemFile())
                qStorage.addObject(zipObject)
                if deposit.noOp:
                    print "-- Testing noOp='true' --"
                else:
                    # deposit the content
                    pass
            except Exception, e:
                print "---"
#.........这里部分代码省略.........
开发者ID:kiranba,项目名称:the-fascinator,代码行数:103,代码来源:sword.py


注:本文中的au.edu.usq.fascinator.common.JsonConfigHelper.store方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。