本文整理汇总了Python中twext.python.filepath.CachingFilePath.createDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python CachingFilePath.createDirectory方法的具体用法?Python CachingFilePath.createDirectory怎么用?Python CachingFilePath.createDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twext.python.filepath.CachingFilePath
的用法示例。
在下文中一共展示了CachingFilePath.createDirectory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
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)
示例2: test_fileStoreFromPath
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
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()
示例3: doDirectoryTest
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
def doDirectoryTest(self, addedNames, modify=lambda x: None,
expectedNames=None):
"""
Do a test of a L{DAVFile} pointed at a directory, verifying that files
existing with the given names will be faithfully 'played back' via HTML
rendering.
"""
if expectedNames is None:
expectedNames = addedNames
fp = FilePath(self.mktemp())
fp.createDirectory()
for sampleName in expectedNames:
fp.child(sampleName).touch()
df = DAVFile(fp)
modify(df)
responseText = (yield df.render(SimpleFakeRequest('/'))).stream.read()
responseXML = browserHTML2ETree(responseText)
names = set([element.text.encode("utf-8")
for element in responseXML.findall(".//a")])
self.assertEquals(set(expectedNames), names)
示例4: test_triggerGroupCacherUpdate
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
def test_triggerGroupCacherUpdate(self):
"""
Verify triggerGroupCacherUpdate can read a pidfile and send a SIGHUP
"""
self.calledArgs = None
def killMethod(pid, sig):
self.calledArgs = (pid, sig)
class StubConfig(object):
def __init__(self, runRootPath):
self.RunRoot = runRootPath
runRootDir = FilePath(self.mktemp())
runRootDir.createDirectory()
pidFile = runRootDir.child("groupcacher.pid")
pidFile.setContent("1234")
testConfig = StubConfig(runRootDir.path)
triggerGroupCacherUpdate(testConfig, killMethod=killMethod)
self.assertEquals(self.calledArgs, (1234, signal.SIGHUP))
runRootDir.remove()
示例5: PostgresService
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
#.........这里部分代码省略.........
statusMonitor = CapturingProcessProtocol(d, None)
self.reactor.spawnProcess(
statusMonitor, pgCtl, [pgCtl, "status"],
env=self.env, path=self.workingDir.path,
uid=self.uid, gid=self.gid,
)
return d.addCallback(gotStatus).addErrback(giveUp)
def giveUp(f):
"""
We can't start postgres or connect to a running instance. Shut
down.
"""
log.failure("Can't start or connect to postgres", f)
self.deactivateDelayedShutdown()
self.reactor.stop()
self.monitor.completionDeferred.addCallback(
gotReady).addErrback(couldNotStart)
shouldStopDatabase = False
def startService(self):
MultiService.startService(self)
self.activateDelayedShutdown()
clusterDir = self.dataStoreDirectory.child(self.clusterName)
env = self.env = os.environ.copy()
env.update(PGDATA=clusterDir.path,
PGHOST=self.host,
PGUSER=self.spawnedDBUser)
initdb = self.initdb()
if self.socketDir:
if not self.socketDir.isdir():
self.socketDir.createDirectory()
if self.uid and self.gid:
os.chown(self.socketDir.path, self.uid, self.gid)
if self.dataStoreDirectory.isdir():
self.startDatabase()
else:
self.dataStoreDirectory.createDirectory()
if not self.workingDir.isdir():
self.workingDir.createDirectory()
if self.uid and self.gid:
os.chown(self.dataStoreDirectory.path, self.uid, self.gid)
os.chown(self.workingDir.path, self.uid, self.gid)
dbInited = Deferred()
self.reactor.spawnProcess(
CapturingProcessProtocol(dbInited, None),
initdb, [initdb, "-E", "UTF8", "-U", self.spawnedDBUser],
env=env, path=self.workingDir.path,
uid=self.uid, gid=self.gid,
)
def doCreate(result):
if result.find("FATAL:") != -1:
log.error(result)
raise RuntimeError("Unable to initialize postgres database: %s" % (result,))
self.startDatabase()
dbInited.addCallback(doCreate)
def stopService(self):
"""
Stop all child services, then stop the subprocess, if it's running.
"""
if self.delayedShutdown:
示例6: createDataStore
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
def createDataStore(self):
# FIXME: AddressBookHomeTestCase needs the same treatment.
fp = FilePath(self.mktemp())
fp.createDirectory()
return CommonDataStore(fp, None, True, False)
示例7: PostgresService
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
#.........这里部分代码省略.........
uid=self.uid, gid=self.gid,
)
return d.addCallback(gotStatus).addErrback(giveUp)
def giveUp(f):
"""
We can't start postgres or connect to a running instance. Shut
down.
"""
log.critical(
"Can't start or connect to postgres: {failure.value}",
failure=f
)
self.deactivateDelayedShutdown()
self.reactor.stop()
self.monitor.completionDeferred.addCallback(
gotReady).addErrback(couldNotStart)
shouldStopDatabase = False
def startService(self):
MultiService.startService(self)
self.activateDelayedShutdown()
clusterDir = self.dataStoreDirectory.child(self.clusterName)
env = self.env = os.environ.copy()
env.update(PGDATA=clusterDir.path,
PGHOST=self.host,
PGUSER=self.spawnedDBUser)
if self.socketDir:
if not self.socketDir.isdir():
log.info("Creating {dir}", dir=self.socketDir.path.decode("utf-8"))
self.socketDir.createDirectory()
if self.uid and self.gid:
os.chown(self.socketDir.path, self.uid, self.gid)
os.chmod(self.socketDir.path, 0770)
if not self.dataStoreDirectory.isdir():
log.info("Creating {dir}", dir=self.dataStoreDirectory.path.decode("utf-8"))
self.dataStoreDirectory.createDirectory()
if not self.workingDir.isdir():
log.info("Creating {dir}", dir=self.workingDir.path.decode("utf-8"))
self.workingDir.createDirectory()
if self.uid and self.gid:
os.chown(self.dataStoreDirectory.path, self.uid, self.gid)
os.chown(self.workingDir.path, self.uid, self.gid)
if not clusterDir.isdir():
# No cluster directory, run initdb
log.info("Running initdb for {dir}", dir=clusterDir.path.decode("utf-8"))
dbInited = Deferred()
self.reactor.spawnProcess(
CapturingProcessProtocol(dbInited, None),
self._initdb,
[self._initdb, "-E", "UTF8", "-U", self.spawnedDBUser],
env=env, path=self.workingDir.path,
uid=self.uid, gid=self.gid,
)
def doCreate(result):
if result.find("FATAL:") != -1:
示例8: PostgresService
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
#.........这里部分代码省略.........
def pauseMonitor(self):
"""
Pause monitoring. This is a testing hook for when (if) we are
continuously monitoring output from the 'postgres' process.
"""
# for pipe in self.monitor.transport.pipes.values():
# pipe.stopReading()
# pipe.stopWriting()
def unpauseMonitor(self):
"""
Unpause monitoring.
@see: L{pauseMonitor}
"""
# for pipe in self.monitor.transport.pipes.values():
# pipe.startReading()
# pipe.startWriting()
def startDatabase(self):
"""
Start the database and initialize the subservice.
"""
monitor = _PostgresMonitor(self)
pg_ctl = which("pg_ctl")[0]
# check consistency of initdb and postgres?
reactor.spawnProcess(
monitor, pg_ctl,
[
pg_ctl,
"start",
"-l", self.logFile,
"-w",
# XXX what are the quoting rules for '-o'? do I need to repr()
# the path here?
"-o", "-c listen_addresses='' -k '%s' -c standard_conforming_strings=on -c shared_buffers=%d -c max_connections=%d"
% (self.socketDir.path, self.sharedBuffers, self.maxConnections),
],
self.env,
uid=self.uid, gid=self.gid,
)
self.monitor = monitor
def gotReady(result):
self.ready()
def reportit(f):
log.err(f)
self.monitor.completionDeferred.addCallback(
gotReady).addErrback(reportit)
def startService(self):
MultiService.startService(self)
clusterDir = self.dataStoreDirectory.child("cluster")
workingDir = self.dataStoreDirectory.child("working")
env = self.env = os.environ.copy()
env.update(PGDATA=clusterDir.path,
PGHOST=self.socketDir.path)
initdb = which("initdb")[0]
if not self.socketDir.isdir():
self.socketDir.createDirectory()
if self.uid and self.gid:
os.chown(self.socketDir.path, self.uid, self.gid)
if self.dataStoreDirectory.isdir():
self.startDatabase()
else:
self.dataStoreDirectory.createDirectory()
workingDir.createDirectory()
if self.uid and self.gid:
os.chown(self.dataStoreDirectory.path, self.uid, self.gid)
os.chown(workingDir.path, self.uid, self.gid)
dbInited = Deferred()
reactor.spawnProcess(
CapturingProcessProtocol(dbInited, None),
initdb, [initdb], env, workingDir.path,
uid=self.uid, gid=self.gid,
)
def doCreate(result):
self.startDatabase()
dbInited.addCallback(doCreate)
def stopService(self):
"""
Stop all child services, then stop the subprocess, if it's running.
"""
d = MultiService.stopService(self)
def superStopped(result):
# Probably want to stop and wait for startup if that hasn't
# completed yet...
monitor = _PostgresMonitor()
pg_ctl = which("pg_ctl")[0]
reactor.spawnProcess(monitor, pg_ctl,
[pg_ctl, '-l', 'logfile', 'stop'],
self.env,
uid=self.uid, gid=self.gid,
)
return monitor.completionDeferred
return d.addCallback(superStopped)
示例9: HomeMigrationTests
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
class HomeMigrationTests(CommonCommonTests, TestCase):
"""
Tests for L{UpgradeToDatabaseStep}.
"""
av1 = Component.fromString("""BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//calendarserver.org//Zonal//EN
BEGIN:VAVAILABILITY
ORGANIZER:mailto:[email protected]
UID:[email protected]
DTSTAMP:20061005T133225Z
DTEND:20140101T000000Z
BEGIN:AVAILABLE
UID:[email protected]
DTSTAMP:20061005T133225Z
SUMMARY:Monday to Friday from 9:00 to 17:00
DTSTART:20130101T090000Z
DTEND:20130101T170000Z
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
END:AVAILABLE
END:VAVAILABILITY
END:VCALENDAR
""")
@inlineCallbacks
def setUp(self):
"""
Set up two stores to migrate between.
"""
yield super(HomeMigrationTests, self).setUp()
yield self.buildStoreAndDirectory(
extraUids=(
u"home1",
u"home2",
u"home3",
u"home_defaults",
u"home_no_splits",
u"home_splits",
u"home_splits_shared",
)
)
self.sqlStore = self.store
# Add some files to the file store.
self.filesPath = CachingFilePath(self.mktemp())
self.filesPath.createDirectory()
fileStore = self.fileStore = CommonDataStore(
self.filesPath, {"push": StubNotifierFactory()}, self.directory, True, True
)
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()
#.........这里部分代码省略.........
示例10: HomeMigrationTests
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import createDirectory [as 别名]
class HomeMigrationTests(TestCase):
"""
Tests for L{UpgradeToDatabaseStep}.
"""
@inlineCallbacks
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")
def mergeRequirements(self, a, b):
"""
Merge two requirements dictionaries together, modifying C{a} and
returning it.
@param a: Some requirements, in the format of
L{CommonTests.requirements}.
@type a: C{dict}
@param b: Some additional requirements, to be merged into C{a}.
@type b: C{dict}
@return: C{a}
@rtype: C{dict}
"""
for homeUID in b:
homereq = a.setdefault(homeUID, {})
homeExtras = b[homeUID]
for calendarUID in homeExtras:
calreq = homereq.setdefault(calendarUID, {})
calendarExtras = homeExtras[calendarUID]
calreq.update(calendarExtras)
return a
@withSpecialValue(
"extraRequirements",
{
"home1": {
"calendar_1": {
"bogus.ics": (
getModule("twistedcaldav").filePath.sibling("zoneinfo")
.child("EST.ics").getContent(),
CommonTests.metadata1
)
}
}
}
)
@inlineCallbacks
def test_unknownTypeNotMigrated(self):
"""
The only types of calendar objects that should get migrated are VEVENTs
and VTODOs. Other component types, such as free-standing VTIMEZONEs,
don't have a UID and can't be stored properly in the database, so they
should not be migrated.
"""
yield self.upgrader.stepWithResult(None)
txn = self.sqlStore.newTransaction()
self.addCleanup(txn.commit)
self.assertIdentical(
None,
(yield (yield (yield
(yield txn.calendarHomeWithUID("home1"))
.calendarWithName("calendar_1")))
.calendarObjectWithName("bogus.ics"))
)
#.........这里部分代码省略.........