ARC SDK
Retrieving Results
1 #! /usr/bin/env python
2 import arc
3 import sys
4 import os
5 
6 def example():
7  # Creating a UserConfig object with the user's proxy
8  # and the path of the trusted CA certificates
9  uc = arc.UserConfig()
10  uc.ProxyPath("/tmp/x509up_u%s" % os.getuid())
11  uc.CACertificatesDirectory("/etc/grid-security/certificates")
12 
13  # Create a new job object with a given JobID
14  job = arc.Job()
15  job.JobID = "https://piff.hep.lu.se:443/arex/hYDLDmyxvUfn5h5iWqkutBwoABFKDmABFKDmIpHKDmYBFKDmtRy9En"
16  job.Flavour = "ARC1"
17  job.ServiceInformationURL = job.JobStatusURL = job.JobManagementURL = arc.URL("https://piff.hep.lu.se:443/arex")
18 
19  print "Get job information from the computing element..."
20  # Put the job into a JobSupervisor and update its information
21  job_supervisor = arc.JobSupervisor(uc, [job])
22  job_supervisor.Update()
23 
24  print "Downloading results..."
25  # Prepare a list for storing the directories for the downloaded job results (if there would be more jobs)
26  downloadeddirectories = arc.StringList()
27  # Start retrieving results of all the selected jobs
28  # into the "/tmp" directory (first argument)
29  # using the jobid and not the jobname as the name of the subdirectory (second argument, usejobname = False)
30  # do not overwrite existing directories with the same name (third argument: force = False)
31  # collect the downloaded directories into the variable "downloadeddirectories" (forth argument)
32  success = job_supervisor.Retrieve("/tmp", False, False, downloadeddirectories)
33  if not success:
34  print "Downloading results failed."
35  for downloadeddirectory in downloadeddirectories:
36  print "Job results were downloaded to", downloadeddirectory
37  print "Contents of the directory:"
38  for filename in os.listdir(downloadeddirectory):
39  print " ", filename
40 
41 # wait for all the background threads to finish before we destroy the objects they may use
42 import atexit
43 @atexit.register
44 def wait_exit():
45  arc.ThreadInitializer().waitExit()
46 
47 # arc.Logger.getRootLogger().addDestination(arc.LogStream(sys.stderr))
48 # arc.Logger.getRootLogger().setThreshold(arc.DEBUG)
49 
50 # run the example
51 example()