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
21632261
Commit
21632261
authored
Aug 17, 2020
by
Reimar Stier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add minor python version to regex; use another user agent in conda release crawler
parent
95d8bbfd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
conda_releases.py
local_roles/conda_installer/lookup_plugins/conda_releases.py
+9
-4
No files found.
local_roles/conda_installer/lookup_plugins/conda_releases.py
View file @
21632261
...
...
@@ -6,6 +6,7 @@ import re
from
ansible.module_utils.urls
import
open_url
from
ansible.plugins.lookup
import
LookupBase
from
bs4
import
BeautifulSoup
import
logging
MINICONDA
=
"miniconda"
ANACONDA
=
"anaconda"
...
...
@@ -16,17 +17,18 @@ BASE_URL = {
}
PATTERN_FILENAME
=
{
MINICONDA
:
re
.
compile
(
r"Miniconda(?P<python>\d+)-(?P<version>[0-9]+.[0-9]+.[0-9]+(.[0-9]+)?|latest)-(?P<os>\w+)-(?P<arch>\w+).\w+"
),
r"Miniconda(?P<python>\d+)-(?P<
python_minor>py\d+_)?(?P<
version>[0-9]+.[0-9]+.[0-9]+(.[0-9]+)?|latest)-(?P<os>\w+)-(?P<arch>\w+).\w+"
),
ANACONDA
:
re
.
compile
(
r"Anaconda(?P<python>\d+)-(?P<version>[0-9]+.[0-9]+(.[0-9]+)?|latest)-(?P<os>\w+)-(?P<arch>\w+).\w+"
),
}
RELEASE_MAX_AGE_DAYS
=
365
RELEASE_MAX_AGE_DAYS
=
720
def
fetch_releases
(
distribution
=
MINICONDA
,
architecture
=
"x86_64"
,
python_version
=
"3"
,
release_max_age_days
=
RELEASE_MAX_AGE_DAYS
):
base_url
=
BASE_URL
[
distribution
]
request
=
open_url
(
url
=
base_url
,
method
=
"GET"
)
logging
.
debug
(
"base_url={}"
.
format
(
base_url
))
request
=
open_url
(
url
=
base_url
,
method
=
"GET"
,
headers
=
{
'User-Agent'
:
"Magic Browser"
})
response
=
request
.
read
()
data
=
{}
...
...
@@ -59,6 +61,7 @@ def fetch_releases(distribution=MINICONDA, architecture="x86_64", python_version
if
len
(
data
)
==
0
:
return
data
# nothing found
logging
.
debug
(
json
.
dumps
(
data
))
# find latest version number
if
distribution
==
MINICONDA
:
latest_item
=
[
item
for
item
in
data
.
values
()
if
item
[
"version"
]
==
"latest"
]
...
...
@@ -96,5 +99,7 @@ class LookupModule(LookupBase):
if
__name__
==
'__main__'
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
"
%(asctime)
s :
%(levelname)
s :
%(name)
s :
%(message)
s"
)
print
(
json
.
dumps
({
"Miniconda for python 3"
:
fetch_releases
(
distribution
=
MINICONDA
,
python_version
=
"3"
)},
indent
=
4
))
print
(
json
.
dumps
({
"Anaconda for python 2"
:
fetch_releases
(
distribution
=
ANACONDA
,
python_version
=
"
2
"
)},
indent
=
4
))
print
(
json
.
dumps
({
"Anaconda for python 2"
:
fetch_releases
(
distribution
=
ANACONDA
,
python_version
=
"
3
"
)},
indent
=
4
))
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