Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vagrantsetup
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
devbox
vagrantsetup
Commits
70b00ddb
Commit
70b00ddb
authored
Sep 03, 2019
by
Reimar Stier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lookup latest conda version
parent
3b59f22f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
1 deletion
+54
-1
conda_version.py
lookup_plugins/conda_version.py
+54
-1
No files found.
lookup_plugins/conda_version.py
View file @
70b00ddb
https
:
//
repo
.
anaconda
.
com
/
archive
/
#!/usr/bin/env python
import
re
from
ansible.module_utils.urls
import
open_url
from
ansible.plugins.lookup
import
LookupBase
from
bs4
import
BeautifulSoup
from
pprint
import
pprint
import
datetime
URL_ANACONDA
=
"https://repo.anaconda.com/archive/"
URL_MINICONDA
=
"https://repo.continuum.io/miniconda/"
PATTERN_PYTHON
=
re
.
compile
(
r"Miniconda(?P<python>\d+)-(?P<version>[0-9]+.[0-9]+.[0-9]+|latest)-(?P<os>\w+)-(?P<arch>\w+).\w+"
)
RELEASE_MAX_AGE_DAYS
=
180
def
main
():
request
=
open_url
(
url
=
URL_MINICONDA
,
method
=
"GET"
)
response
=
request
.
read
()
data
=
[]
soup
=
BeautifulSoup
(
response
,
"html.parser"
)
table
=
soup
.
find
(
'table'
)
rows
=
table
.
find_all
(
'tr'
)
header
=
[
element
.
text
for
element
in
rows
[
0
]
.
find_all
(
'th'
)]
now
=
datetime
.
datetime
.
now
()
for
row
in
rows
[
1
:]:
cols
=
row
.
find_all
(
'td'
)
cols
=
[
ele
.
text
.
strip
()
for
ele
in
cols
]
release
=
{
key
:
value
for
key
,
value
in
zip
(
header
,
cols
)}
result
=
PATTERN_PYTHON
.
match
(
release
[
"Filename"
])
if
result
:
info
=
{
"python"
:
result
.
group
(
"python"
),
"version"
:
result
.
group
(
"version"
),
"os"
:
result
.
group
(
"os"
),
"arch"
:
result
.
group
(
"arch"
)
}
release
.
update
(
info
)
timestamp
=
datetime
.
datetime
.
strptime
(
release
[
"Last Modified"
],
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
(
now
-
timestamp
)
.
days
>
RELEASE_MAX_AGE_DAYS
:
continue
if
release
[
"os"
]
==
"Linux"
and
release
[
'arch'
]
==
'x86_64'
and
release
[
"python"
]
==
"3"
:
data
.
append
(
release
)
latest_item
=
[
item
for
item
in
data
if
item
[
"version"
]
==
"latest"
]
latest_version
=
[
item
for
item
in
data
if
item
[
"MD5"
]
==
latest_item
[
0
][
"MD5"
]]
pprint
(
data
)
print
(
latest_version
[
0
][
"version"
])
if
__name__
==
'__main__'
:
main
()
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