Skip to content

Commit

Permalink
Versioneer now also returns and persists the branch from which OctoPr…
Browse files Browse the repository at this point in the history
…int was installed

Changed version output accordingly to now display "{version} ({branch} branch)" if branch information is available (which should be the case if installation was performed from git).
(cherry picked from commit a48b5de)
  • Loading branch information
foosel committed Sep 3, 2014
1 parent e51d943 commit 45c1958
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/octoprint/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def versions_from_lookup(lookup, root, verbose=False):
if dirty:
version += "-dirty"
full += "-dirty"
return {"version": version, "full": full}
return {"version": version, "full": full, "branch": current_branch}

return {}

Expand Down Expand Up @@ -195,7 +195,14 @@ def versions_from_vcs(tag_prefix, root, verbose=False):
full = stdout.strip()
if tag.endswith("-dirty"):
full += "-dirty"
return {"version": tag, "full": full}

stdout = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
cwd=root)
if stdout is None:
branch = None
else:
branch = stdout.strip()
return {"version": tag, "full": full, "branch": branch}


def versions_from_parentdir(parentdir_prefix, root, verbose=False):
Expand Down
9 changes: 7 additions & 2 deletions src/octoprint/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
import octoprint._version


VERSION = octoprint._version.get_versions()['version']

versions = octoprint._version.get_versions()
VERSION = versions['version']
BRANCH = versions['branch'] if 'branch' in versions else None
DISPLAY_VERSION = "%s (%s branch)" % (VERSION, BRANCH) if BRANCH else VERSION
del versions

@app.route("/")
def index():
Expand All @@ -58,6 +62,7 @@ def index():
firstRun=settings().getBoolean(["server", "firstRun"]) and (userManager is None or not userManager.hasBeenCustomized()),
debug=debug,
version=VERSION,
display_version=DISPLAY_VERSION,
stylesheet=settings().get(["devel", "stylesheet"]),
gcodeMobileThreshold=settings().get(["gcodeViewer", "mobileSizeThreshold"]),
gcodeThreshold=settings().get(["gcodeViewer", "sizeThreshold"])
Expand Down Expand Up @@ -126,7 +131,7 @@ def run(self):
self._initLogging(self._debug)
logger = logging.getLogger(__name__)

logger.info("Starting OctoPrint (%s)" % VERSION)
logger.info("Starting OctoPrint %s" % DISPLAY_VERSION)

eventManager = events.eventManager()
gcodeManager = gcodefiles.GcodeManager()
Expand Down
2 changes: 1 addition & 1 deletion src/octoprint/templates/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
</div>
<div class="footer">
<ul class="pull-left muted">
<li><small>Version: <span class="version">{{ version }}</span></small></li>
<li><small>Version: <span class="version">{{ display_version }}</span></small></li>
</ul>
<ul class="pull-right">
<li><a href="http://octoprint.org"><i class="icon-home"></i> Homepage</a></li>
Expand Down
25 changes: 21 additions & 4 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def versions_from_lookup(lookup, root, verbose=False):
if dirty:
version += "-dirty"
full += "-dirty"
return {"version": version, "full": full}
return {"version": version, "full": full, "branch": current_branch}
return {}
Expand Down Expand Up @@ -454,7 +454,14 @@ def versions_from_vcs(tag_prefix, root, verbose=False):
full = stdout.strip()
if tag.endswith("-dirty"):
full += "-dirty"
return {"version": tag, "full": full}
stdout = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
cwd=root)
if stdout is None:
branch = None
else:
branch = stdout.strip()
return {"version": tag, "full": full, "branch": branch}
def versions_from_parentdir(parentdir_prefix, root, verbose=False):
Expand Down Expand Up @@ -685,7 +692,7 @@ def versions_from_lookup(lookup, root, verbose=False):
if dirty:
version += "-dirty"
full += "-dirty"
return {"version": version, "full": full}
return {"version": version, "full": full, "branch": current_branch}

return {}

Expand Down Expand Up @@ -715,7 +722,14 @@ def versions_from_vcs(tag_prefix, root, verbose=False):
full = stdout.strip()
if tag.endswith("-dirty"):
full += "-dirty"
return {"version": tag, "full": full}

stdout = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
cwd=root)
if stdout is None:
branch = None
else:
branch = stdout.strip()
return {"version": tag, "full": full, "branch": branch}


def versions_from_parentdir(parentdir_prefix, root, verbose=False):
Expand Down Expand Up @@ -787,7 +801,10 @@ def do_vcs_install(manifest_in, versionfile_source, ipy):
version_version = '%(version)s'
version_full = '%(full)s'
version_branch = %(branch)r
def get_versions(default={}, verbose=False):
if version_branch:
return {'version': version_version, 'full': version_full, 'branch': version_branch}
return {'version': version_version, 'full': version_full}
"""
Expand Down

0 comments on commit 45c1958

Please sign in to comment.