本文整理汇总了Python中twisted.python.filepath.FilePath.chmod方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.chmod方法的具体用法?Python FilePath.chmod怎么用?Python FilePath.chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.chmod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_twistd
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_twistd(self):
"""
Should run twistd with the given arguments
"""
runner = Runner()
fake_twistd = FilePath(self.mktemp())
fake_twistd.setContent('#!%s\n'
'import sys, os\n'
'print " ".join(sys.argv[1:])\n'
'print os.environ["FOO"]\n'
'print os.path.abspath(os.curdir)\n'
'sys.stdout.flush()\n'
'sys.stderr.write("error\\n")\n'
'print "stdout"\n'
'sys.exit(4)\n' % sys.executable)
fake_twistd.chmod(0777)
runner._twistdBin = lambda: fake_twistd.path
path = FilePath(self.mktemp())
path.makedirs()
d = runner.twistd(['foo', 'bar', 'baz'], env={'FOO': 'foo value'},
path=path.path)
def check(result):
out, err, code = result
self.assertEqual(code, 4)
self.assertEqual(out,
'foo bar baz\n'
'foo value\n'
'%s\n'
'stdout\n' % path.path)
self.assertEqual(err, 'error\n')
return d.addCallback(check)
示例2: test_directory
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_directory(self):
"""
A directory can exist
"""
root = FilePath(self.mktemp())
root.makedirs()
root.chmod(0777)
stdout, stderr, code = self.runScript(['inspect'], json.dumps({
'kind': 'file',
'path': root.path,
}))
data = json.loads(stdout)
self.assertEqual(data['kind'], 'file')
self.assertEqual(data['path'], root.path)
self.assertEqual(data['exists'], True)
self.assertEqual(data['filetype'], 'dir')
self.assertEqual(data['owner'], pwd.getpwuid(os.geteuid()).pw_name)
self.assertEqual(data['group'], grp.getgrgid(os.getegid()).gr_name)
self.assertEqual(data['perms'], '0777')
root.restat()
self.assertEqual(data['ctime'], int(root.statinfo.st_ctime))
self.assertEqual(type(data['ctime']), int)
self.assertEqual(data['mtime'], int(root.statinfo.st_mtime))
self.assertEqual(type(data['mtime']), int)
self.assertEqual(data['atime'], int(root.statinfo.st_atime))
self.assertEqual(type(data['atime']), int)
示例3: test_file
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_file(self):
"""
An existing file has these attributes
"""
root = FilePath(self.mktemp())
root.setContent('the content')
root.chmod(0777)
stdout, stderr, code = self.runScript(['inspect'], json.dumps({
'kind': 'file',
'path': root.path,
}))
data = json.loads(stdout)
self.assertEqual(data['kind'], 'file')
self.assertEqual(data['path'], root.path)
self.assertEqual(data['exists'], True)
self.assertEqual(data['filetype'], 'file')
self.assertEqual(data['owner'], pwd.getpwuid(os.geteuid()).pw_name)
self.assertEqual(data['group'], grp.getgrgid(os.getegid()).gr_name)
self.assertEqual(data['perms'], '0777')
root.restat()
self.assertEqual(data['ctime'], int(root.statinfo.st_ctime))
self.assertEqual(type(data['ctime']), int)
self.assertEqual(data['mtime'], int(root.statinfo.st_mtime))
self.assertEqual(type(data['mtime']), int)
self.assertEqual(data['atime'], int(root.statinfo.st_atime))
self.assertEqual(type(data['atime']), int)
self.assertEqual(data['sha1'], sha1('the content').hexdigest())
self.assertEqual(data['size'], len('the content'))
示例4: create_credentials
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def create_credentials():
"""
Create PKI credentials for TLS access to libvirtd.
Credentials are not signed by the host CA. This only allows
unverified access but removes the need to transfer files
between the host and the guest.
"""
path = FilePath(tempfile.mkdtemp())
try:
ca = RootCredential.initialize(path, b"mycluster")
NodeCredential.initialize(path, ca, uuid='client')
ca_dir = FilePath('/etc/pki/CA')
if not ca_dir.exists():
ca_dir.makedirs()
path.child(AUTHORITY_CERTIFICATE_FILENAME).copyTo(
FilePath('/etc/pki/CA/cacert.pem')
)
client_key_dir = FilePath('/etc/pki/libvirt/private')
if not client_key_dir.exists():
client_key_dir.makedirs()
client_key_dir.chmod(0700)
path.child('client.key').copyTo(
client_key_dir.child('clientkey.pem')
)
path.child('client.crt').copyTo(
FilePath('/etc/pki/libvirt/clientcert.pem')
)
finally:
path.remove()
示例5: test_unix_already_listening_cant_delete
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_unix_already_listening_cant_delete(self):
"""
A config with type = "unix" will create an endpoint for a UNIX socket
at the given path, and delete it if required. If it can't delete it, it
will raise an exception.
"""
parent_fp = FilePath("/tmp").child(uuid4().hex)
parent_fp.makedirs()
fp = parent_fp.child(uuid4().hex)
# Something is already there
fp.setContent(b"")
fp.chmod(0o544)
parent_fp.chmod(0o544)
reactor = SelectReactor()
config = {
"type": "unix",
"path": fp.path
}
with self.assertRaises(OSError) as e:
create_listening_endpoint_from_config(config, self.cbdir,
reactor, self.log)
self.assertEqual(e.exception.errno, 13) # Permission Denied
parent_fp.chmod(0o777)
parent_fp.remove()
示例6: test_no_logging_if_permission_denied
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_no_logging_if_permission_denied(self):
"""
If there is no permission to write to the given directory this does
not prevent the script from running.
"""
options = usage.Options()
sys = FakeSysModule(argv=[b"mythingie"])
logs = FilePath(self.mktemp())
logs.makedirs()
logs.chmod(0)
self.addCleanup(logs.chmod, 0o777)
class Script(object):
ran = False
def main(self, *args, **kwargs):
self.ran = True
return succeed(None)
script = Script()
from twisted.test.test_task import _FakeReactor
fakeReactor = _FakeReactor()
runner = FlockerScriptRunner(script, options, reactor=fakeReactor,
sys_module=sys)
runner.log_directory = logs
try:
with attempt_effective_uid('nobody', suppress_errors=True):
runner.main()
except SystemExit:
pass
self.assertTrue(script.ran)
示例7: wrapper
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def wrapper(case, *args, **kwargs):
test_file = FilePath(case.mktemp())
test_file.touch()
test_file.chmod(0o000)
permissions = test_file.getPermissions()
test_file.chmod(0o777)
if permissions != Permissions(0o000):
raise SkipTest("Can't run test on filesystem with broken permissions.")
return test_method(case, *args, **kwargs)
示例8: test_config_write_failed
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_config_write_failed(self):
"""If writing the config fails then CreateConfigurationError
is raised."""
path = FilePath(self.mktemp())
path.makedirs()
path.chmod(0)
self.addCleanup(path.chmod, 0o777)
path = path.child(b"config.json")
service = VolumeService(path, None, reactor=Clock())
self.assertRaises(CreateConfigurationError, service.startService)
示例9: test_config_makedirs_failed
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_config_makedirs_failed(self):
"""If creating the config directory fails then CreateConfigurationError
is raised."""
path = FilePath(self.mktemp())
path.makedirs()
path.chmod(0)
self.addCleanup(path.chmod, 0o777)
path = path.child(b"dir").child(b"config.json")
service = VolumeService(path, None, reactor=Clock())
with attempt_effective_uid('nobody', suppress_errors=True):
self.assertRaises(CreateConfigurationError, service.startService)
示例10: test_config_write_failed
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_config_write_failed(self):
"""If writing the config fails then CreateConfigurationError
is raised."""
path = FilePath(self.mktemp())
path.makedirs()
path.chmod(0)
self.addCleanup(path.chmod, 0o777)
path = path.child(b"config.json")
service = VolumeService(path, FilesystemStoragePool(FilePath(self.mktemp())), reactor=Clock())
with attempt_effective_uid("nobody", suppress_errors=True):
self.assertRaises(CreateConfigurationError, service.startService)
示例11: test_no_permission
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_no_permission(self):
"""If the config file is not writeable a meaningful response is
written.
"""
path = FilePath(self.mktemp())
path.makedirs()
path.chmod(0)
self.addCleanup(path.chmod, 0o777)
config = path.child(b"out.json")
with attempt_effective_uid("nobody", suppress_errors=True):
result = run_expecting_error(b"--config", config.path)
self.assertEqual(result, b"Writing config file %s failed: Permission denied\n" % (config.path,))
示例12: test_permissionDenied
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_permissionDenied(self):
"""
If the a source file is not readable, this is reported on standard
error.
"""
sourcePath = FilePath(self.mktemp())
sourcePath.setContent('')
sourcePath.chmod(0)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEquals(count, 1)
self.assertEquals(
err.getvalue(), "%s: Permission denied\n" % (sourcePath.path,))
示例13: test_install_dir_normalises_permissions
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_install_dir_normalises_permissions(self):
# install_dir() normalises directory permissions to 0755 and file
# permissions to 0644.
target_dir = FilePath(self.make_dir())
new_dir = FilePath(self.make_dir())
new_dir.chmod(0700)
new_image = new_dir.child("image")
new_image.touch()
new_image.chmod(0600)
install_dir(new_dir.path, target_dir.path)
self.assertEqual(
"rwxr-xr-x",
target_dir.getPermissions().shorthand())
self.assertEqual(
"rw-r--r--",
target_dir.child("image").getPermissions().shorthand())
示例14: test_exit
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_exit(self):
"""
``VolumeScript._create_volume_service`` raises ``SystemExit`` with a
non-zero code if ``VolumeService.startService`` raises
``CreateConfigurationError``.
"""
directory = FilePath(self.mktemp())
directory.makedirs()
directory.chmod(0o000)
self.addCleanup(directory.chmod, 0o777)
config = directory.child("config.yml")
stderr = StringIO()
reactor = object()
options = VolumeOptions()
options.parseOptions([b"--config", config.path])
with attempt_effective_uid("nobody", suppress_errors=True):
exc = self.assertRaises(SystemExit, VolumeScript._create_volume_service, stderr, reactor, options)
self.assertEqual(1, exc.code)
示例15: test_forbiddenResource
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import chmod [as 别名]
def test_forbiddenResource(self):
"""
If the file in the filesystem which would satisfy a request cannot be
read, L{File.render} sets the HTTP response code to I{FORBIDDEN}.
"""
base = FilePath(self.mktemp())
base.setContent('')
# Make sure we can delete the file later.
self.addCleanup(base.chmod, 0700)
# Get rid of our own read permission.
base.chmod(0)
file = static.File(base.path)
request = DummyRequest([''])
d = self._render(file, request)
def cbRendered(ignored):
self.assertEqual(request.responseCode, 403)
d.addCallback(cbRendered)
return d