本文整理汇总了Python中twisted.python.filepath.FilePath.createDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.createDirectory方法的具体用法?Python FilePath.createDirectory怎么用?Python FilePath.createDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.createDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_path_relative
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_path_relative(self):
"""
If the ``path`` argument is relative, the path is combined with the
current working directory. The command is executed in that directory,
and that directory is logged.
"""
base_path = FilePath(self.mktemp())
base_path.createDirectory()
child_path = base_path.child('child')
child_path.createDirectory()
cmd = [sys.executable, '-c', 'import os, sys; sys.stdout.write(os.getcwd())']
old_cwd = os.getcwd()
os.chdir(base_path.path)
self.addCleanup(os.chdir, old_cwd)
self.setupStep(
master.MasterShellCommand(command=cmd, path="child"))
self.expectLogfile('stdio', child_path.path)
self.expectOutcome(result=SUCCESS, status_text=["Ran"])
d = self.runStep()
@d.addCallback
def check(_):
headers = self.step_status.logs['stdio'].header.splitlines()
self.assertIn(" in dir %s" % (child_path.path,), headers)
return d
示例2: getMaster
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def getMaster(case, reactor, config_dict):
"""
Create a started ``BuildMaster`` with the given configuration.
"""
basedir = FilePath(case.mktemp())
basedir.createDirectory()
config_dict['buildbotNetUsageData'] = None
master = BuildMaster(
basedir.path, reactor=reactor, config_loader=DictLoader(config_dict))
if 'db_url' not in config_dict:
config_dict['db_url'] = 'sqlite://'
# TODO: Allow BuildMaster to transparently upgrade the database, at least
# for tests.
master.config.db['db_url'] = config_dict['db_url']
yield master.db.setup(check_version=False)
yield master.db.model.upgrade()
master.db.setup = lambda: None
yield master.startService()
# and shutdown the db threadpool, as is normally done at reactor stop
case.addCleanup(master.db.pool.shutdown)
case.addCleanup(master.stopService)
defer.returnValue(master)
示例3: setupJobdir
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def setupJobdir(self):
jobdir = FilePath(self.mktemp())
jobdir.createDirectory()
self.jobdir = jobdir.path
for sub in 'new', 'tmp', 'cur':
jobdir.child(sub).createDirectory()
return self.jobdir
示例4: test_alwaysPreferPy
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_alwaysPreferPy(self):
"""
Verify that .py files will always be preferred to .pyc files, regardless of
directory listing order.
"""
mypath = FilePath(self.mktemp())
mypath.createDirectory()
pp = modules.PythonPath(sysPath=[mypath.path])
originalSmartPath = pp._smartPath
def _evilSmartPath(pathName):
o = originalSmartPath(pathName)
originalChildren = o.children
def evilChildren():
# normally this order is random; let's make sure it always
# comes up .pyc-first.
x = originalChildren()
x.sort()
x.reverse()
return x
o.children = evilChildren
return o
mypath.child("abcd.py").setContent("\n")
compileall.compile_dir(mypath.path, quiet=True)
# sanity check
self.assertEquals(len(mypath.children()), 2)
pp._smartPath = _evilSmartPath
self.assertEquals(pp["abcd"].filePath, mypath.child("abcd.py"))
示例5: test_worker_multiple_substantiations_succeed
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_worker_multiple_substantiations_succeed(self):
"""
If multiple builders trigger try to substantiate a worker at
the same time, if the substantiation succeeds then all of
the builds proceeed.
"""
controller = LatentController('local')
config_dict = {
'builders': [
BuilderConfig(name="testy-1",
workernames=["local"],
factory=BuildFactory(),
),
BuilderConfig(name="testy-2",
workernames=["local"],
factory=BuildFactory(),
),
],
'workers': [controller.worker],
'protocols': {'null': {}},
'multiMaster': True,
}
master = self.successResultOf(
getMaster(self, self.reactor, config_dict))
builder_ids = [
self.successResultOf(master.data.updates.findBuilderId('testy-1')),
self.successResultOf(master.data.updates.findBuilderId('testy-2')),
]
finished_builds = []
self.successResultOf(master.mq.startConsuming(
lambda key, build: finished_builds.append(build),
('builds', None, 'finished')))
# Trigger a buildrequest
bsid, brids = self.successResultOf(
master.data.updates.addBuildset(
waited_for=False,
builderids=builder_ids,
sourcestamps=[
{'codebase': '',
'repository': '',
'branch': None,
'revision': None,
'project': ''},
],
)
)
# The worker fails to substantiate.
controller.start_instance(True)
local_workdir = FilePath(self.mktemp())
local_workdir.createDirectory()
controller.connect_worker(local_workdir)
# We check that there were two builds that finished, and
# that they both finished with success
self.assertEqual([build['results']
for build in finished_builds], [SUCCESS] * 2)
示例6: setupConfig
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def setupConfig(self, config_dict, startWorker=True):
"""
Setup and start a master configured
by the function configFunc defined in the test module.
@type config_dict: dict
@param configFunc: The BuildmasterConfig dictionary.
"""
# mock reactor.stop (which trial *really* doesn't
# like test code to call!)
stop = mock.create_autospec(reactor.stop)
self.patch(reactor, 'stop', stop)
if startWorker:
if self.proto == 'pb':
proto = {"pb": {"port": "tcp:0:interface=127.0.0.1"}}
workerclass = worker.Worker
elif self.proto == 'null':
proto = {"null": {}}
workerclass = worker.LocalWorker
config_dict['workers'] = [workerclass("local1", "localpw")]
config_dict['protocols'] = proto
m = yield getMaster(self, reactor, config_dict)
self.master = m
self.assertFalse(stop.called,
"startService tried to stop the reactor; check logs")
if not startWorker:
return
if self.proto == 'pb':
# We find out the worker port automatically
workerPort = list(itervalues(m.pbmanager.dispatchers))[
0].port.getHost().port
# create a worker, and attach it to the master, it will be started, and stopped
# along with the master
worker_dir = FilePath(self.mktemp())
worker_dir.createDirectory()
self.w = Worker(
"127.0.0.1", workerPort, "local1", "localpw", worker_dir.path,
False)
elif self.proto == 'null':
self.w = None
if self.w is not None:
self.w.startService()
self.addCleanup(self.w.stopService)
@defer.inlineCallbacks
def dump():
if not self._passed:
dump = StringIO.StringIO()
print("FAILED! dumping build db for debug", file=dump)
builds = yield self.master.data.get(("builds",))
for build in builds:
yield self.printBuild(build, dump, withLogs=True)
raise self.failureException(dump.getvalue())
self.addCleanup(dump)
示例7: test_latent_max_builds
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_latent_max_builds(self):
"""
If max_builds is set, only one build is started on a latent
worker at a time.
"""
controller = LatentController(
'local',
max_builds=1,
)
step_controller = StepController()
config_dict = {
'builders': [
BuilderConfig(name="testy-1",
workernames=["local"],
factory=BuildFactory([step_controller]),
),
BuilderConfig(name="testy-2",
workernames=["local"],
factory=BuildFactory([step_controller]),
),
],
'workers': [controller.worker],
'protocols': {'null': {}},
'multiMaster': True,
}
master = self.successResultOf(getMaster(self, self.reactor, config_dict))
builder_ids = [
self.successResultOf(master.data.updates.findBuilderId('testy-1')),
self.successResultOf(master.data.updates.findBuilderId('testy-2')),
]
started_builds = []
self.successResultOf(master.mq.startConsuming(
lambda key, build: started_builds.append(build),
('builds', None, 'new')))
# Trigger a buildrequest
bsid, brids = self.successResultOf(
master.data.updates.addBuildset(
waited_for=False,
builderids=builder_ids,
sourcestamps=[
{'codebase': '',
'repository': '',
'branch': None,
'revision': None,
'project': ''},
],
)
)
# The worker fails to substantiate.
controller.start_instance(True)
local_workdir = FilePath(self.mktemp())
local_workdir.createDirectory()
controller.connect_worker(local_workdir)
self.assertEqual(len(started_builds), 1)
示例8: create_service
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def create_service():
path = FilePath(test.mktemp())
path.createDirectory()
pool = FilesystemStoragePool(path)
service = VolumeService(FilePath(test.mktemp()), pool, reactor=Clock())
service.startService()
test.addCleanup(service.stopService)
return service
示例9: cbConnect
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def cbConnect(self, directoryService):
"""
Callback from the directory service.
From this point we're connected and authenticated.
"""
basepath = FilePath(os.path.expanduser('~/.distfs'))
if not basepath.exists():
basepath.createDirectory()
store = FileSystemStore(basepath.child('store').path)
chunkFactory = Site(server.StoreResource(store))
locname = self['alias'] or directoryService.service
# Listen for remote connections. This is for the other nodes
# to access our store.
port = self['port'] and int(self['port']) or 0
listeningPort = reactor.listenTCP(port, chunkFactory)
keyStore = SQLiteDataStore(basepath.child('%s.db' % locname).path)
dhtNode = KademliaNode(listeningPort.getHost().port, keyStore,
reactor=reactor)
# Listen locally so that applications can easily access the
# store.
reactor.listenUNIX(basepath.child('%s.http' % locname).path,
chunkFactory)
resolverPublisher = ResolverPublisher(dhtNode)
controlFactory = control.ControlFactory(store, directoryService,
dhtNode, resolverPublisher)
reactor.listenUNIX(basepath.child('%s.ctrl' % locname).path,
controlFactory)
# Start a looping call that will publish chunks to the
# overlay; do that every 6th hour. Delay the procedure a bit
# so that the node has a chance to join the network.
looping = task.LoopingCall(publishChunks, store, resolverPublisher)
reactor.callLater(10, looping.start, 6*60*60, True)
# Try joining the network.
introducers = list()
if self['introducer']:
try:
address, port = self['introducer'].split(':')
except ValueError:
address, port = self['introducer'], 8033
introducers.append((address, int(port)))
dhtNode.joinNetwork(introducers)
# At this point everything that can go (majorly) wrong has
# been initialized and we can daemonize.
if not self['no-daemon']:
daemonize()
示例10: getMaster
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def getMaster(self, config_dict):
"""
Create a started ``BuildMaster`` with the given configuration.
"""
basedir = FilePath(self.mktemp())
basedir.createDirectory()
master = BuildMaster(
basedir.path, reactor=reactor, config_loader=DictLoader(config_dict))
master.config = master.config_loader.loadConfig()
return master
示例11: makeProjects
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def makeProjects(self, *versions):
"""
Create a series of projects underneath a temporary base directory.
@return: A L{FilePath} for the base directory.
"""
baseDirectory = FilePath(self.mktemp())
baseDirectory.createDirectory()
for version in versions:
self.makeProject(version, baseDirectory)
return baseDirectory
示例12: test_absolute_args_no_box
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_absolute_args_no_box(self):
"""
When invoked as `build-vagrant-box`, specifying a box is required.
"""
path = FilePath(self.mktemp())
path.createDirectory()
base_path = path.descendant(['bin', 'build-vagrant-box'])
options = BuildOptions(base_path=base_path, top_level=path)
self.assertRaises(UsageError, options.parseOptions, [])
示例13: test_relative_args_with_box
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_relative_args_with_box(self):
"""
When invoked as `build`, no box can be specified.
"""
path = FilePath(self.mktemp())
path.createDirectory()
base_path = path.descendant(['somewhere', 'box-name', 'build'])
options = BuildOptions(base_path=base_path, top_level=path)
self.assertRaises(UsageError, options.parseOptions, ['--box', 'box'])
示例14: test_path_is_renderable
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def test_path_is_renderable(self):
"""
The ``path`` argument of ``MasterShellCommand`` is renderable.`
"""
path = FilePath(self.mktemp())
path.createDirectory()
cmd = [sys.executable, '-c', 'import os, sys; sys.stdout.write(os.getcwd())']
self.setupStep(
master.MasterShellCommand(command=cmd, path=Interpolate(path.path)))
self.expectLogfile('stdio', path.path)
self.expectOutcome(result=SUCCESS, status_text=["Ran"])
return self.runStep()
示例15: _underUnderPathTest
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import createDirectory [as 别名]
def _underUnderPathTest(self, doImport=True):
moddir2 = self.mktemp()
fpmd = FilePath(moddir2)
fpmd.createDirectory()
fpmd.child("foozle.py").setContent("x = 123\n")
self.packagePath.child("__init__.py").setContent("__path__.append(%r)\n" % (moddir2,))
# Cut here
self._setupSysPath()
modinfo = modules.getModule(self.packageName)
self.assertEquals(
self.findByIteration(self.packageName + ".foozle", modinfo, importPackages=doImport), modinfo["foozle"]
)
self.assertEquals(modinfo["foozle"].load().x, 123)