本文整理汇总了Python中twisted.python.filepath.FilePath.moveTo方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.moveTo方法的具体用法?Python FilePath.moveTo怎么用?Python FilePath.moveTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.moveTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def generate(cls, directory, control_hostname, num_nodes, cluster_id=None):
"""
Generate certificates in the given directory.
:param FilePath directory: Directory to use for certificate authority.
:param bytes control_hostname: The hostname of the control service.
:param int num_nodes: Number of nodes in the cluster.
:param UUID cluster_id: The unique identifier of the cluster for which
the certificates are being generated. If not given, a random
identifier will be generated.
:return: ``Certificates`` instance.
"""
RootCredential.initialize(
directory, b"acceptance-cluster", cluster_id=cluster_id,
)
def run(*arguments):
check_call([b"flocker-ca"] + list(arguments), cwd=directory.path)
run(b"create-control-certificate", control_hostname)
run(b"create-api-certificate", b"allison")
# Rename to user.crt/user.key so we can use this folder directly
# from flocker-deploy and other clients:
directory.child(b"allison.crt").moveTo(directory.child(b"user.crt"))
directory.child(b"allison.key").moveTo(directory.child(b"user.key"))
for i in range(num_nodes):
run(b"create-node-certificate")
for i, child in enumerate(
directory.globChildren(b"????????-????-*.crt")):
sibling = FilePath(child.path[:-3] + b"key")
child.moveTo(directory.child(b"node-%d.crt" % (i,)))
sibling.moveTo(directory.child(b"node-%d.key" % (i,)))
return cls(directory)
示例2: test_renamedSource
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def test_renamedSource(self):
"""
Warnings emitted by a function defined in a file which has been renamed
since it was initially compiled can still be flushed.
This is testing the code which specifically supports working around the
unfortunate behavior of CPython to write a .py source file name into
the .pyc files it generates and then trust that it is correct in
various places. If source files are renamed, .pyc files may not be
regenerated, but they will contain incorrect filenames.
"""
package = FilePath(self.mktemp().encode('utf-8')).child(b'twisted_private_helper')
package.makedirs()
package.child(b'__init__.py').setContent(b'')
package.child(b'module.py').setContent(b'''
import warnings
def foo():
warnings.warn("oh no")
''')
pathEntry = package.parent().path.decode('utf-8')
sys.path.insert(0, pathEntry)
self.addCleanup(sys.path.remove, pathEntry)
# Import it to cause pycs to be generated
from twisted_private_helper import module
# Clean up the state resulting from that import; we're not going to use
# this module, so it should go away.
del sys.modules['twisted_private_helper']
del sys.modules[module.__name__]
# Some Python versions have extra state related to the just
# imported/renamed package. Clean it up too. See also
# http://bugs.python.org/issue15912
try:
from importlib import invalidate_caches
except ImportError:
pass
else:
invalidate_caches()
# Rename the source directory
package.moveTo(package.sibling(b'twisted_renamed_helper'))
# Import the newly renamed version
from twisted_renamed_helper import module
self.addCleanup(sys.modules.pop, 'twisted_renamed_helper')
self.addCleanup(sys.modules.pop, module.__name__)
# Generate the warning
module.foo()
# Flush it
self.assertEqual(len(self.flushWarnings([module.foo])), 1)
示例3: buildPDF
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def buildPDF(self, bookPath, inputDirectory, outputPath):
"""
Build a PDF from the given a LaTeX book document.
@type bookPath: L{FilePath}
@param bookPath: The location of a LaTeX document defining a book.
@type inputDirectory: L{FilePath}
@param inputDirectory: The directory which the inputs of the book are
relative to.
@type outputPath: L{FilePath}
@param outputPath: The location to which to write the resulting book.
"""
if not bookPath.basename().endswith(".tex"):
raise ValueError("Book filename must end with .tex")
workPath = FilePath(mkdtemp())
try:
startDir = os.getcwd()
try:
os.chdir(inputDirectory.path)
texToDVI = (
"latex -interaction=nonstopmode "
"-output-directory=%s %s") % (
workPath.path, bookPath.path)
# What I tell you three times is true!
# The first two invocations of latex on the book file allows it
# correctly create page numbers for in-text references. Why this is
# the case, I could not tell you. -exarkun
for i in range(3):
self.run(texToDVI)
bookBaseWithoutExtension = bookPath.basename()[:-4]
dviPath = workPath.child(bookBaseWithoutExtension + ".dvi")
psPath = workPath.child(bookBaseWithoutExtension + ".ps")
pdfPath = workPath.child(bookBaseWithoutExtension + ".pdf")
self.run(
"dvips -o %(postscript)s -t letter -Ppdf %(dvi)s" % {
'postscript': psPath.path,
'dvi': dviPath.path})
self.run("ps2pdf13 %(postscript)s %(pdf)s" % {
'postscript': psPath.path,
'pdf': pdfPath.path})
pdfPath.moveTo(outputPath)
workPath.remove()
finally:
os.chdir(startDir)
except:
workPath.moveTo(bookPath.parent().child(workPath.basename()))
raise
示例4: _wrap
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def _wrap(path,**template):
scratchfile=path.dirname()+"."+path.basename()+".tmp"
fh=path.open('r')
sfp=FilePath(scratchfile)
sfh=sfp.open('w')
seeklast=0
for buffer in fh.readlines():
for line in buffer:
sfh.write(line.format(**template))
sfh.flush()
sfh.close()
fh.close()
sfp.moveTo(path.realpath())
示例5: add_node
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def add_node(self, index):
"""
Generate another node certificate.
:rtype: CertAndKey
:return: The newly created node certificate.
"""
def run(*arguments):
check_call([b"flocker-ca"] + list(arguments), cwd=self.directory.path)
run(b"create-node-certificate")
tmp_crt = self.directory.globChildren(b"????????-????-*.crt")[0]
tmp_key = FilePath(tmp_crt.path[:-3] + b"key")
crt = self.directory.child(b"node-%d.crt" % (index,))
key = self.directory.child(b"node-%d.key" % (index,))
tmp_crt.moveTo(crt)
tmp_key.moveTo(key)
cert = CertAndKey(crt, key)
self.nodes.append(cert)
return cert
示例6: WarnAboutFunctionTests
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
#.........这里部分代码省略.........
self.assertEqual(warningsShown[0]["message"], "A Warning String")
self.assertEqual(len(warningsShown), 1)
def assertSamePath(self, first, second):
"""
Assert that the two paths are the same, considering case normalization
appropriate for the current platform.
@type first: L{FilePath}
@type second: L{FilePath}
@raise C{self.failureType}: If the paths are not the same.
"""
self.assertTrue(
normcase(first.path) == normcase(second.path),
"%r != %r" % (first, second))
def test_renamedFile(self):
"""
Even if the implementation of a deprecated function is moved around on
the filesystem, the line number in the warning emitted by
L{deprecate.warnAboutFunction} points to a line in the implementation of
the deprecated function.
"""
from twisted_private_helper import module
# Clean up the state resulting from that import; we're not going to use
# this module, so it should go away.
del sys.modules['twisted_private_helper']
del sys.modules[module.__name__]
# Rename the source directory
self.package.moveTo(self.package.sibling(b'twisted_renamed_helper'))
# Make sure importlib notices we've changed importable packages:
if invalidate_caches:
invalidate_caches()
# Import the newly renamed version
from twisted_renamed_helper import module
self.addCleanup(sys.modules.pop, 'twisted_renamed_helper')
self.addCleanup(sys.modules.pop, module.__name__)
module.callTestFunction()
warningsShown = self.flushWarnings([module.testFunction])
warnedPath = FilePath(warningsShown[0]["filename"].encode("utf-8"))
expectedPath = self.package.sibling(
b'twisted_renamed_helper').child(b'module.py')
self.assertSamePath(warnedPath, expectedPath)
self.assertEqual(warningsShown[0]["lineno"], 9)
self.assertEqual(warningsShown[0]["message"], "A Warning String")
self.assertEqual(len(warningsShown), 1)
def test_filteredWarning(self):
"""
L{deprecate.warnAboutFunction} emits a warning that will be filtered if
L{warnings.filterwarning} is called with the module name of the
deprecated function.
"""
# Clean up anything *else* that might spuriously filter out the warning,
# such as the "always" simplefilter set up by unittest._collectWarnings.
# We'll also rely on trial to restore the original filters afterwards.
del warnings.filters[:]
示例7: connectionLost
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import moveTo [as 别名]
def connectionLost(self, reason):
if self.persistent:
self._historyFd.close()
path = FilePath(self.historyFile + ('.%d' % self._historySession))
path.moveTo(FilePath(self.historyFile))
ConsoleManhole.connectionLost(self, reason)