Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
f0670efa
Commit
f0670efa
authored
Oct 03, 2015
by
LE GAC Renaud
Browse files
Clean build_version.py and migrate to argparse.
parent
0d5b758d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
372 deletions
+72
-372
build_version.py
build_version.py
+72
-372
No files found.
build_version.py
View file @
f0670efa
...
...
@@ -9,23 +9,20 @@
DESCRIPTION
Helper script to build a version of the track_publications.
Push version number in the CHANGELOG.
Commit the new version in git and tag it
EXAMPLES
> build_version -h
AUTHOR
R. Le Gac, renaud.legac@
free
.fr
R. Le Gac, renaud.legac@
cppm.in2p3
.fr
Copyright (c) 2012-2015 R. Le Gac
"""
import
argparse
import
datetime
import
optparse
import
os
import
re
import
sys
...
...
@@ -33,7 +30,7 @@ import tempfile
from
os.path
import
join
as
opj
from
subprocess
import
call
,
check_output
from
subprocess
import
call
# constants
APP
=
os
.
path
.
basename
(
os
.
getcwd
())
...
...
@@ -146,7 +143,7 @@ def build_pdf(doc):
def
change_log
():
"""Commit CHANGELOG
and App.js
.
"""Commit CHANGELOG.
"""
print
"Commit CHANGELOG..."
...
...
@@ -160,115 +157,13 @@ def change_log():
git
(
"add"
,
CHANGELOG
)
print
'git commit'
msg
=
"Start release
cycle
%s"
%
get_version
()
msg
=
"Start release %s"
%
get_version
()
git
(
"commit -m"
,
msg
)
def
close_bugfix
():
"""Close the bugfix cycle.
"""
print
"Close the bugfix cycle..."
identifier
=
select_identifier
(
"bugfix"
)
if
not
identifier
:
sys
.
exit
(
0
)
branch
=
"bugfix-%s"
%
identifier
git
(
"checkout develop"
)
git
(
"merge --no-ff"
,
branch
)
rep
=
raw_input
(
"Delete the locale branch %s [y/N]"
%
branch
)
if
rep
==
'y'
:
git
(
"branch -d"
,
branch
)
def
close_feature
():
"""Close the feature cycle.
"""
print
"Close the feature cycle..."
identifier
=
select_identifier
(
"feature"
)
if
not
identifier
:
sys
.
exit
(
0
)
branch
=
"feature-%s"
%
identifier
git
(
"checkout develop"
)
git
(
"merge --no-ff"
,
branch
)
rep
=
raw_input
(
"Delete branch %s [y/N]:"
%
branch
)
if
rep
==
'y'
:
git
(
"branch -d"
,
branch
)
def
close_hotfix
():
"""Close the hotfix cycle.
"""
print
"Close the hotfix cycle..."
release
=
select_identifier
(
"hotfix"
)
if
not
release
:
sys
.
exit
(
0
)
branch
=
"hotfix-%s"
%
release
git
(
"checkout master"
)
git
(
"merge --no-ff"
,
branch
)
msg
=
"Release %s"
%
release
git
(
"tag -a"
,
release
,
"-m"
,
msg
)
git
(
"checkout develop"
)
git
(
"merge --no-ff"
,
branch
)
rep
=
raw_input
(
"Delete branch %s [y/N]:"
%
branch
)
if
rep
==
"y"
:
git
(
"branch -d"
,
branch
)
git
(
"checkout master"
)
build
()
print
"The hotfix cycle "
,
release
,
"is over"
def
close_release
():
"""Close the release cycle.
"""
print
"Close the release cycle..."
release
=
select_identifier
(
"release"
)
if
not
release
:
sys
.
exit
(
0
)
branch
=
"release-%s"
%
release
msg
=
"Release %s"
%
release
print
msg
git
(
"checkout develop"
)
git
(
"merge --no-ff"
,
branch
,
"-m"
,
msg
)
git
(
"checkout master"
)
git
(
"merge --no-ff"
,
branch
,
"-m"
,
msg
)
git
(
"tag -a"
,
release
,
"-m"
,
msg
)
rep
=
raw_input
(
"Delete branch %s [y/N]:"
%
branch
)
if
rep
==
"y"
:
git
(
"branch -d"
,
branch
)
build
()
print
"The release cycle "
,
release
,
"is over"
def
compile_js
():
"""compile_js the javascript code and generate the debug version
as well as the minified version
of the dbui library
.
as well as the minified version.
The compiler verify that the code complied with the class model
and order the file in the proper way.
...
...
@@ -285,7 +180,7 @@ def compile_js():
This operation relies on the Sencha Cmd:
http://www.sencha.com/products/sencha-cmd/download
The details docum
a
ntation can be found:
The details docum
e
ntation can be found:
http://docs.sencha.com/extjs/4.2.2/#!/guide/command
"""
...
...
@@ -345,25 +240,6 @@ def get_version():
return
""
def
get_identifiers
(
branch_type
):
"""Return the list of identifiers for the branch of type branch_type.
Args:
branchType (str): one of "feature", "hotfix", "release" or "bugfix"
Return (str): a list of branch identifiers of type branch_type
"""
if
not
os
.
path
.
exists
(
GIT
):
print
'
\n\t
The application git is missing !'
sys
.
exit
(
-
1
)
output
=
check_output
([
GIT
,
"branch"
,
"--list"
,
branch_type
+
"-*"
])
output
=
output
.
rstrip
().
split
(
"
\n
"
)
idx
=
len
(
branch_type
)
+
3
return
[
branch
[
idx
:]
for
branch
in
output
]
def
git
(
*
args
,
**
kwargs
):
"""run any git instruction:
...
...
@@ -427,40 +303,8 @@ def jsduck():
print
"JavaScript documentation in"
,
JSDOC
def
select_identifier
(
branch_type
):
"""Select the identifier to close.
Args:
branch_type (str): one of "feature", "hotfix", "release" or "bugfix"
Returns:
str: the selected identifier or an empty string if none is selected
"""
identifiers
=
get_identifiers
(
branch_type
)
if
not
identifiers
:
print
"Couldn't find any %s branch"
%
branch_type
return
""
if
len
(
identifiers
)
==
1
:
rep
=
raw_input
(
"Close %s '%s' [y/N]:"
%
(
branch_type
,
identifiers
[
0
]))
if
rep
==
'y'
:
identifier
=
identifiers
[
0
]
else
:
return
""
else
:
print
'%s identifiers:'
%
branch_type
print
' '
,
'
\n
'
.
join
(
identifiers
)
identifier
=
raw_input
(
"Select the %s identifier:"
%
branch_type
)
if
not
identifier
in
identifiers
:
return
""
return
identifier
def
set_version
(
version
):
"""Set release identifier in CHANGELOG
and App.js
"""Set release identifier in CHANGELOG
.
Args:
version (str): release identifier
...
...
@@ -532,67 +376,14 @@ def sphinx(*args, **kwargs):
call
(
cmd
,
**
kwargs
)
def
start_bugfix
():
"""Start the bugfix cycle.
"""
print
"Start the bugfix cycle..."
issue_number
=
raw_input
(
"Enter the bugfix issue number [None]:"
)
if
issue_number
and
not
issue_number
.
isdigit
():
print
"The issue number must be a number"
sys
.
exit
(
-
1
)
rep
=
raw_input
(
"Enter the bugfix identifier:"
)
if
not
rep
:
sys
.
exit
(
0
)
if
not
issue_number
:
branch
=
"bugfix-%s"
%
rep
else
:
branch
=
"bugfix-%s-%s"
%
(
issue_number
,
rep
)
git
(
"checkout -b"
,
branch
,
"develop"
)
def
start_feature
():
"""Start the feature cycle.
"""
print
"Start the feature cycle..."
rep
=
raw_input
(
"Enter the feature identifier:"
)
if
not
rep
:
sys
.
exit
(
0
)
branch
=
"feature-%s"
%
rep
git
(
"checkout -b"
,
branch
,
"develop"
)
def
start_hotfix
():
"""Start the hotfix cycle.
"""
print
"Start the hotfix cycle..."
print
"The current release is"
,
get_version
()
rep
=
raw_input
(
"Enter the hotfix release identifer:"
)
if
not
rep
:
sys
.
exit
(
0
)
branch
=
"hotfix-%s"
%
rep
git
(
"checkout -b"
,
branch
,
"master"
)
set_version
(
rep
)
change_log
()
def
start_release
():
"""Start the release cycle.
"""
print
"Start the release cycle..."
git
(
"checkout"
,
"master"
)
old_release
=
get_version
()
print
"Current release is"
,
old_release
...
...
@@ -600,9 +391,6 @@ def start_release():
if
not
new_release
:
sys
.
exit
(
0
)
branch
=
"release-%s"
%
new_release
git
(
"checkout"
,
"-b"
,
branch
,
"develop"
)
set_version
(
new_release
)
change_log
()
build
()
...
...
@@ -611,180 +399,92 @@ def start_release():
if
__name__
==
'__main__'
:
# define script options
OPS
=
optparse
.
OptionParser
()
OPS
.
add_option
(
"-a"
,
"--api-doc"
,
action
=
"store_true"
,
dest
=
"api_doc"
,
help
=
"build the API documentation in HTML."
)
OPS
.
add_option
(
"--api-pdf"
,
action
=
"store_true"
,
dest
=
"api_pdf"
,
help
=
"build the API documentation in PDF."
)
OPS
.
add_option
(
"--start-bugfix"
,
action
=
"store_true"
,
dest
=
"start_bugfix"
,
help
=
"start the bugfix cycle."
)
OPS
.
add_option
(
"--start-feature"
,
action
=
"store_true"
,
dest
=
"start_feature"
,
help
=
"start the feature cycle."
)
OPS
.
add_option
(
"--start-hotfix"
,
action
=
"store_true"
,
dest
=
"start_hotfix"
,
help
=
"start the hotfix cycle."
)
OPS
.
add_option
(
"--start-release"
,
action
=
"store_true"
,
dest
=
"start_release"
,
help
=
"start the new release branch cycle."
)
OPS
.
add_option
(
"--close-hotfix"
,
action
=
"store_true"
,
dest
=
"close_hotfix"
,
help
=
"close the hotfix branch cycle."
)
OPS
.
add_option
(
"--close-feature"
,
action
=
"store_true"
,
dest
=
"close_feature"
,
help
=
"close the feature branch cycle."
)
OPS
.
add_option
(
"--close-bugfix"
,
action
=
"store_true"
,
dest
=
"close_bugfix"
,
help
=
"close the bugfix branch cycle."
)
OPS
.
add_option
(
"--close-release"
,
action
=
"store_true"
,
dest
=
"close_release"
,
help
=
"close the release branch cycle."
)
OPS
.
add_option
(
"-c"
,
"--compile"
,
action
=
"store_true"
,
dest
=
"compile"
,
help
=
"compile the javascript library."
)
OPS
.
add_option
(
"--commit-changelog"
,
action
=
"store_true"
,
dest
=
"changelog"
,
help
=
"commit CHANGELOG and App.js."
)
OPS
.
add_option
(
"-j"
,
"--jsduck"
,
action
=
"store_true"
,
dest
=
"jsduck"
,
help
=
"build the JavaScript documentation."
)
OPS
.
add_option
(
"-r"
,
"--reference-doc"
,
action
=
"store_true"
,
dest
=
"reference_doc"
,
help
=
"build the reference manual in HTML."
)
OPS
.
add_option
(
"--reference-pdf"
,
action
=
"store_true"
,
dest
=
"reference_pdf"
,
help
=
"build the reference manual in PDF."
)
OPS
.
add_option
(
"--write-release"
,
action
=
"store_true"
,
dest
=
"release"
,
help
=
"write the release number in CHANGELOG and App.js."
)
OPS
.
add_option
(
"-u"
,
"--user-doc"
,
action
=
"store_true"
,
dest
=
"user_doc"
,
help
=
"build the user manual in HTML."
)
OPS
.
add_option
(
"--user-pdf"
,
action
=
"store_true"
,
dest
=
"user_pdf"
,
help
=
"build the user manual in PDF."
)
OPS
.
add_option
(
"-v"
,
"--version"
,
action
=
"store_true"
,
dest
=
"version"
,
help
=
"get the current release identifier."
)
OPS
.
set_defaults
(
api_doc
=
False
,
api_pdf
=
False
,
close_bugfix
=
False
,
close_feature
=
False
,
close_hotfix
=
False
,
close_release
=
False
,
changelog
=
False
,
compile
=
False
,
jsduck
=
False
,
reference_doc
=
False
,
reference_pdf
=
False
,
release
=
False
,
start_bugfix
=
False
,
start_feature
=
False
,
start_hotfix
=
False
,
start_release
=
False
,
user_doc
=
False
,
user_pdf
=
False
,
version
=
False
)
(
OPT
,
ARGS
)
=
OPS
.
parse_args
()
if
OPT
.
api_doc
:
sphinx
(
"-b html"
,
opj
(
DOCSRC
,
API
),
opj
(
DOCS
,
API
))
APS
=
argparse
.
ArgumentParser
()
if
OPT
.
api_pdf
:
build_pdf
(
API
)
APS
.
add_argument
(
"-a"
,
"--api-doc"
,
action
=
"store_true"
,
help
=
"build the API documentation in HTML."
)
APS
.
add_argument
(
"-A"
,
"--api-pdf"
,
action
=
"store_true"
,
help
=
"build the API documentation in PDF."
)
if
OPT
.
close_bugfix
:
close_bugfix
()
APS
.
add_argument
(
"-c"
,
"--compile"
,
action
=
"store_true"
,
help
=
"compile the javascript library."
)
if
OPT
.
close_feature
:
close_feature
()
APS
.
add_argument
(
"-C"
,
"--commit-changelog"
,
action
=
"store_true"
,
help
=
"commit CHANGELOG."
)
if
OPT
.
close_hotfix
:
close_hotfix
()
APS
.
add_argument
(
"-j"
,
"--jsduck"
,
action
=
"store_true"
,
help
=
"build the JavaScript documentation."
)
if
OPT
.
close_release
:
close_release
()
APS
.
add_argument
(
"-r"
,
"--reference-doc"
,
action
=
"store_true"
,
help
=
"build the reference manual in HTML."
)
if
OPT
.
compile
:
APS
.
add_argument
(
"-R"
,
"--reference-pdf"
,
action
=
"store_true"
,
help
=
"build the reference manual in PDF."
)
APS
.
add_argument
(
"-s"
,
"--start-release"
,
action
=
"store_true"
,
help
=
"start the new release."
)
APS
.
add_argument
(
"-u"
,
"--user-doc"
,
action
=
"store_true"
,
help
=
"build the user manual in HTML."
)
APS
.
add_argument
(
"-U"
,
"--user-pdf"
,
action
=
"store_true"
,
help
=
"build the user manual in PDF."
)
APS
.
add_argument
(
"-v"
,
"--version"
,
action
=
"store_true"
,
help
=
"get the current release identifier."
)
APS
.
add_argument
(
"-w"
,
"--write-release"
,
action
=
"store_true"
,
help
=
"write the release number in CHANGELOG."
)
ARGS
=
APS
.
parse_args
()
if
ARGS
.
api_doc
:
sphinx
(
"-b html"
,
opj
(
DOCSRC
,
API
),
opj
(
DOCS
,
API
))
if
ARGS
.
api_pdf
:
build_pdf
(
API
)
if
ARGS
.
compile
:
compile_js
()
if
OPT
.
changelog
:
if
ARGS
.
commit_
changelog
:
change_log
()
if
OPT
.
jsduck
:
if
ARGS
.
jsduck
:
jsduck
()
if
OPT
.
release
:
if
ARGS
.
write_
release
:
set_version
(
raw_input
(
MSG_RELEASE
))
if
OPT
.
reference_doc
:
if
ARGS
.
reference_doc
:
sphinx
(
"-b html"
,
opj
(
DOCSRC
,
REFERENCE
),
opj
(
DOCS
,
REFERENCE
))
if
OPT
.
reference_pdf
:
if
ARGS
.
reference_pdf
:
build_pdf
(
REFERENCE
)
if
OPT
.
start_bugfix
:
start_bugfix
()
if
OPT
.
start_feature
:
start_feature
()
if
OPT
.
start_hotfix
:
start_hotfix
()
if
OPT
.
start_release
:
if
ARGS
.
start_release
:
start_release
()
if
OPT
.
user_doc
:
if
ARGS
.
user_doc
:
sphinx
(
"-b html"
,
opj
(
DOCSRC
,
USER
),
opj
(
DOCS
,
USER
))
if
OPT
.
user_pdf
:
if
ARGS
.
user_pdf
:
build_pdf
(
USER
)
if
OPT
.
version
:
if
ARGS
.
version
:
print
"
\n
The current release is %s
\n
"
%
get_version
()
sys
.
exit
(
0
)
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