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


Python CachingFilePath.setContent方法代码示例

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


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

示例1: configure

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def configure(self):
        """
        Adjust the global configuration for this test.
        """
        self.serverRoot = self.mktemp()
        os.mkdir(self.serverRoot)

        config.reset()

        config.ServerRoot = os.path.abspath(self.serverRoot)
        config.ConfigRoot = "config"
        config.LogRoot = "logs"
        config.RunRoot = "logs"

        if not os.path.exists(config.DataRoot):
            os.makedirs(config.DataRoot)
        if not os.path.exists(config.DocumentRoot):
            os.makedirs(config.DocumentRoot)
        if not os.path.exists(config.ConfigRoot):
            os.makedirs(config.ConfigRoot)
        if not os.path.exists(config.LogRoot):
            os.makedirs(config.LogRoot)

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True
        memcacher.Memcacher.memoryCacheInstance = None
        config.DirectoryAddressBook.Enabled = False
        config.UsePackageTimezones = True

        accounts = FilePath(config.DataRoot).child("accounts.xml")
        accounts.setContent(xmlFile.getContent())
开发者ID:anemitz,项目名称:calendarserver,代码行数:35,代码来源:util.py

示例2: __init__

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def __init__(self, params, alwaysStat=False):

        defaults = {
            'xmlFile' : None,
            'directoryBackedAddressBook': None,
            'recordTypes' : (
                self.recordType_users,
                self.recordType_groups,
                self.recordType_locations,
                self.recordType_resources,
            ),
            'cacheTimeout' : 30,
            'realmName' : '/Search',
        }
        ignored = None
        params = self.getParams(params, defaults, ignored)

        self._recordTypes = params['recordTypes']
        self.realmName = params['realmName']

        super(XMLDirectoryService, self).__init__(params['cacheTimeout'])

        xmlFile = fullServerPath(config.DataRoot, params.get("xmlFile"))
        if type(xmlFile) is str:
            xmlFile = FilePath(xmlFile)

        if not xmlFile.exists():
            xmlFile.setContent("""<?xml version="1.0" encoding="utf-8"?>

<accounts realm="%s">
</accounts>
""" % (self.realmName,))

        uid = -1
        if config.UserName:
            try:
                uid = pwd.getpwnam(config.UserName).pw_uid
            except KeyError:
                self.log_error("User not found: %s" % (config.UserName,))

        gid = -1
        if config.GroupName:
            try:
                gid = grp.getgrnam(config.GroupName).gr_gid
            except KeyError:
                self.log_error("Group not found: %s" % (config.GroupName,))

        if uid != -1 and gid != -1:
            os.chown(xmlFile.path, uid, gid)


        self.xmlFile = xmlFile
        self._fileInfo = None
        self._lastCheck = 0
        self._alwaysStat = alwaysStat
        self.directoryBackedAddressBook = params.get('directoryBackedAddressBook')

        self._accounts()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:60,代码来源:xmlfile.py

示例3: test_shouldReparse

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
 def test_shouldReparse(self):
     """
     Verify that a change to the file will get noticed
     """
     newxmlfile = FilePath(self.mktemp())
     FilePath(xmlFile).copyTo(newxmlfile)
     db = AugmentXMLDB((newxmlfile.path,))
     self.assertFalse(db._shouldReparse([newxmlfile.path])) # No need to parse
     newxmlfile.setContent("") # Change the file
     self.assertTrue(db._shouldReparse([newxmlfile.path])) # Need to parse
开发者ID:nunb,项目名称:calendarserver,代码行数:12,代码来源:test_augment.py

示例4: test_parseNonASCIIConfig

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
 def test_parseNonASCIIConfig(self):
     """
     Non-ASCII <string>s found as part of a configuration file will be
     retrieved as UTF-8 encoded 'str' objects, as parsed by
     L{NoUnicodePlistParser}.
     """
     cfg = Config(PListConfigProvider({"DataRoot": ""}))
     tempfile = FilePath(self.mktemp())
     tempfile.setContent(nonASCIIConfigPList)
     cfg.load(tempfile.path)
     self.assertEquals(cfg.DataRoot, nonASCIIValue)
开发者ID:nunb,项目名称:calendarserver,代码行数:13,代码来源:test_stdconfig.py

示例5: test_includes

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def test_includes(self):

        plist1 = """
<plist version="1.0">
  <dict>
    <key>ServerRoot</key>
    <string>/root</string>
    <key>DocumentRoot</key>
    <string>defaultdoc</string>
    <key>DataRoot</key>
    <string>defaultdata</string>
    <key>ConfigRoot</key>
    <string>defaultconfig</string>
    <key>LogRoot</key>
    <string>defaultlog</string>
    <key>RunRoot</key>
    <string>defaultrun</string>
    <key>Includes</key>
    <array>
        <string>%s</string>
    </array>
  </dict>
</plist>
"""

        plist2 = """
<plist version="1.0">
  <dict>
    <key>DataRoot</key>
    <string>overridedata</string>
  </dict>
</plist>
"""

        tempfile2 = FilePath(self.mktemp())
        tempfile2.setContent(plist2)

        tempfile1 = FilePath(self.mktemp())
        tempfile1.setContent(plist1 % (tempfile2.path,))

        cfg = Config(PListConfigProvider({
            "ServerRoot": "",
            "DocumentRoot": "",
            "DataRoot": "",
            "ConfigRoot": "",
            "LogRoot": "",
            "RunRoot": "",
            "Includes": [],
        }))
        cfg.addPostUpdateHooks([_updateDataStore])
        cfg.load(tempfile1.path)
        self.assertEquals(cfg.DocumentRoot, "/root/overridedata/defaultdoc")
        self.assertEquals(cfg.DataRoot, "/root/overridedata")
开发者ID:nunb,项目名称:calendarserver,代码行数:55,代码来源:test_stdconfig.py

示例6: setUp

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def setUp(self):
        super(ManagePrincipalsTestCase, self).setUp()

        # Since this test operates on proxy db, we need to assign the service:
        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))

        config.GlobalAddressBook.Enabled = False

        testRoot = os.path.join(os.path.dirname(__file__), "principals")
        templateName = os.path.join(testRoot, "caldavd.plist")
        templateFile = open(templateName)
        template = templateFile.read()
        templateFile.close()

        databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
        newConfig = template % {
            "ServerRoot" : os.path.abspath(config.ServerRoot),
            "DataRoot" : os.path.abspath(config.DataRoot),
            "DatabaseRoot" : databaseRoot,
            "DocumentRoot" : os.path.abspath(config.DocumentRoot),
            "LogRoot" : os.path.abspath(config.LogRoot),
        }
        configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        origUsersFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "users-groups.xml"))
        copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml"))
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "resources-locations.xml"))
        copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml"))
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "augments.xml"))
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        # Make sure trial puts the reactor in the right state, by letting it
        # run one reactor iteration.  (Ignore me, please.)
        d = Deferred()
        reactor.callLater(0, d.callback, True)
        return d
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:50,代码来源:test_principals.py

示例7: test_quitAfterUpgradeStep

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
 def test_quitAfterUpgradeStep(self):
     triggerFileName = "stop_after_upgrade"
     triggerFile = FilePath(triggerFileName)
     self.pps.addStep(
         StepOne(self._record, False)
     ).addStep(
         StepTwo(self._record, False)
     ).addStep(
         QuitAfterUpgradeStep(triggerFile.path, reactor=self.clock)
     ).addStep(
         StepFour(self._record, True)
     )
     triggerFile.setContent("")
     self.pps.startService()
     self.assertEquals(self.history,
         ['one success', 'two success', 'four failure',
         ('serviceCreator', None, 'storageService')])
     self.assertFalse(triggerFile.exists())
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:20,代码来源:test_caldav.py

示例8: test_relativeDefaultPaths

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
 def test_relativeDefaultPaths(self):
     """
     The paths specified in the default configuration should be interpreted
     as relative to the paths specified in the configuration file.
     """
     cfg = Config(PListConfigProvider(
         {"AccountingLogRoot": "some-path",
          "LogRoot": "should-be-ignored"}))
     cfg.addPostUpdateHooks([_updateDataStore])
     tempfile = FilePath(self.mktemp())
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/some/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/some/root/some-path")
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/other/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/other/root/some-path")
开发者ID:nunb,项目名称:calendarserver,代码行数:22,代码来源:test_stdconfig.py

示例9: setUp

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def setUp(self):
        super(RunCommandTestCase, self).setUp()

        testRoot = os.path.join(os.path.dirname(__file__), "gateway")
        templateName = os.path.join(testRoot, "caldavd.plist")
        templateFile = open(templateName)
        template = templateFile.read()
        templateFile.close()

        databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
        newConfig = template % {
            "ServerRoot" : os.path.abspath(config.ServerRoot),
            "DatabaseRoot" : databaseRoot,
            "WritablePlist" : os.path.join(os.path.abspath(config.ConfigRoot), "caldavd-writable.plist"),
        }
        configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        origUsersFile = FilePath(os.path.join(os.path.dirname(__file__),
            "gateway", "users-groups.xml"))
        copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml"))
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
            "gateway", "resources-locations.xml"))
        copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml"))
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__),
            "gateway", "augments.xml"))
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        # Make sure trial puts the reactor in the right state, by letting it
        # run one reactor iteration.  (Ignore me, please.)
        d = Deferred()
        reactor.callLater(0, d.callback, True)
        return d
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:43,代码来源:test_gateway.py

示例10: setUp

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def setUp(self):
        super(ManagePrincipalsTestCase, self).setUp()

        config.GlobalAddressBook.Enabled = False

        testRoot = os.path.join(os.path.dirname(__file__), "principals")
        templateName = os.path.join(testRoot, "caldavd.plist")
        templateFile = open(templateName)
        template = templateFile.read()
        templateFile.close()

        newConfig = template % {
            "ServerRoot" : os.path.abspath(config.ServerRoot),
        }
        configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        origUsersFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "users-groups.xml"))
        copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml"))
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "resources-locations.xml"))
        copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml"))
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__),
            "principals", "augments.xml"))
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        # Make sure trial puts the reactor in the right state, by letting it
        # run one reactor iteration.  (Ignore me, please.)
        d = Deferred()
        reactor.callLater(0, d.callback, True)
        return d
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:42,代码来源:test_principals.py

示例11: setUp

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def setUp(self):
        super(DeprovisionTestCase, self).setUp()

        testRootPath = FilePath(__file__).sibling("deprovision")
        template = testRootPath.child("caldavd.plist").getContent()

        newConfig = template % {
            "ServerRoot" : os.path.abspath(config.ServerRoot),
        }
        configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        origUsersFile = FilePath(__file__).sibling(
            "deprovision").child("users-groups.xml")
        copyUsersFile = FilePath(config.DataRoot).child("accounts.xml")
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(__file__).sibling(
            "deprovision").child("resources-locations.xml")
        copyResourcesFile = FilePath(config.DataRoot).child("resources.xml")
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(__file__).sibling(
            "deprovision").child("augments.xml")
        copyAugmentFile = FilePath(config.DataRoot).child("augments.xml")
        origAugmentFile.copyTo(copyAugmentFile)

        self.rootResource = getRootResource(config)
        self.directory = self.rootResource.getDirectory()

        # Make sure trial puts the reactor in the right state, by letting it
        # run one reactor iteration.  (Ignore me, please.)
        d = Deferred()
        reactor.callLater(0, d.callback, True)
        return d
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:40,代码来源:test_purge.py

示例12: TestCase

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
class TestCase(twext.web2.dav.test.util.TestCase):
    resource_class = RootResource

    def createStockDirectoryService(self):
        """
        Create a stock C{directoryService} attribute and assign it.
        """
        self.xmlFile = FilePath(config.DataRoot).child("accounts.xml")
        self.xmlFile.setContent(xmlFile.getContent())

        # *temporarily* set up an augment service so this directory service will
        # work.
        self.patch(augment, "AugmentService", augment.AugmentXMLDB(
                xmlFiles=(augmentsFile.path,)
            )
        )

        self.directoryService = XMLDirectoryService(
            {'xmlFile' : "accounts.xml"}
        )

        # FIXME: see FIXME in DirectoryPrincipalProvisioningResource.__init__;
        # this performs a necessary modification to the directory service
        # object for it to be fully functional.
        self.principalsResource = DirectoryPrincipalProvisioningResource(
            "/principals/", self.directoryService
        )


    def createDataStore(self):
        """
        Create an L{IDataStore} that can store calendars (but not
        addressbooks.)  By default returns a L{CommonDataStore}, but this is a
        hook for subclasses to override to provide different data stores.
        """
        return CommonDataStore(FilePath(config.DocumentRoot), None, True, False)


    def setupCalendars(self):
        """
        Set up the resource at /calendars (a L{DirectoryCalendarHomeProvisioningResource}),
        and assign it as C{self.calendarCollection}.
        """

        # Need a data store
        _newStore = self.createDataStore()

        self.calendarCollection = DirectoryCalendarHomeProvisioningResource(
            self.directoryService,
            "/calendars/",
            _newStore
        )
        self.site.resource.putChild("calendars", self.calendarCollection)

        self.addressbookCollection = DirectoryAddressBookHomeProvisioningResource(
            self.directoryService,
            "/addressbooks/",
            _newStore
        )
        self.site.resource.putChild("addressbooks", self.addressbookCollection)


    def setUp(self):
        super(TestCase, self).setUp()

        # FIXME: this is only here to workaround circular imports
        doBind()

        config.reset()
        serverroot = self.mktemp()
        os.mkdir(serverroot)
        config.ServerRoot = os.path.abspath(serverroot)
        config.ConfigRoot = "config"
        config.LogRoot = "logs"
        config.RunRoot = "logs"

        if not os.path.exists(config.DataRoot):
            os.makedirs(config.DataRoot)
        if not os.path.exists(config.DocumentRoot):
            os.makedirs(config.DocumentRoot)
        if not os.path.exists(config.ConfigRoot):
            os.makedirs(config.ConfigRoot)
        if not os.path.exists(config.LogRoot):
            os.makedirs(config.LogRoot)

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True

        config.DirectoryAddressBook.Enabled = False


    def createHierarchy(self, structure, root=None):
        if root is None:
            root = self.mktemp()
            os.mkdir(root)

        def createChildren(parent, subStructure):
            for childName, childStructure in subStructure.iteritems():
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:103,代码来源:util.py

示例13: TestCase

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
class TestCase(twext.web2.dav.test.util.TestCase):
    resource_class = RootResource

    def createDataStore(self):
        """
        Create an L{IDataStore} that can store calendars (but not
        addressbooks.)  By default returns a L{CommonDataStore}, but this is a
        hook for subclasses to override to provide different data stores.
        """
        return CommonDataStore(FilePath(config.DocumentRoot), None, None, True, False,
                               quota=deriveQuota(self))


    def createStockDirectoryService(self):
        """
        Create a stock C{directoryService} attribute and assign it.
        """
        self.xmlFile = FilePath(config.DataRoot).child("accounts.xml")
        self.xmlFile.setContent(xmlFile.getContent())
        self.directoryFixture.addDirectoryService(XMLDirectoryService({
            "xmlFile": "accounts.xml",
            "augmentService":
                augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
        }))


    def setupCalendars(self):
        """
        When a directory service exists, set up the resources at C{/calendars}
        and C{/addressbooks} (a L{DirectoryCalendarHomeProvisioningResource}
        and L{DirectoryAddressBookHomeProvisioningResource} respectively), and
        assign them to the C{self.calendarCollection} and
        C{self.addressbookCollection} attributes.

        A directory service may be associated with this L{TestCase} with
        L{TestCase.createStockDirectoryService} or
        L{TestCase.directoryFixture.addDirectoryService}.
        """
        newStore = self.createDataStore()
        @self.directoryFixture.whenDirectoryServiceChanges
        def putAllChildren(ds):
            self.calendarCollection = (
                DirectoryCalendarHomeProvisioningResource(
                    ds, "/calendars/", newStore
                ))
            self.site.resource.putChild("calendars", self.calendarCollection)
            self.addressbookCollection = (
                DirectoryAddressBookHomeProvisioningResource(
                    ds, "/addressbooks/", newStore
                ))
            self.site.resource.putChild("addressbooks",
                                        self.addressbookCollection)


    def configure(self):
        """
        Adjust the global configuration for this test.
        """
        config.reset()

        config.ServerRoot = os.path.abspath(self.serverRoot)
        config.ConfigRoot = "config"
        config.LogRoot = "logs"
        config.RunRoot = "logs"

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True
        memcacher.Memcacher.memoryCacheInstance = None
        config.DirectoryAddressBook.Enabled = False
        config.UsePackageTimezones = True


    @property
    def directoryService(self):
        """
        Read-only alias for L{DirectoryFixture.directoryService} for
        compatibility with older tests.  TODO: remove this.
        """
        return self.directoryFixture.directoryService


    def setUp(self):
        super(TestCase, self).setUp()

        self.directoryFixture = DirectoryFixture()

        # FIXME: this is only here to workaround circular imports
        doBind()

        self.serverRoot = self.mktemp()
        os.mkdir(self.serverRoot)

        self.configure()

        if not os.path.exists(config.DataRoot):
            os.makedirs(config.DataRoot)
        if not os.path.exists(config.DocumentRoot):
            os.makedirs(config.DocumentRoot)
#.........这里部分代码省略.........
开发者ID:anemitz,项目名称:calendarserver,代码行数:103,代码来源:util.py

示例14: setUp

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
    def setUp(self):

        self.serverRoot = self.mktemp()
        os.mkdir(self.serverRoot)
        self.absoluteServerRoot = os.path.abspath(self.serverRoot)

        configRoot = os.path.join(self.absoluteServerRoot, "Config")
        if not os.path.exists(configRoot):
            os.makedirs(configRoot)

        dataRoot = os.path.join(self.absoluteServerRoot, "Data")
        if not os.path.exists(dataRoot):
            os.makedirs(dataRoot)

        documentRoot = os.path.join(self.absoluteServerRoot, "Documents")
        if not os.path.exists(documentRoot):
            os.makedirs(documentRoot)

        logRoot = os.path.join(self.absoluteServerRoot, "Logs")
        if not os.path.exists(logRoot):
            os.makedirs(logRoot)

        runRoot = os.path.join(self.absoluteServerRoot, "Run")
        if not os.path.exists(runRoot):
            os.makedirs(runRoot)

        config.reset()

        testRoot = os.path.join(os.path.dirname(__file__), "gateway")
        templateName = os.path.join(testRoot, "caldavd.plist")
        templateFile = open(templateName)
        template = templateFile.read()
        templateFile.close()

        databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
        newConfig = template % {
            "ServerRoot": self.absoluteServerRoot,
            "DataRoot": dataRoot,
            "DatabaseRoot": databaseRoot,
            "DocumentRoot": documentRoot,
            "ConfigRoot": configRoot,
            "LogRoot": logRoot,
            "RunRoot": runRoot,
            "WritablePlist": os.path.join(
                os.path.abspath(configRoot), "caldavd-writable.plist"
            ),
        }
        configFilePath = FilePath(
            os.path.join(configRoot, "caldavd.plist")
        )

        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True
        memcacher.Memcacher.reset()
        config.DirectoryAddressBook.Enabled = False
        config.UsePackageTimezones = True

        origUsersFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "users-groups.xml"
            )
        )
        copyUsersFile = FilePath(
            os.path.join(config.DataRoot, "accounts.xml")
        )
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "resources-locations.xml"
            )
        )
        copyResourcesFile = FilePath(
            os.path.join(config.DataRoot, "resources.xml")
        )
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "augments.xml"
            )
        )
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        self.notifierFactory = StubNotifierFactory()
        self.store = yield theStoreBuilder.buildStore(self, self.notifierFactory)
#.........这里部分代码省略.........
开发者ID:eventable,项目名称:CalendarServer,代码行数:103,代码来源:test_gateway.py

示例15: buildTestDirectory

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import setContent [as 别名]
def buildTestDirectory(
    store, dataRoot, accounts=None, resources=None, augments=None, proxies=None,
    serversDB=None
):
    """
    @param store: the store for the directory to use

    @param dataRoot: the directory to copy xml files to

    @param accounts: path to the accounts.xml file
    @type accounts: L{FilePath}

    @param resources: path to the resources.xml file
    @type resources: L{FilePath}

    @param augments: path to the augments.xml file
    @type augments: L{FilePath}

    @param proxies: path to the proxies.xml file
    @type proxies: L{FilePath}

    @return: the directory service
    @rtype: L{IDirectoryService}
    """

    defaultDirectory = FilePath(__file__).sibling("accounts")
    if accounts is None:
        accounts = defaultDirectory.child("accounts.xml")
    if resources is None:
        resources = defaultDirectory.child("resources.xml")
    if augments is None:
        augments = defaultDirectory.child("augments.xml")
    if proxies is None:
        proxies = defaultDirectory.child("proxies.xml")

    if not os.path.exists(dataRoot):
        os.makedirs(dataRoot)

    accountsCopy = FilePath(dataRoot).child("accounts.xml")
    accountsCopy.setContent(accounts.getContent())

    resourcesCopy = FilePath(dataRoot).child("resources.xml")
    resourcesCopy.setContent(resources.getContent())

    augmentsCopy = FilePath(dataRoot).child("augments.xml")
    augmentsCopy.setContent(augments.getContent())

    proxiesCopy = FilePath(dataRoot).child("proxies.xml")
    proxiesCopy.setContent(proxies.getContent())

    servicesInfo = (
        ConfigDict(
            {
                "Enabled": True,
                "type": "xml",
                "params": {
                    "xmlFile": "accounts.xml",
                    "recordTypes": ("users", "groups"),
                },
            }
        ),
        ConfigDict(
            {
                "Enabled": True,
                "type": "xml",
                "params": {
                    "xmlFile": "resources.xml",
                    "recordTypes": ("locations", "resources", "addresses"),
                },
            }
        ),
    )
    augmentServiceInfo = ConfigDict(
        {
            "type": "twistedcaldav.directory.augment.AugmentXMLDB",
            "params": {
                "xmlFiles": ["augments.xml", ],
                "statSeconds": 15,
            },
        }
    )
    wikiServiceInfo = ConfigDict(
        {
            "Enabled": True,
            "CollabHost": "localhost",
            "CollabPort": 4444,
        }
    )
    directory = buildDirectory(
        store, dataRoot, servicesInfo, augmentServiceInfo, wikiServiceInfo,
        serversDB
    )

    store.setDirectoryService(directory)

    return directory
开发者ID:nunb,项目名称:calendarserver,代码行数:98,代码来源:util.py


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