本文整理汇总了Python中twext.python.filepath.CachingFilePath类的典型用法代码示例。如果您正苦于以下问题:Python CachingFilePath类的具体用法?Python CachingFilePath怎么用?Python CachingFilePath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CachingFilePath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: buildStore
def buildStore(self, testCase, notifierFactory):
"""
Do the necessary work to build a store for a particular test case.
@return: a L{Deferred} which fires with an L{IDataStore}.
"""
disableMemcacheForTest(testCase)
dbRoot = CachingFilePath(self.SHARED_DB_PATH)
attachmentRoot = dbRoot.child("attachments")
if self.sharedService is None:
ready = Deferred()
def getReady(connectionFactory):
self.makeAndCleanStore(
testCase, notifierFactory, attachmentRoot
).chainDeferred(ready)
return Service()
self.sharedService = self.createService(getReady)
self.sharedService.startService()
def startStopping():
log.msg("Starting stopping.")
self.sharedService.unpauseMonitor()
return self.sharedService.stopService()
reactor.addSystemEventTrigger(#@UndefinedVariable
"before", "shutdown", startStopping)
result = ready
else:
result = self.makeAndCleanStore(
testCase, notifierFactory, attachmentRoot
)
def cleanUp():
def stopit():
self.sharedService.pauseMonitor()
return deferLater(reactor, 0.1, stopit)
testCase.addCleanup(cleanUp)
return result
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:35,代码来源:util.py
示例2: test_fileStoreFromPath
def test_fileStoreFromPath(self):
"""
Verify that fileStoreFromPath() will return a CommonDataStore if
the given path contains either "calendars" or "addressbooks"
sub-directories. Otherwise it returns None
"""
# No child directories
docRootPath = CachingFilePath(self.mktemp())
docRootPath.createDirectory()
step = UpgradeToDatabaseStep.fileStoreFromPath(docRootPath)
self.assertEquals(step, None)
# "calendars" child directory exists
childPath = docRootPath.child("calendars")
childPath.createDirectory()
step = UpgradeToDatabaseStep.fileStoreFromPath(docRootPath)
self.assertTrue(isinstance(step, CommonDataStore))
childPath.remove()
# "addressbooks" child directory exists
childPath = docRootPath.child("addressbooks")
childPath.createDirectory()
step = UpgradeToDatabaseStep.fileStoreFromPath(docRootPath)
self.assertTrue(isinstance(step, CommonDataStore))
childPath.remove()
开发者ID:eventable,项目名称:CalendarServer,代码行数:26,代码来源:test_migrate.py
示例3: _connectorFor_pg8000
def _connectorFor_pg8000(dbmodule, **kwargs):
"""
Turn properties into pg8000 kwargs
"""
params = DBAPIParameters(**kwargs)
dbkwargs = {
"user": params.user,
"password": params.password,
"database": params.database,
}
if params.unixsocket:
dbkwargs["unix_sock"] = params.unixsocket
# We're using a socket file
socketFP = CachingFilePath(dbkwargs["unix_sock"])
if socketFP.isdir():
# We have been given the directory, not the actual socket file
socketFP = socketFP.child(".s.PGSQL.{}".format(params.port if params.port else "5432"))
dbkwargs["unix_sock"] = socketFP.path
if not socketFP.isSocket():
raise InternalDataStoreError(
"No such socket file: {}".format(socketFP.path)
)
else:
dbkwargs["host"] = params.host
if params.port:
dbkwargs["port"] = int(params.port)
return DBAPIConnector(dbmodule, postgresPreflight, **dbkwargs)
开发者ID:eventable,项目名称:CalendarServer,代码行数:30,代码来源:dbapiclient.py
示例4: ready
def ready(self, createDatabaseConn, createDatabaseCursor):
"""
Subprocess is ready. Time to initialize the subservice.
If the database has not been created and there is a dump file,
then the dump file is imported.
"""
if self.resetSchema:
try:
createDatabaseCursor.execute(
"drop database {}".format(self.databaseName)
)
except pgdb.DatabaseError:
pass
try:
createDatabaseCursor.execute(
"create database {} with encoding 'UTF8'"
.format(self.databaseName)
)
except:
# database already exists
executeSQL = False
else:
# database does not yet exist; if dump file exists, execute it,
# otherwise execute schema
executeSQL = True
sqlToExecute = self.schema
if self.importFileName:
importFilePath = CachingFilePath(self.importFileName)
if importFilePath.exists():
sqlToExecute = importFilePath.getContent()
createDatabaseCursor.close()
createDatabaseConn.close()
if executeSQL:
connection = self.produceConnection()
cursor = connection.cursor()
cursor.execute(sqlToExecute)
connection.commit()
connection.close()
if self.shutdownDeferred is None:
# Only continue startup if we've not begun shutdown
self.subServiceFactory(
self.produceConnection, self
).setServiceParent(self)
开发者ID:nunb,项目名称:calendarserver,代码行数:48,代码来源:subpostgres.py
示例5: setUp
def setUp(self):
"""
Set up two stores to migrate between.
"""
# Add some files to the file store.
self.filesPath = CachingFilePath(self.mktemp())
self.filesPath.createDirectory()
fileStore = self.fileStore = CommonDataStore(
self.filesPath, {"push": StubNotifierFactory()}, TestStoreDirectoryService(), True, True
)
self.sqlStore = yield theStoreBuilder.buildStore(
self, StubNotifierFactory()
)
self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore)
requirements = CommonTests.requirements
extras = deriveValue(self, "extraRequirements", lambda t: {})
requirements = self.mergeRequirements(requirements, extras)
yield populateCalendarsFrom(requirements, fileStore)
md5s = CommonTests.md5s
yield resetCalendarMD5s(md5s, fileStore)
self.filesPath.child("calendars").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
requirements = ABCommonTests.requirements
yield populateAddressBooksFrom(requirements, fileStore)
md5s = ABCommonTests.md5s
yield resetAddressBookMD5s(md5s, fileStore)
self.filesPath.child("addressbooks").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:test_migrate.py
示例6: setUp
def setUp(self):
"""
Create a L{CachingFilePath} for the test to use.
"""
self.cfp = CachingFilePath(self.mktemp())
self.clock = Clock()
self.cfp._sleep = self.clock.advance
开发者ID:jrossi,项目名称:twext,代码行数:7,代码来源:test_filepath.py
示例7: setUp
def setUp(self):
"""
Set up two stores to migrate between.
"""
# Add some files to the file store.
self.filesPath = CachingFilePath(self.mktemp())
self.filesPath.createDirectory()
fileStore = self.fileStore = CommonDataStore(
self.filesPath, {"push": StubNotifierFactory()}, TestStoreDirectoryService(), True, True
)
self.sqlStore = yield theStoreBuilder.buildStore(
self, StubNotifierFactory()
)
self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore)
requirements = CommonTests.requirements
extras = deriveValue(self, "extraRequirements", lambda t: {})
requirements = self.mergeRequirements(requirements, extras)
yield populateCalendarsFrom(requirements, fileStore)
md5s = CommonTests.md5s
yield resetCalendarMD5s(md5s, fileStore)
self.filesPath.child("calendars").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
requirements = ABCommonTests.requirements
yield populateAddressBooksFrom(requirements, fileStore)
md5s = ABCommonTests.md5s
yield resetAddressBookMD5s(md5s, fileStore)
self.filesPath.child("addressbooks").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
# Add some properties we want to check get migrated over
txn = self.fileStore.newTransaction()
home = yield txn.calendarHomeWithUID("home_defaults")
cal = yield home.calendarWithName("calendar_1")
props = cal.properties()
props[PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet)] = caldavxml.SupportedCalendarComponentSet(
caldavxml.CalendarComponent(name="VEVENT"),
caldavxml.CalendarComponent(name="VTODO"),
)
props[PropertyName.fromElement(element.ResourceType)] = element.ResourceType(
element.Collection(),
caldavxml.Calendar(),
)
props[PropertyName.fromElement(customxml.GETCTag)] = customxml.GETCTag.fromString("foobar")
inbox = yield home.calendarWithName("inbox")
props = inbox.properties()
props[PropertyName.fromElement(customxml.CalendarAvailability)] = customxml.CalendarAvailability.fromString(str(self.av1))
props[PropertyName.fromElement(caldavxml.ScheduleDefaultCalendarURL)] = caldavxml.ScheduleDefaultCalendarURL(
element.HRef.fromString("/calendars/__uids__/home_defaults/calendar_1"),
)
yield txn.commit()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:59,代码来源:test_migrate.py
示例8: setUp
def setUp(self):
"""
Set up two stores to migrate between.
"""
# Add some files to the file store.
self.filesPath = CachingFilePath(self.mktemp())
self.filesPath.createDirectory()
fileStore = self.fileStore = CommonDataStore(
self.filesPath, StubNotifierFactory(), True, True
)
self.sqlStore = yield theStoreBuilder.buildStore(
self, StubNotifierFactory()
)
subStarted = self.subStarted = Deferred()
class StubService(Service, object):
def startService(self):
super(StubService, self).startService()
if not subStarted.called:
subStarted.callback(None)
from twisted.python import log
def justOnce(evt):
if evt.get('isError') and not hasattr(subStarted, 'result'):
subStarted.errback(
evt.get('failure',
RuntimeError("error starting up (see log)"))
)
log.addObserver(justOnce)
def cleanObserver():
try:
log.removeObserver(justOnce)
except ValueError:
pass # x not in list, I don't care.
self.addCleanup(cleanObserver)
self.stubService = StubService()
self.topService = MultiService()
self.upgrader = self.createUpgradeService()
self.upgrader.setServiceParent(self.topService)
requirements = CommonTests.requirements
extras = deriveValue(self, "extraRequirements", lambda t: {})
requirements = self.mergeRequirements(requirements, extras)
yield populateCalendarsFrom(requirements, fileStore)
md5s = CommonTests.md5s
yield resetCalendarMD5s(md5s, fileStore)
self.filesPath.child("calendars").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
requirements = ABCommonTests.requirements
yield populateAddressBooksFrom(requirements, fileStore)
md5s = ABCommonTests.md5s
yield resetAddressBookMD5s(md5s, fileStore)
self.filesPath.child("addressbooks").child(
"__uids__").child("ho").child("me").child("home1").child(
".some-extra-data").setContent("some extra data")
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:57,代码来源:test_migrate.py
示例9: __init__
def __init__(self, attachment, contentType, dispositionName, creating=False, migrating=False):
super(AttachmentStorageTransport, self).__init__(
attachment, contentType, dispositionName)
fileDescriptor, fileName = self._temporaryFile()
# Wrap the file descriptor in a file object we can write to
self._file = os.fdopen(fileDescriptor, "w")
self._path = CachingFilePath(fileName)
self._hash = hashlib.md5()
self._creating = creating
self._migrating = migrating
self._txn.postAbort(self.aborted)
开发者ID:red-hood,项目名称:calendarserver,代码行数:13,代码来源:sql_attachment.py
示例10: __init__
def __init__(self, dataStoreDirectory, subServiceFactory,
schema, databaseName='subpostgres', resetSchema=False,
logFile="postgres.log", testMode=False,
uid=None, gid=None):
"""
Initialize a L{PostgresService} pointed at a data store directory.
@param dataStoreDirectory: the directory to
@type dataStoreDirectory: L{twext.python.filepath.CachingFilePath}
@param subServiceFactory: a 1-arg callable that will be called with a
1-arg callable which returns a DB-API cursor.
@type subServiceFactory: C{callable}
"""
MultiService.__init__(self)
self.subServiceFactory = subServiceFactory
self.dataStoreDirectory = dataStoreDirectory
self.resetSchema = resetSchema
if os.getuid() == 0:
socketRoot = "/var/run"
else:
socketRoot = "/tmp"
self.socketDir = CachingFilePath("%s/ccs_postgres_%s/" %
(socketRoot, md5(dataStoreDirectory.path).hexdigest()))
self.databaseName = databaseName
self.logFile = logFile
self.uid = uid
self.gid = gid
self.schema = schema
self.monitor = None
self.openConnections = []
# FIXME: By default there is very little (4MB) shared memory available,
# so at the moment I am lowering these postgres config options to allow
# multiple servers to run. We might want to look into raising
# kern.sysv.shmmax.
# See: http://www.postgresql.org/docs/8.4/static/kernel-resources.html
if testMode:
self.sharedBuffers = 16
self.maxConnections = 2
else:
self.sharedBuffers = 30
self.maxConnections = 20
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:44,代码来源:subpostgres.py
示例11: configure
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,代码行数:33,代码来源:util.py
示例12: setUp
def setUp(self):
tempDir = FilePath(self.mktemp())
tempDir.makedirs()
tempFile = tempDir.child("test")
tempFile.touch()
self.propertyStore = self.propertyStore1 = PropertyStore("user01", "user01", lambda : tempFile)
self.propertyStore2 = PropertyStore("user02", "user01", lambda : tempFile)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:7,代码来源:test_xattr.py
示例13: setUp
def setUp(self):
"""
Replace self.site.resource with an appropriately provisioned
AddressBookHomeFile, and replace self.docroot with a path pointing at that
file.
"""
super(AddressBookHomeTestCase, self).setUp()
fp = FilePath(self.mktemp())
fp.createDirectory()
self.createStockDirectoryService()
# Need a data store
_newStore = CommonDataStore(fp, None, True, False)
self.homeProvisioner = DirectoryAddressBookHomeProvisioningResource(
self.directoryService, "/addressbooks/",
_newStore
)
def _defer(user):
# Commit the transaction
self.site.resource._associatedTransaction.commit()
self.docroot = user._newStoreHome._path.path
return self._refreshRoot().addCallback(_defer)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:util.py
示例14: test_collection_in_calendar
def test_collection_in_calendar(self):
"""
Make (regular) collection in calendar
"""
calendar_path, calendar_uri = self.mkdtemp("collection_in_calendar")
calPath = FilePath(calendar_path)
calPath.remove()
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
def mkcol_cb(response):
response = IResponse(response)
if response.code != responsecode.FORBIDDEN:
self.fail("Incorrect response to nested MKCOL: %s" % (response.code,))
nested_uri = "/".join([calendar_uri, "nested"])
request = SimpleRequest(self.site, "MKCOL", nested_uri)
self.send(request, mkcol_cb)
request = SimpleRequest(self.site, "MKCALENDAR", calendar_uri)
return self.send(request, mkcalendar_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:test_collectioncontents.py
示例15: __init__
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,代码行数:58,代码来源:xmlfile.py
示例16: test_shouldReparse
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,代码行数:10,代码来源:test_augment.py
示例17: test_parseNonASCIIConfig
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,代码行数:11,代码来源:test_stdconfig.py
示例18: setUp
def setUp(self):
yield super(GroupShareeTestBase, self).setUp()
accountsFilePath = FilePath(
os.path.join(os.path.dirname(__file__), "accounts")
)
yield self.buildStoreAndDirectory(
accounts=accountsFilePath.child("groupAccounts.xml"),
)
yield self.populate()
self.paths = {}
开发者ID:eventable,项目名称:CalendarServer,代码行数:12,代码来源:test_group_sharees.py
示例19: test_copy
def test_copy(self):
tempDir = FilePath(self.mktemp())
tempDir.makedirs()
tempFile1 = tempDir.child("test1")
tempFile1.touch()
tempFile2 = tempDir.child("test2")
tempFile2.touch()
# Existing store
store1_user1 = PropertyStore("user01", lambda : tempFile1)
store1_user2 = PropertyStore("user01", lambda : tempFile1)
store1_user2._setPerUserUID("user02")
# New store
store2_user1 = PropertyStore("user01", lambda : tempFile2)
store2_user2 = PropertyStore("user01", lambda : tempFile2)
store2_user2._setPerUserUID("user02")
# Populate current store with data
class DummyProperty1(WebDAVTextElement):
namespace = "http://calendarserver.org/ns/"
name = "dummy1"
class DummyProperty2(WebDAVTextElement):
namespace = "http://calendarserver.org/ns/"
name = "dummy2"
class DummyProperty3(WebDAVTextElement):
namespace = "http://calendarserver.org/ns/"
name = "dummy3"
props_user1 = (
DummyProperty1.fromString("value1-user1"),
DummyProperty2.fromString("value2-user1"),
)
props_user2 = (
DummyProperty1.fromString("value1-user2"),
DummyProperty3.fromString("value3-user2"),
)
for prop in props_user1:
store1_user1[PropertyName.fromElement(prop)] = prop
for prop in props_user2:
store1_user2[PropertyName.fromElement(prop)] = prop
store1_user1.flush()
store1_user2.flush()
# Do copy and check results
store2_user1.copyAllProperties(store1_user1)
store2_user1.flush()
self.assertEqual(store1_user1.attrs.items(), store2_user1.attrs.items())
self.assertEqual(store1_user2.attrs.items(), store2_user2.attrs.items())
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:52,代码来源:test_xattr.py
示例20: setUp
def setUp(self):
tempDir = FilePath(self.mktemp())
tempDir.makedirs()
tempFile = tempDir.child("test")
tempFile.touch()
self.propertyStore = PropertyStore("user01", lambda : tempFile)
self.propertyStore1 = self.propertyStore
self.propertyStore2 = PropertyStore("user01", lambda : tempFile)
self.propertyStore2._setPerUserUID("user02")
self.propertyStore2._setProxyUID("user02")
self.propertyStore3 = PropertyStore("user01", lambda : tempFile)
self.propertyStore3._setProxyUID("user03")
self.propertyStore4 = PropertyStore("user01", lambda : tempFile)
self.propertyStore4._setPerUserUID("user02")
self.propertyStore4._setProxyUID("user04")
开发者ID:nunb,项目名称:calendarserver,代码行数:15,代码来源:test_xattr.py
注:本文中的twext.python.filepath.CachingFilePath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论