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
30552cf7
Commit
30552cf7
authored
Sep 16, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problems with undefined references to self.display and remove method that's no longer called
parent
3f8e12d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
71 deletions
+28
-71
lib/ansible/galaxy/role.py
+28
-71
No files found.
lib/ansible/galaxy/role.py
View file @
30552cf7
...
@@ -31,6 +31,12 @@ from urllib2 import urlopen
...
@@ -31,6 +31,12 @@ from urllib2 import urlopen
from
ansible
import
constants
as
C
from
ansible
import
constants
as
C
from
ansible.errors
import
AnsibleError
from
ansible.errors
import
AnsibleError
try
:
from
__main__
import
display
except
ImportError
:
from
ansible.utils.display
import
Display
display
=
Display
()
class
GalaxyRole
(
object
):
class
GalaxyRole
(
object
):
SUPPORTED_SCMS
=
set
([
'git'
,
'hg'
])
SUPPORTED_SCMS
=
set
([
'git'
,
'hg'
])
...
@@ -45,7 +51,6 @@ class GalaxyRole(object):
...
@@ -45,7 +51,6 @@ class GalaxyRole(object):
self
.
_install_info
=
None
self
.
_install_info
=
None
self
.
options
=
galaxy
.
options
self
.
options
=
galaxy
.
options
self
.
display
=
galaxy
.
display
self
.
name
=
name
self
.
name
=
name
self
.
version
=
version
self
.
version
=
version
...
@@ -67,54 +72,6 @@ class GalaxyRole(object):
...
@@ -67,54 +72,6 @@ class GalaxyRole(object):
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
self
.
name
==
other
.
name
return
self
.
name
==
other
.
name
def
fetch_from_scm_archive
(
self
):
# this can be configured to prevent unwanted SCMS but cannot add new ones unless the code is also updated
if
scm
not
in
self
.
scms
:
self
.
display
.
display
(
"The
%
s scm is not currently supported"
%
scm
)
return
False
tempdir
=
tempfile
.
mkdtemp
()
clone_cmd
=
[
scm
,
'clone'
,
role_url
,
self
.
name
]
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
try
:
self
.
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
clone_cmd
))
popen
=
subprocess
.
Popen
(
clone_cmd
,
cwd
=
tempdir
,
stdout
=
devnull
,
stderr
=
devnull
)
except
:
raise
AnsibleError
(
"error executing:
%
s"
%
" "
.
join
(
clone_cmd
))
rc
=
popen
.
wait
()
if
rc
!=
0
:
self
.
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
clone_cmd
))
self
.
display
.
display
(
" in directory
%
s"
%
tempdir
)
return
False
temp_file
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'.tar'
)
if
scm
==
'hg'
:
archive_cmd
=
[
'hg'
,
'archive'
,
'--prefix'
,
"
%
s/"
%
self
.
name
]
if
role_version
:
archive_cmd
.
extend
([
'-r'
,
role_version
])
archive_cmd
.
append
(
temp_file
.
name
)
if
scm
==
'git'
:
archive_cmd
=
[
'git'
,
'archive'
,
'--prefix=
%
s/'
%
self
.
name
,
'--output=
%
s'
%
temp_file
.
name
]
if
role_version
:
archive_cmd
.
append
(
role_version
)
else
:
archive_cmd
.
append
(
'HEAD'
)
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
self
.
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
archive_cmd
))
popen
=
subprocess
.
Popen
(
archive_cmd
,
cwd
=
os
.
path
.
join
(
tempdir
,
self
.
name
),
stderr
=
devnull
,
stdout
=
devnull
)
rc
=
popen
.
wait
()
if
rc
!=
0
:
self
.
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
archive_cmd
))
self
.
display
.
display
(
" in directory
%
s"
%
tempdir
)
return
False
rmtree
(
tempdir
,
ignore_errors
=
True
)
return
temp_file
.
name
@property
@property
def
metadata
(
self
):
def
metadata
(
self
):
"""
"""
...
@@ -127,7 +84,7 @@ class GalaxyRole(object):
...
@@ -127,7 +84,7 @@ class GalaxyRole(object):
f
=
open
(
meta_path
,
'r'
)
f
=
open
(
meta_path
,
'r'
)
self
.
_metadata
=
yaml
.
safe_load
(
f
)
self
.
_metadata
=
yaml
.
safe_load
(
f
)
except
:
except
:
self
.
display
.
vvvvv
(
"Unable to load metadata for
%
s"
%
self
.
name
)
display
.
vvvvv
(
"Unable to load metadata for
%
s"
%
self
.
name
)
return
False
return
False
finally
:
finally
:
f
.
close
()
f
.
close
()
...
@@ -148,7 +105,7 @@ class GalaxyRole(object):
...
@@ -148,7 +105,7 @@ class GalaxyRole(object):
f
=
open
(
info_path
,
'r'
)
f
=
open
(
info_path
,
'r'
)
self
.
_install_info
=
yaml
.
safe_load
(
f
)
self
.
_install_info
=
yaml
.
safe_load
(
f
)
except
:
except
:
self
.
display
.
vvvvv
(
"Unable to load Galaxy install info for
%
s"
%
self
.
name
)
display
.
vvvvv
(
"Unable to load Galaxy install info for
%
s"
%
self
.
name
)
return
False
return
False
finally
:
finally
:
f
.
close
()
f
.
close
()
...
@@ -202,7 +159,7 @@ class GalaxyRole(object):
...
@@ -202,7 +159,7 @@ class GalaxyRole(object):
archive_url
=
'https://github.com/
%
s/
%
s/archive/
%
s.tar.gz'
%
(
role_data
[
"github_user"
],
role_data
[
"github_repo"
],
self
.
version
)
archive_url
=
'https://github.com/
%
s/
%
s/archive/
%
s.tar.gz'
%
(
role_data
[
"github_user"
],
role_data
[
"github_repo"
],
self
.
version
)
else
:
else
:
archive_url
=
self
.
src
archive_url
=
self
.
src
self
.
display
.
display
(
"- downloading role from
%
s"
%
archive_url
)
display
.
display
(
"- downloading role from
%
s"
%
archive_url
)
try
:
try
:
url_file
=
urlopen
(
archive_url
)
url_file
=
urlopen
(
archive_url
)
...
@@ -216,7 +173,7 @@ class GalaxyRole(object):
...
@@ -216,7 +173,7 @@ class GalaxyRole(object):
except
:
except
:
# TODO: better urllib2 error handling for error
# TODO: better urllib2 error handling for error
# messages that are more exact
# messages that are more exact
self
.
display
.
error
(
"failed to download the file."
)
display
.
error
(
"failed to download the file."
)
return
False
return
False
...
@@ -225,7 +182,7 @@ class GalaxyRole(object):
...
@@ -225,7 +182,7 @@ class GalaxyRole(object):
# to the specified (or default) roles directory
# to the specified (or default) roles directory
if
not
tarfile
.
is_tarfile
(
role_filename
):
if
not
tarfile
.
is_tarfile
(
role_filename
):
self
.
display
.
error
(
"the file downloaded was not a tar.gz"
)
display
.
error
(
"the file downloaded was not a tar.gz"
)
return
False
return
False
else
:
else
:
if
role_filename
.
endswith
(
'.gz'
):
if
role_filename
.
endswith
(
'.gz'
):
...
@@ -241,32 +198,32 @@ class GalaxyRole(object):
...
@@ -241,32 +198,32 @@ class GalaxyRole(object):
meta_file
=
member
meta_file
=
member
break
break
if
not
meta_file
:
if
not
meta_file
:
self
.
display
.
error
(
"this role does not appear to have a meta/main.yml file."
)
display
.
error
(
"this role does not appear to have a meta/main.yml file."
)
return
False
return
False
else
:
else
:
try
:
try
:
self
.
_metadata
=
yaml
.
safe_load
(
role_tar_file
.
extractfile
(
meta_file
))
self
.
_metadata
=
yaml
.
safe_load
(
role_tar_file
.
extractfile
(
meta_file
))
except
:
except
:
self
.
display
.
error
(
"this role does not appear to have a valid meta/main.yml file."
)
display
.
error
(
"this role does not appear to have a valid meta/main.yml file."
)
return
False
return
False
# we strip off the top-level directory for all of the files contained within
# we strip off the top-level directory for all of the files contained within
# the tar file here, since the default is 'github_repo-target', and change it
# the tar file here, since the default is 'github_repo-target', and change it
# to the specified role's name
# to the specified role's name
self
.
display
.
display
(
"- extracting
%
s to
%
s"
%
(
self
.
name
,
self
.
path
))
display
.
display
(
"- extracting
%
s to
%
s"
%
(
self
.
name
,
self
.
path
))
try
:
try
:
if
os
.
path
.
exists
(
self
.
path
):
if
os
.
path
.
exists
(
self
.
path
):
if
not
os
.
path
.
isdir
(
self
.
path
):
if
not
os
.
path
.
isdir
(
self
.
path
):
self
.
display
.
error
(
"the specified roles path exists and is not a directory."
)
display
.
error
(
"the specified roles path exists and is not a directory."
)
return
False
return
False
elif
not
getattr
(
self
.
options
,
"force"
,
False
):
elif
not
getattr
(
self
.
options
,
"force"
,
False
):
self
.
display
.
error
(
"the specified role
%
s appears to already exist. Use --force to replace it."
%
self
.
name
)
display
.
error
(
"the specified role
%
s appears to already exist. Use --force to replace it."
%
self
.
name
)
return
False
return
False
else
:
else
:
# using --force, remove the old path
# using --force, remove the old path
if
not
self
.
remove
():
if
not
self
.
remove
():
self
.
display
.
error
(
"
%
s doesn't appear to contain a role."
%
self
.
path
)
display
.
error
(
"
%
s doesn't appear to contain a role."
%
self
.
path
)
self
.
display
.
error
(
" please remove this directory manually if you really want to put the role here."
)
display
.
error
(
" please remove this directory manually if you really want to put the role here."
)
return
False
return
False
else
:
else
:
os
.
makedirs
(
self
.
path
)
os
.
makedirs
(
self
.
path
)
...
@@ -288,11 +245,11 @@ class GalaxyRole(object):
...
@@ -288,11 +245,11 @@ class GalaxyRole(object):
# write out the install info file for later use
# write out the install info file for later use
self
.
_write_galaxy_install_info
()
self
.
_write_galaxy_install_info
()
except
OSError
as
e
:
except
OSError
as
e
:
self
.
display
.
error
(
"Could not update files in
%
s:
%
s"
%
(
self
.
path
,
str
(
e
)))
display
.
error
(
"Could not update files in
%
s:
%
s"
%
(
self
.
path
,
str
(
e
)))
return
False
return
False
# return the parsed yaml metadata
# return the parsed yaml metadata
self
.
display
.
display
(
"-
%
s was installed successfully"
%
self
.
name
)
display
.
display
(
"-
%
s was installed successfully"
%
self
.
name
)
return
True
return
True
@property
@property
...
@@ -328,20 +285,20 @@ class GalaxyRole(object):
...
@@ -328,20 +285,20 @@ class GalaxyRole(object):
@staticmethod
@staticmethod
def
scm_archive_role
(
scm
,
role_url
,
role_version
,
role_name
):
def
scm_archive_role
(
scm
,
role_url
,
role_version
,
role_name
):
if
scm
not
in
[
'hg'
,
'git'
]:
if
scm
not
in
[
'hg'
,
'git'
]:
self
.
display
.
display
(
"- scm
%
s is not currently supported"
%
scm
)
display
.
display
(
"- scm
%
s is not currently supported"
%
scm
)
return
False
return
False
tempdir
=
tempfile
.
mkdtemp
()
tempdir
=
tempfile
.
mkdtemp
()
clone_cmd
=
[
scm
,
'clone'
,
role_url
,
role_name
]
clone_cmd
=
[
scm
,
'clone'
,
role_url
,
role_name
]
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
try
:
try
:
self
.
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
clone_cmd
))
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
clone_cmd
))
popen
=
subprocess
.
Popen
(
clone_cmd
,
cwd
=
tempdir
,
stdout
=
devnull
,
stderr
=
devnull
)
popen
=
subprocess
.
Popen
(
clone_cmd
,
cwd
=
tempdir
,
stdout
=
devnull
,
stderr
=
devnull
)
except
:
except
:
raise
AnsibleError
(
"error executing:
%
s"
%
" "
.
join
(
clone_cmd
))
raise
AnsibleError
(
"error executing:
%
s"
%
" "
.
join
(
clone_cmd
))
rc
=
popen
.
wait
()
rc
=
popen
.
wait
()
if
rc
!=
0
:
if
rc
!=
0
:
self
.
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
clone_cmd
))
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
clone_cmd
))
self
.
display
.
display
(
" in directory
%
s"
%
tempdir
)
display
.
display
(
" in directory
%
s"
%
tempdir
)
return
False
return
False
temp_file
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'.tar'
)
temp_file
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'.tar'
)
...
@@ -358,16 +315,16 @@ class GalaxyRole(object):
...
@@ -358,16 +315,16 @@ class GalaxyRole(object):
archive_cmd
.
append
(
'HEAD'
)
archive_cmd
.
append
(
'HEAD'
)
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
with
open
(
'/dev/null'
,
'w'
)
as
devnull
:
self
.
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
archive_cmd
))
display
.
display
(
"- executing:
%
s"
%
" "
.
join
(
archive_cmd
))
popen
=
subprocess
.
Popen
(
archive_cmd
,
cwd
=
os
.
path
.
join
(
tempdir
,
role_name
),
popen
=
subprocess
.
Popen
(
archive_cmd
,
cwd
=
os
.
path
.
join
(
tempdir
,
role_name
),
stderr
=
devnull
,
stdout
=
devnull
)
stderr
=
devnull
,
stdout
=
devnull
)
rc
=
popen
.
wait
()
rc
=
popen
.
wait
()
if
rc
!=
0
:
if
rc
!=
0
:
self
.
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
archive_cmd
))
display
.
display
(
"- command
%
s failed"
%
' '
.
join
(
archive_cmd
))
self
.
display
.
display
(
" in directory
%
s"
%
tempdir
)
display
.
display
(
" in directory
%
s"
%
tempdir
)
return
False
return
False
shutil
.
rmtree
(
tempdir
,
ignore_errors
=
True
)
rmtree
(
tempdir
,
ignore_errors
=
True
)
return
temp_file
.
name
return
temp_file
.
name
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