Hi Stephen
On 28/01/09 15:53, Stephen Childs wrote:
> How can I list the files associated with a particular space token (or
> dpm-spacetoken-list-files)?
>
> In case you can't tell, I'm looking forward to the next release of the
> admin tools so I don't have to copy and paste sql commands!
Have a look at this attached script for printing out the list of
physical filenames that at associated with a particular space token
description.
Again, I'll add it to the next release if it proves to be useful.
Cheers,
Greig
#! /usr/bin/env python
# $Id: dpm-sql-usage-by-vo-user,v 1.1 2009/01/23 15:20:41 gcowan Exp $
__author__ = 'Greig A Cowan'
__date__ = 'January 2009'
__version = 0.1
'''List physical files in a space token'''
import sys
import os
from optparse import OptionParser
import string
import getpass
import MySQLdb
def main():
parser = OptionParser(
usage = 'usage: %prog')
parser.add_option('--st', dest='st',default='',
help='Specify a space token description')
(options, args) = parser.parse_args()
if len(args) > 1:
parser.error("incorrect number of arguments")
if (os.environ['LCG_LOCATION']):
dpminfopath = os.environ['LCG_LOCATION'].rstrip('/') + '/etc/DPMINFO'
else:
dpminfopath = '/opt/lcg/etc/DPMINFO'
dpminfo = file(dpminfopath)
(up,hd) = dpminfo.readline().split('@')
(u,p) = up.split('/')
(h,d) = hd.split('/')
if (d==None):
d='cns_db'
try:
c = MySQLdb.connect(host=h, user=u, passwd=p, db=d.strip())
cc = c.cursor()
cc.execute('''
select cns_db.Cns_file_replica.sfn from cns_db.Cns_file_replica join dpm_db.dpm_space_reserv on dpm_db.dpm_space_reserv.s_token = cns_db.Cns_file_replica.setname where dpm_db.dpm_space_reserv.u_token="%s"''' % (options.st))
results = cc.fetchall()
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cc.close()
c.close()
for line in results:
print line[0].tostring()
if __name__ == '__main__':
main()
|