Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
ea0c82d6
Commit
ea0c82d6
authored
Jul 04, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #534 from davehatton/switch_to_shutil_copy
switch to shutil.copy rather than os.system(cp)
parents
0bbe0a86
9d85a554
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
library/copy
+12
-5
No files found.
library/copy
View file @
ea0c82d6
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
import
sys
import
sys
import
os
import
os
import
shlex
import
shlex
import
shutil
import
syslog
import
syslog
# ===========================================
# ===========================================
...
@@ -42,11 +43,11 @@ def md5_sum(f):
...
@@ -42,11 +43,11 @@ def md5_sum(f):
return
md5sum
return
md5sum
if
len
(
sys
.
argv
)
==
1
:
if
len
(
sys
.
argv
)
==
1
:
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"incorrect number of arguments given"
)
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"incorrect number of arguments given"
)
argfile
=
sys
.
argv
[
1
]
argfile
=
sys
.
argv
[
1
]
if
not
os
.
path
.
exists
(
argfile
):
if
not
os
.
path
.
exists
(
argfile
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"file
%
s does not exist"
%
(
argfile
))
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"file
%
s does not exist"
%
(
argfile
))
args
=
open
(
argfile
,
'r'
)
.
read
()
args
=
open
(
argfile
,
'r'
)
.
read
()
items
=
shlex
.
split
(
args
)
items
=
shlex
.
split
(
args
)
...
@@ -69,7 +70,7 @@ if dest:
...
@@ -69,7 +70,7 @@ if dest:
md5sum_src
=
None
md5sum_src
=
None
# raise an error if there is no src file
# raise an error if there is no src file
if
not
os
.
path
.
exists
(
src
):
if
not
os
.
path
.
exists
(
src
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Source
%
s failed to transfer"
%
(
src
))
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Source
%
s failed to transfer"
%
(
src
))
if
not
os
.
access
(
src
,
os
.
R_OK
):
if
not
os
.
access
(
src
,
os
.
R_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Source
%
s not readable"
%
(
src
))
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Source
%
s not readable"
%
(
src
))
md5sum_src
=
md5_sum
(
src
)
md5sum_src
=
md5_sum
(
src
)
...
@@ -85,10 +86,16 @@ if os.path.exists(dest):
...
@@ -85,10 +86,16 @@ if os.path.exists(dest):
md5sum_dest
=
md5_sum
(
dest
)
md5sum_dest
=
md5_sum
(
dest
)
else
:
else
:
if
not
os
.
access
(
os
.
path
.
dirname
(
dest
),
os
.
W_OK
):
if
not
os
.
access
(
os
.
path
.
dirname
(
dest
),
os
.
W_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not writable"
%
(
dest
))
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not writable"
%
(
os
.
path
.
dirname
(
dest
)
))
if
md5sum_src
!=
md5sum_dest
:
if
md5sum_src
!=
md5sum_dest
:
os
.
system
(
"cp
%
s
%
s"
%
(
src
,
dest
))
# was os.system("cp %s %s" % (src, dest))
try
:
shutil
.
copyfile
(
src
,
dest
)
except
shutil
.
Error
:
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"failed to copy:
%
s and
%
s are the same"
%
(
src
,
dest
))
except
IOError
:
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"failed to copy:
%
s to
%
s"
%
(
src
,
dest
))
changed
=
True
changed
=
True
else
:
else
:
changed
=
False
changed
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment