This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
forked from ansible/mazer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move impl of
mazer version
from actions->mazer_version
Move the impl details of collecting the mazer version info for `mazer version` to ansible_galaxy.mazer_version so that other modules can use it (namely, ansible_galaxy.cli.galaxy for logging info at cli startup) Fixes ansible#267
- Loading branch information
Showing
4 changed files
with
90 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,12 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
from ansible_galaxy.utils.text import to_text | ||
from ansible_galaxy import mazer_version | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
VERSION_FIELDS = ('name', 'version', 'config_file', 'uname', 'executable_location', 'python_version', 'python_executable') | ||
|
||
|
||
def version_data(config_file_path, cli_version, argv): | ||
data = {} | ||
|
||
data['name'] = 'mazer' | ||
data['version'] = cli_version | ||
data['executable_location'] = argv[0] | ||
data['uname'] = u', '.join(os.uname()) | ||
|
||
sys_ver = u"%s" % ''.join(sys.version.splitlines()) | ||
|
||
data['python_version'] = sys_ver | ||
data['python_executable'] = sys.executable | ||
|
||
if config_file_path: | ||
data['config_file'] = to_text(config_file_path) | ||
else: | ||
data['config_file'] = u'No config file found; using defaults' | ||
|
||
return data | ||
|
||
|
||
def version_repr(version_data): | ||
lines = [] | ||
|
||
for field in VERSION_FIELDS: | ||
lines.append(u'%s = %s' % (field, version_data.get(field, ''))) | ||
|
||
buf = u'\n'.join(lines) | ||
return buf | ||
|
||
|
||
def version(config_file_path, cli_version, display_callback=None): | ||
version_buf = version_repr(version_data(config_file_path, cli_version, sys.argv)) | ||
version_buf = mazer_version.version_repr(mazer_version.version_data(config_file_path, cli_version, sys.argv)) | ||
display_callback(version_buf) | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
from ansible_galaxy.utils.text import to_text | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
VERSION_FIELDS = ('name', 'version', 'config_file', 'uname', 'executable_location', 'python_version', 'python_executable') | ||
|
||
|
||
def version_data(config_file_path, cli_version, argv): | ||
data = {} | ||
|
||
data['name'] = 'mazer' | ||
data['version'] = cli_version | ||
data['executable_location'] = argv[0] | ||
data['uname'] = u', '.join(os.uname()) | ||
|
||
sys_ver = u"%s" % ''.join(sys.version.splitlines()) | ||
|
||
data['python_version'] = sys_ver | ||
data['python_executable'] = sys.executable | ||
|
||
if config_file_path: | ||
data['config_file'] = to_text(config_file_path) | ||
else: | ||
data['config_file'] = u'No config file found; using defaults' | ||
|
||
return data | ||
|
||
|
||
def version_repr(version_data): | ||
lines = [] | ||
|
||
for field in VERSION_FIELDS: | ||
lines.append(u'%s = %s' % (field, version_data.get(field, ''))) | ||
|
||
buf = u'\n'.join(lines) | ||
return buf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
import logging | ||
|
||
from ansible_galaxy import mazer_version | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def test_version_data(): | ||
config_path = '/dev/null/some/faux/mazer.yml' | ||
cli_version = '1.2.3' | ||
args = ['/bin/mazer', 'version'] | ||
|
||
res = mazer_version.version_data(config_file_path=config_path, | ||
cli_version=cli_version, | ||
argv=args) | ||
|
||
log.debug('res: %s', res) | ||
|
||
assert isinstance(res, dict) | ||
|
||
for field in mazer_version.VERSION_FIELDS: | ||
assert field in res | ||
|
||
assert res['config_file'] == config_path | ||
assert res['version'] == cli_version | ||
assert res['executable_location'] == args[0] | ||
|
||
|
||
def test_version_repr(): | ||
config_path = '/dev/null/some/faux/mazer.yml' | ||
cli_version = '1.2.3' | ||
args = ['/bin/mazer', 'version'] | ||
|
||
data = mazer_version.version_data(config_file_path=config_path, | ||
cli_version=cli_version, | ||
argv=args) | ||
|
||
res = mazer_version.version_repr(data) | ||
assert 'mazer.yml' in res | ||
|
||
|
||
def test_version_repr_empty_data(): | ||
data = {} | ||
res = mazer_version.version_repr(data) | ||
|
||
assert 'name =' in res | ||
assert 'version =' in res |