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
035b9535
Commit
035b9535
authored
Jul 03, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #529 from davehatton/error_trapping_md5
improve error trapping for md5
parents
05121bf3
345499c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
22 deletions
+26
-22
library/copy
+25
-21
library/setup
+1
-1
No files found.
library/copy
View file @
035b9535
...
...
@@ -37,6 +37,10 @@ def exit_kv(rc=0, **kwargs):
print
dump_kv
(
kwargs
)
sys
.
exit
(
rc
)
def
md5_sum
(
f
):
md5sum
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2>/dev/null || /sbin/md5 -q
%(file)
s 2>/dev/null || /usr/bin/digest -a md5 -v
%(file)
s 2>/dev/null"
%
{
"file"
:
f
})
.
read
()
.
split
()[
0
]
return
md5sum
if
len
(
sys
.
argv
)
==
1
:
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"incorrect number of arguments given"
)
...
...
@@ -61,34 +65,34 @@ if src:
src
=
os
.
path
.
expanduser
(
src
)
if
dest
:
dest
=
os
.
path
.
expanduser
(
dest
)
# raise an error if there is no src file
if
not
os
.
path
.
exists
(
src
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Source
%
s failed to transfer"
%
(
src
))
if
os
.
path
.
exists
(
dest
):
# raise an error if copy has no permission on dest
if
not
os
.
access
(
dest
,
os
.
W_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not writable"
%
(
dest
))
elif
not
os
.
access
(
dest
,
os
.
R_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not readable"
%
(
dest
))
else
:
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
=
"Source
%
s failed to transfer"
%
(
src
))
# raise an error if there is no dest file
if
not
os
.
path
.
exists
(
dest
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s does not exist"
%
(
dest
))
md5sum
=
None
changed
=
False
if
os
.
path
.
exists
(
dest
):
md5sum
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2> /dev/null || /sbin/md5 -q
%(file)
s"
%
{
"file"
:
dest
})
.
read
()
.
split
()[
0
]
# raise an error if copy has no permission on dest
if
not
os
.
access
(
dest
,
os
.
W_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not writable"
%
(
dest
))
elif
not
os
.
access
(
dest
,
os
.
R_OK
):
exit_kv
(
rc
=
1
,
failed
=
1
,
msg
=
"Destination
%
s not readable"
%
(
dest
))
md5sum2
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2> /dev/null || /sbin/md5 -q
%(file)
s"
%
{
"file"
:
src
})
.
read
()
.
split
()[
0
]
md5sum_src
=
None
md5sum_src
=
md5_sum
(
src
)
if
md5sum
!=
md5sum2
:
md5sum_dest
=
None
md5sum_dest
=
md5_sum
(
dest
)
if
md5sum_src
!=
md5sum_dest
:
os
.
system
(
"cp
%
s
%
s"
%
(
src
,
dest
))
changed
=
True
else
:
changed
=
False
# mission accomplished
#print "md5sum=%s changed=%s" % (md5sum2, changed)
exit_kv
(
dest
=
dest
,
src
=
src
,
changed
=
"md5sum=
%
s changed=
%
s"
%
(
md5sum2
,
changed
))
#print "md5sum=%s changed=%s" % (md5sum_dest, changed)
exit_kv
(
dest
=
dest
,
src
=
src
,
changed
=
"md5sum=
%
s changed=
%
s"
%
(
md5sum_dest
,
changed
))
library/setup
View file @
035b9535
...
...
@@ -312,7 +312,7 @@ def ansible_facts():
return
facts
def
md5_sum
(
f
):
md5sum
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2>
/dev/null || /sbin/md5 -q
%(file)
s 2> /dev/null || /usr/bin/digest -a md5 -v
%(file)
s
"
%
{
"file"
:
f
})
.
read
()
.
split
()[
0
]
md5sum
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2>
/dev/null || /sbin/md5 -q
%(file)
s 2>/dev/null || /usr/bin/digest -a md5 -v
%(file)
s 2>/dev/null
"
%
{
"file"
:
f
})
.
read
()
.
split
()[
0
]
return
md5sum
# load config & template variables
...
...
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