]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
Add automatic git version and describe to database module
authorKarel Kočí <cynerd@email.cz>
Fri, 20 Nov 2015 11:34:53 +0000 (12:34 +0100)
committerKarel Kočí <cynerd@email.cz>
Fri, 26 Feb 2016 15:29:04 +0000 (16:29 +0100)
Entries in tables toolsgit and linuxgit are managed automatically using
get().
Also removing relevant configuration options which are not used anymore.

scripts/lcp_django/database/models.py

index 5a6fd4c209b947f915042f9913a44ec05b9ffd6c..f964973f87d6bc792d6afadd17ff542d7b015a64 100644 (file)
@@ -1,13 +1,35 @@
 import os
 import sys
+import subprocess
+from .settings import conf
+from .settings import sf
 from django.db import models
 
+__git_describe__ = 'git describe --always --tags --dirty'
+__git_commit__ = 'git rev-parse --verify HEAD'
+
 class ToolsGit(models.Model):
     id = models.AutoField(primary_key=True)
     git_describe = models.TextField()
     git_commit = models.TextField()
     class Meta:
         db_table = "toolsgit"
+    def get():
+        """Return ToolsGit object of current git. If no entry is in database, new
+        object is created.
+        """
+        ds = subprocess.check_output('cd ' + sf(conf.linux_sources) + ' && '
+            + __git_describe__, shell=True).decode(sys.getdefaultencoding()).strip()
+        cm = subprocess.check_output('cd ' + sf(conf.linux_sources) + ' && '
+            + __git_commit__, shell=True).decode(sys.getdefaultencoding()).strip()
+        lg = LinuxGit.objects.filter(git_describe=ds, git_commit=cm)
+        if not lg:
+            nlg = LinuxGit()
+            nlg.git_commit = cm
+            nlg.git_describe = ds
+            return nlg
+        else:
+            return lg[0]
 
 class LinuxGit(models.Model):
     id = models.AutoField(primary_key=True)
@@ -15,6 +37,23 @@ class LinuxGit(models.Model):
     git_commit = models.TextField()
     class Meta:
         db_table = "linuxgit"
+    def get():
+        """Return LinuxGIt object of current linux tree git. If no entry is in
+        database, new object is created.
+        """
+        ds = subprocess.check_output('cd ' + sf(conf.linux_sources) + ' && '
+            + __git_describe__, shell=True).decode(sys.getdefaultencoding()).strip()
+        cm = subprocess.check_output('cd ' + sf(conf.linux_sources) + ' && '
+            + __git_commit__, shell=True).decode(sys.getdefaultencoding()).strip()
+        lg = LinuxGit.objects.filter(git_describe=ds, git_commit=cm)
+        if not lg:
+            nlg = LinuxGit()
+            nlg.git_commit = cm
+            nlg.git_describe = ds
+            return nlg
+        else:
+            return lg[0]
+
 
 class Configurations(models.Model):
     id = models.AutoField(primary_key=True)