# Path: borme/models.py
# class Config(m.Model):
#     last_modified = m.DateTimeField()
#     version = m.CharField(max_length=50)
# 
# Path: libreborme/utils.py
# def get_git_revision_short_hash():
#     os.chdir(os.path.dirname(libreborme.__file__))
#     try:
#         version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()
#         if isinstance(version, bytes):
#             version = version.decode('unicode_escape')
#     except subprocess.CalledProcessError:
#         logger.warning("Couldn't guess git revision")
#         version = 'Unknown'
#     return version


from django.core.management.base import BaseCommand
from django.utils import timezone
from borme.models import Config
from libreborme.utils import get_git_revision_short_hash
# -*- coding: utf-8 -*-





class Command(BaseCommand):
    help = 'Update current Git version hash'

    def handle(self, *args, **options):
        config = Config.objects.first()
        version = get_git_revision_short_hash()
        print(version)
        if config:
            config.version = version
        else:
            date = timezone.make_aware(timezone.datetime(2000, 1, 1))

# Path: borme/models.py
# class Config(m.Model):
#     last_modified = m.DateTimeField()
#     version = m.CharField(max_length=50)
# 
# Path: libreborme/utils.py
# def get_git_revision_short_hash():
#     os.chdir(os.path.dirname(libreborme.__file__))
#     try:
#         version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()
#         if isinstance(version, bytes):
#             version = version.decode('unicode_escape')
#     except subprocess.CalledProcessError:
#         logger.warning("Couldn't guess git revision")
#         version = 'Unknown'
#     return version


# Path: libreborme/management/commands/updateversion.py
from django.core.management.base import BaseCommand
from django.utils import timezone
from borme.models import Config
from libreborme.utils import get_git_revision_short_hash

# -*- coding: utf-8 -*-





class Command(BaseCommand):
    help = 'Update current Git version hash'

    def handle(self, *args, **options):
        config = Config.objects.first()
        version = get_git_revision_short_hash()
        print(version)
        if config:
            config.version = version
        else:
            date = timezone.make_aware(timezone.datetime(2000, 1, 1))

            config = Config(version=version, last_modified=date)