Add Git repository info to the installation report

This commit is contained in:
Roberto Rosario
2012-07-25 03:03:59 -04:00
parent 48df2e026d
commit f2e5dba492
2 changed files with 34 additions and 2 deletions

View File

@@ -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):

View File

@@ -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