From f2e5dba4922f5f6d7061f305b23123c85798348d Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 25 Jul 2012 03:03:59 -0400 Subject: [PATCH] Add Git repository info to the installation report --- apps/installation/models.py | 35 +++++++++++++++++++++++++++++++++-- requirements/production.txt | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/installation/models.py b/apps/installation/models.py index d1407d0d0b..f4019ba5bb 100644 --- a/apps/installation/models.py +++ b/apps/installation/models.py @@ -2,10 +2,12 @@ import os import sys import platform import uuid +import time import pbs import psutil import requests +from git import Repo try: from pbs import lsb_release, uname @@ -13,6 +15,7 @@ except pbs.CommandNotFound: LSB = False else: LSB = True + from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -67,7 +70,7 @@ class Installation(Singleton): self.add_property(Property('codename', _(u'Codename'), lsb_release('-c','-s'))) self.add_property(Property('sysinfo', _(u'System info'), uname('-a'))) else: - self.add_property(Property('is_posix', _(u'POSIX OS'), False)) + self.add_property(Property('is_lsb', _(u'LSB OS'), False)) self.add_property(Property('architecture', _(u'OS architecture'), platform.architecture())) self.add_property(Property('python_version', _(u'Python version'), platform.python_version())) @@ -91,7 +94,24 @@ class Installation(Singleton): self.add_property(Property('mayan_version', _(u'Mayan EDMS version'), mayan_version)) self.add_property(Property('fabfile', _(u'Installed via fabfile'), os.path.exists(FABFILE_MARKER))) - + + try: + repo = Repo(settings.PROJECT_ROOT) + except: + self.add_property(Property('is_git_repo', _(u'Running from a Git repository'), False)) + else: + repo.config_reader() + headcommit = repo.head.commit + self.add_property(Property('is_git_repo', _(u'Running from a Git repository'), True)) + self.add_property(Property('repo_remotes', _(u'Repository remotes'), ', '.join([unicode(remote) for remote in repo.remotes]))) + self.add_property(Property('repo_head_reference', _(u'Branch'), repo.head.reference)) + self.add_property(Property('headcommit_hexsha', _(u'HEAD commit hex SHA'), headcommit.hexsha)) + self.add_property(Property('headcommit_author', _(u'HEAD commit author'), headcommit.author)) + self.add_property(Property('headcommit_authored_date', _(u'HEAD commit authored date'), time.asctime(time.gmtime(headcommit.authored_date)))) + self.add_property(Property('headcommit_committer', _(u'HEAD commit committer'), headcommit.committer)) + self.add_property(Property('headcommit_committed_date', _(u'HEAD commit committed date'), time.asctime(time.gmtime(headcommit.committed_date)))) + self.add_property(Property('headcommit_message', _(u'HEAD commit message'), headcommit.message)) + def __getattr__(self, name): self.set_properties() try: @@ -133,6 +153,17 @@ class Installation(Singleton): 'fabfile': unicode(self.fabfile), } ) + if self.is_git_repo: + dictionary.update( + { + 'repo_remotes': unicode(self.repo_remotes), + 'repo_head_reference': unicode(self.repo_head_reference), + 'headcommit_hexsha': unicode(self.headcommit_hexsha), + 'headcommit_authored_date': unicode(self.headcommit_authored_date), + 'headcommit_committed_date': unicode(self.headcommit_committed_date), + 'headcommit_message': unicode(self.headcommit_message), + } + ) requests.post(FORM_SUBMIT_URL, data={'formkey': FORM_KEY, FORM_RECEIVER_FIELD: dumps(dictionary)}, timeout=TIMEOUT) except (requests.exceptions.Timeout, requests.exceptions.ConnectionError): diff --git a/requirements/production.txt b/requirements/production.txt index 0e0f8beed7..258332f21f 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -19,3 +19,4 @@ python-hkp==0.1.3 requests==0.13.1 pbs==0.105 psutil==0.5.1 +GitPython==0.3.2.RC1