From 77f95ece65628db007376fd0177ec701a94b4a28 Mon Sep 17 00:00:00 2001 From: Jake Davis Date: Sun, 21 Oct 2012 10:25:01 -0500 Subject: Git.py - fallback to native git when dulwich not installed Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Server/Plugins/Git.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Git.py b/src/lib/Bcfg2/Server/Plugins/Git.py index 56f05e4f6..177770a12 100644 --- a/src/lib/Bcfg2/Server/Plugins/Git.py +++ b/src/lib/Bcfg2/Server/Plugins/Git.py @@ -1,7 +1,12 @@ """ The Git plugin provides a revision interface for Bcfg2 repos using git. """ -from dulwich.repo import Repo +try: + from dulwich.repo import Repo +except ImportError: + # fallback to shell commands when dulwich unavailable + from subprocess import Popen, PIPE + import Bcfg2.Server.Plugin @@ -22,6 +27,11 @@ class Git(Bcfg2.Server.Plugin.Plugin, """Read git revision information for the Bcfg2 repository.""" try: return Repo(self.datastore).head() + except NameError: + return Popen("env LC_ALL=C git log -1 --pretty=format:%H", + shell=True, + cwd=self.datastore, + stdout=PIPE).stdout.readline() except: msg = "Failed to read git repository" self.logger.error(msg) -- cgit v1.2.3-1-g7c22