File: copy_file.py

package info (click to toggle)
nordugrid-arc 7.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 29,364 kB
  • sloc: cpp: 136,663; python: 12,452; perl: 12,313; php: 11,408; sh: 10,878; ansic: 3,305; makefile: 3,161; xml: 180; sql: 130; javascript: 53; sed: 30
file content (53 lines) | stat: -rw-r--r-- 1,437 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

import sys
import arc

# Copies a file from source to destination

# Wait for all the background threads to exit before exiting
import atexit
@atexit.register
def wait_exit():
    arc.ThreadInitializer().waitExit()

def usage():
    sys.stdout.write(' Usage: copy_file.py source destination\n')
    
if len(sys.argv) != 3:
    usage()
    sys.exit(1)
    
# Logging to stdout
root_logger = arc.Logger.getRootLogger()
stream = arc.LogStream(sys.stdout)
root_logger.addDestination(stream)
# Set threshold to VERBOSE or DEBUG for more information
root_logger.setThreshold(arc.ERROR)

# User configuration - paths to proxy certificates etc can be set here
# With no arguments default values are used
cfg = arc.UserConfig()

# Convert the arguments to DataPoint objects
source = arc.datapoint_from_url(sys.argv[1], cfg)
if source is None:
    root_logger.msg(arc.ERROR, "Can't handle source "+sys.argv[1])
    sys.exit(1)
    
destination = arc.datapoint_from_url(sys.argv[2], cfg)
if destination is None:
    root_logger.msg(arc.ERROR, "Can't handle destination "+sys.argv[2])
    sys.exit(1)

# DataMover does the transfer
mover = arc.DataMover()
# Show transfer progress
mover.verbose(True)
# Don't attempt to retry on error
mover.retry(False)
# Do the transfer
status = mover.Transfer(source, destination, arc.FileCache(), arc.URLMap())

# Print the exit status of the transfer
sys.stdout.write("%s\n"%str(status))