Import and PEP8 cleanups
This commit is contained in:
@@ -5,13 +5,12 @@ from south.signals import post_migrate
|
||||
from project_tools.api import register_tool
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.db.models.signals import post_save
|
||||
from django.db.utils import DatabaseError
|
||||
from django.db import transaction
|
||||
|
||||
from .links import installation_details
|
||||
from .models import Installation
|
||||
|
||||
|
||||
|
||||
@receiver(post_migrate, dispatch_uid='trigger_first_time')
|
||||
def trigger_first_time(sender, **kwargs):
|
||||
@@ -27,7 +26,7 @@ def check_first_run():
|
||||
details = Installation.objects.get()
|
||||
except DatabaseError:
|
||||
# Avoid database errors when the app tables haven't been created yet
|
||||
transaction.rollback()
|
||||
transaction.rollback()
|
||||
else:
|
||||
if details.is_first_run:
|
||||
details.submit()
|
||||
|
||||
@@ -15,7 +15,7 @@ except pbs.CommandNotFound:
|
||||
LSB = False
|
||||
else:
|
||||
LSB = True
|
||||
|
||||
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -34,18 +34,19 @@ FORM_RECEIVER_FIELD = 'entry.0.single'
|
||||
TIMEOUT = 5
|
||||
FABFILE_MARKER = os.path.join(settings.PROJECT_ROOT, 'fabfile_install')
|
||||
|
||||
|
||||
class Property(object):
|
||||
def __init__(self, name, label, value):
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.value = value
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.value)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.value)
|
||||
|
||||
|
||||
|
||||
class Installation(Singleton):
|
||||
_properties = SortedDict()
|
||||
@@ -64,10 +65,10 @@ class Installation(Singleton):
|
||||
self._properties = SortedDict()
|
||||
if LSB:
|
||||
self.add_property(Property('is_lsb', _(u'LSB OS'), True))
|
||||
self.add_property(Property('distributor_id', _(u'Distributor ID'), lsb_release('-i','-s')))
|
||||
self.add_property(Property('description', _(u'Description'), lsb_release('-d','-s')))
|
||||
self.add_property(Property('release', _(u'Release'), lsb_release('-r','-s')))
|
||||
self.add_property(Property('codename', _(u'Codename'), lsb_release('-c','-s')))
|
||||
self.add_property(Property('distributor_id', _(u'Distributor ID'), lsb_release('-i', '-s')))
|
||||
self.add_property(Property('description', _(u'Description'), lsb_release('-d', '-s')))
|
||||
self.add_property(Property('release', _(u'Release'), lsb_release('-r', '-s')))
|
||||
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_lsb', _(u'LSB OS'), False))
|
||||
@@ -81,7 +82,7 @@ class Installation(Singleton):
|
||||
self.add_property(Property('cpus', _(u'Number of CPUs'), psutil.NUM_CPUS))
|
||||
self.add_property(Property('total_phymem', _(u'Total physical memory'), pretty_size(psutil.TOTAL_PHYMEM)))
|
||||
self.add_property(Property('disk_partitions', _(u'Disk partitions'), '; '.join(['%s %s %s %s' % (partition.device, partition.mountpoint, partition.fstype, partition.opts) for partition in psutil.disk_partitions()])))
|
||||
|
||||
|
||||
try:
|
||||
self.add_property(Property('tesseract', _(u'tesseract version'), pbs.tesseract('-v').stderr))
|
||||
except pbs.CommandNotFound:
|
||||
@@ -94,13 +95,13 @@ 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()
|
||||
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])))
|
||||
@@ -111,13 +112,13 @@ class Installation(Singleton):
|
||||
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:
|
||||
return self._properties[name]
|
||||
except KeyError:
|
||||
raise AttributeError, name
|
||||
raise AttributeError
|
||||
|
||||
def submit(self):
|
||||
try:
|
||||
@@ -164,7 +165,7 @@ class Installation(Singleton):
|
||||
'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):
|
||||
pass
|
||||
@@ -174,6 +175,5 @@ class Installation(Singleton):
|
||||
finally:
|
||||
lock.release()
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = verbose_name_plural = _(u'installation details')
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import absolute_import
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from permissions.models import Permission
|
||||
|
||||
@@ -15,11 +14,11 @@ def installation_details(request):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_INSTALLATION_DETAILS])
|
||||
|
||||
paragraphs = []
|
||||
|
||||
|
||||
for name, instance in Installation().get_properties().items():
|
||||
paragraphs.append('%s: %s' % (unicode(instance.label), instance.value))
|
||||
|
||||
|
||||
return render_to_response('generic_template.html', {
|
||||
'paragraphs': paragraphs,
|
||||
'title': _(u'Installation environment details')
|
||||
}, context_instance=RequestContext(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
Reference in New Issue
Block a user