This page includes some simple examples of basic usage of the pyxrootd FileSystem object to interact with an xrootd server.
We’ll use the following imports and FileSystem object as the basis for the rest of the examples:
from XRootD import client
from XRootD.client.flags import DirListFlags, OpenFlags, MkDirFlags, QueryCode
myclient = client.FileSystem('root://someserver:1094')
status = myclient.copy('/tmp/spam', '/tmp/eggs', force=True)
assert status.ok
See XRootD.client.CopyProcess if you need multiple/more configurable copy jobs.
status, listing = myclient.dirlist('/tmp', DirListFlags.STAT)
print listing.parent
for entry in listing:
print "{0} {1:>10} {2}".format(entry.statinfo.modtimestr, entry.statinfo.size, entry.name)
Produces output similar to the following:
2013-04-12 09:46:51 20 spam
2013-04-05 08:23:00 4096 .xrootd
2013-04-12 09:33:25 20 eggs
myclient.mkdir("/tmp/some/dir", MkDirFlags.MAKEPATH)
myclient.rmdir("/tmp/some/dir")
myclient.mv("/tmp/spam", "/tmp/eggs")
myclient.rm("/tmp/eggs")
status, locations = myclient.locate("/tmp", OpenFlags.REFRESH)
print locations
Produces output similar to the following:
<locations: [<type: 2, address: '[::127.0.0.1]:1094', accesstype: 1, is_manager: False, is_server: True>]>
status, response = myclient.query(QueryCode.SPACE, '/tmp')
print response
Produces output similar to the following:
oss.cgroup=public&oss.space=52844687360&oss.free=27084992512&oss.maxf=27084992512&oss.used=25759694848&oss.quota=-1
For more information about XRootD query codes and arguments, see the relevant section in the protocol reference.