#!/usr/bin/python import sys, os, getopt def usage(): print '' print 'make_srmcp_copyjobfile' print '' print 'takes file with dcache url\'s (base_file) and generates srmcp copyjobfile' print 'to stage them to a dcache destination (dcache_destination).' print '' print 'required parameters:' print '--tier (-t) : hit, digi, dst to use the default file names' print '--dcache_destination (-c) : dcache destination' print '' print 'optional parameters:' print '--help (-h) : help' print '--debug (-d) : debug statements' print '' print '--base_file_name (-b) : base_file with dcache url\'s, default: _to_be_staged.cpy' print '--output_file_name (-o) : output_file with dcache url\'s not in both files, default: _to_be_staged_srmcp.cpy' print '' def main(argv) : # default tier = '' base_file_name = '' dcache_destination = '' output_file_name = '' try: opts, args = getopt.getopt(argv, "hdt:b:c:o:", ["help", "debug", "tier=", "base_file_name=", "dcache_destination=", "output_file_name="]) except getopt.GetoptError: usage() sys.exit(2) # check command line parameter for opt, arg in opts : if opt in ("-h","--help") : usage() sys.exit() elif opt in ("-d","--debug") : global _debug _debug = 1 elif opt in ("-t","--tier") : tier = arg elif opt in ("-b","--base_file_name") : base_file_name = arg elif opt in ("-c","--dcache_destination") : dcache_destination = arg elif opt in ("-o","--output_file_name") : output_file_name = arg if base_file_name == '': if tier == '' : usage() sys.exit() else : base_file_name = tier+'_to_be_staged.cpy' if dcache_destination == '' : print '' print 'Please provide dcache destination' usage() sys.exit(1) if output_file_name == '': if tier == '' : usage() sys.exit() else : output_file_name = tier+'_to_be_staged_srmcp.cpy' try: base_file = open(base_file_name) except IOError: print 'Could not open file: ',base_file_name sys.exit() output = open(output_file_name,'w') counter = 0 base_file_line = base_file.readline() while base_file_line : base_file_line = base_file_line.strip() filename = os.path.split(base_file_line)[1] base_file_url = 'gsiftp://cmsstor06.fnal.gov:2811///' index = base_file_line.find('WAX') base_file_url += base_file_line[index:] output_url = 'srm://cmssrm.fnal.gov:8443/srm/managerv1?SFN=' index = dcache_destination.find('WAX') output_url += dcache_destination[index+3:] output_url += '/' output_url += filename output_string = base_file_url+' '+output_url+'\n' output.write(output_string) counter += 1 base_file_line = base_file.readline() print 'Lines in srmcp copyjobfile: ',counter if __name__ == '__main__' : main(sys.argv[1:])