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
612aed55
Commit
612aed55
authored
Nov 07, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1546 from dagwieers/get_url-nonthirsty-fix
Don't require thirsty mode for directory destination
parents
0ed2595b
82ec405b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
19 deletions
+8
-19
library/get_url
+8
-19
No files found.
library/get_url
View file @
612aed55
...
@@ -98,24 +98,14 @@ def url_do_get(module, url, dest):
...
@@ -98,24 +98,14 @@ def url_do_get(module, url, dest):
"""
"""
USERAGENT
=
'ansible-httpget'
USERAGENT
=
'ansible-httpget'
info
=
dict
(
url
=
url
)
info
=
dict
(
url
=
url
,
dest
=
dest
)
r
=
None
r
=
None
actualdest
=
None
if
os
.
path
.
isdir
(
dest
):
urlfilename
=
url_filename
(
url
)
actualdest
=
"
%
s/
%
s"
%
(
dest
,
urlfilename
)
module
.
params
[
'path'
]
=
actualdest
else
:
actualdest
=
dest
info
[
'actualdest'
]
=
actualdest
request
=
urllib2
.
Request
(
url
)
request
=
urllib2
.
Request
(
url
)
request
.
add_header
(
'User-agent'
,
USERAGENT
)
request
.
add_header
(
'User-agent'
,
USERAGENT
)
if
os
.
path
.
exists
(
actual
dest
):
if
os
.
path
.
exists
(
dest
):
t
=
datetime
.
datetime
.
utcfromtimestamp
(
os
.
path
.
getmtime
(
actual
dest
))
t
=
datetime
.
datetime
.
utcfromtimestamp
(
os
.
path
.
getmtime
(
dest
))
tstamp
=
t
.
strftime
(
'
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S +0000'
)
tstamp
=
t
.
strftime
(
'
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S +0000'
)
request
.
add_header
(
'If-Modified-Since'
,
tstamp
)
request
.
add_header
(
'If-Modified-Since'
,
tstamp
)
...
@@ -144,12 +134,11 @@ def url_get(module, url, dest):
...
@@ -144,12 +134,11 @@ def url_get(module, url, dest):
# TODO: should really handle 304, but how? src file could exist (and be newer) but empty
# TODO: should really handle 304, but how? src file could exist (and be newer) but empty
if
info
[
'status'
]
==
304
:
if
info
[
'status'
]
==
304
:
module
.
exit_json
(
url
=
url
,
dest
=
info
.
get
(
'actualdest'
,
dest
)
,
changed
=
False
,
msg
=
info
.
get
(
'msg'
,
''
))
module
.
exit_json
(
url
=
url
,
dest
=
dest
,
changed
=
False
,
msg
=
info
.
get
(
'msg'
,
''
))
# create a temporary file and copy content to do md5-based replacement
# create a temporary file and copy content to do md5-based replacement
if
info
[
'status'
]
!=
200
:
if
info
[
'status'
]
!=
200
:
module
.
fail_json
(
msg
=
"Request failed"
,
status_code
=
info
[
'status'
],
response
=
info
[
'msg'
],
url
=
url
)
module
.
fail_json
(
msg
=
"Request failed"
,
status_code
=
info
[
'status'
],
response
=
info
[
'msg'
],
url
=
url
,
dest
=
dest
)
actualdest
=
info
[
'actualdest'
]
fd
,
tempname
=
tempfile
.
mkstemp
()
fd
,
tempname
=
tempfile
.
mkstemp
()
f
=
os
.
fdopen
(
fd
,
'wb'
)
f
=
os
.
fdopen
(
fd
,
'wb'
)
...
@@ -187,9 +176,10 @@ def main():
...
@@ -187,9 +176,10 @@ def main():
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
thirsty
=
module
.
boolean
(
module
.
params
[
'thirsty'
])
thirsty
=
module
.
boolean
(
module
.
params
[
'thirsty'
])
if
os
.
path
.
isdir
(
dest
):
dest
=
os
.
path
.
join
(
dest
,
url_filename
(
url
))
if
not
thirsty
:
if
not
thirsty
:
if
os
.
path
.
isdir
(
dest
):
module
.
fail_json
(
msg
=
"non-thirsty mode needs a filename for a destination, not a directory"
)
if
os
.
path
.
exists
(
dest
):
if
os
.
path
.
exists
(
dest
):
module
.
exit_json
(
msg
=
"file already exists"
,
dest
=
dest
,
url
=
url
,
changed
=
False
)
module
.
exit_json
(
msg
=
"file already exists"
,
dest
=
dest
,
url
=
url
,
changed
=
False
)
...
@@ -197,7 +187,6 @@ def main():
...
@@ -197,7 +187,6 @@ def main():
tmpsrc
,
info
=
url_get
(
module
,
url
,
dest
)
tmpsrc
,
info
=
url_get
(
module
,
url
,
dest
)
md5sum_src
=
None
md5sum_src
=
None
md5sum_dest
=
None
md5sum_dest
=
None
dest
=
info
[
'actualdest'
]
# raise an error if there is no tmpsrc file
# raise an error if there is no tmpsrc file
if
not
os
.
path
.
exists
(
tmpsrc
):
if
not
os
.
path
.
exists
(
tmpsrc
):
...
...
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