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
fde329fb
Commit
fde329fb
authored
Aug 08, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitversion' of
https://github.com/willthames/ansible
into devel
parents
176bf3cb
9a50ed9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletions
+33
-1
lib/ansible/utils.py
+33
-1
No files found.
lib/ansible/utils.py
View file @
fde329fb
...
...
@@ -39,6 +39,12 @@ try:
except
ImportError
:
from
md5
import
md5
as
_md5
try
:
import
git
HAS_GIT
=
True
except
ImportError
:
HAS_GIT
=
False
###############################################################
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
###############################################################
...
...
@@ -287,6 +293,32 @@ def default(value, function):
return
function
()
return
value
def
_gitinfo
():
''' returns a string containing git branch and commit id
using gitpython if installed and native file operations if not '''
result
=
None
repo_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
'..'
,
'.git'
)
if
os
.
path
.
exists
(
repo_path
):
if
HAS_GIT
:
repo
=
git
.
Repo
(
repo_path
)
head
=
repo
.
head
branch
=
head
.
reference
.
name
commit
=
head
.
commit
.
hexsha
[:
10
]
else
:
with
open
(
os
.
path
.
join
(
repo_path
,
"HEAD"
))
as
f
:
branch
=
f
.
readline
()
.
split
(
'/'
)[
-
1
]
.
rstrip
(
"
\n
"
)
with
open
(
os
.
path
.
join
(
repo_path
,
"refs"
,
"heads"
,
branch
))
as
f
:
commit
=
f
.
readline
()[:
10
]
result
=
"({0}) [{1}]"
.
format
(
branch
,
commit
)
return
result
def
version
(
prog
):
result
=
"{0} {1}"
.
format
(
prog
,
__version__
)
gitinfo
=
_gitinfo
()
if
gitinfo
:
result
=
result
+
" {0}"
.
format
(
gitinfo
)
return
result
####################################################################
# option handling code for /usr/bin/ansible and ansible-playbook
# below this line
...
...
@@ -301,7 +333,7 @@ class SortedOptParser(optparse.OptionParser):
def
base_parser
(
constants
=
C
,
usage
=
""
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
,
connect_opts
=
False
):
''' create an options parser for any ansible script '''
parser
=
SortedOptParser
(
usage
,
version
=
"
%
prog "
+
__version__
)
parser
=
SortedOptParser
(
usage
,
version
=
version
(
"
%
prog"
)
)
parser
.
add_option
(
'-v'
,
'--verbose'
,
default
=
False
,
action
=
"store_true"
,
help
=
'verbose mode'
)
parser
.
add_option
(
'-f'
,
'--forks'
,
dest
=
'forks'
,
default
=
constants
.
DEFAULT_FORKS
,
type
=
'int'
,
...
...
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