# Path: apps/taskomatic/models.py
# class TaskPeriod(models.Model):
#     title = models.CharField(max_length=64)
#     label = models.SlugField(max_length=64, unique=True,
#                              help_text="Label must be same for command 'schedule --schedule-label [label]'")
#     common = models.CharField(_("Command"), max_length=128,
#                               help_text="All allowed <a href=\"https://github.com/SatelliteQE/GreenTea/wiki/Commands\">commands</a>. Example: \'beaker schedule --schedule-label daily\'")
#     date_last = models.DateTimeField(
#         _('Date of last run'),
#         null=True,
#         blank=True)
#     is_enable = models.BooleanField(default=False)
#     cron = models.CharField(max_length=64, default="*  *  *  *  *")
#     position = models.SmallIntegerField(default=0)
# 
#     class Meta:
#         ordering = ["position", "title"]
# 
#     def get_previous_run(self):
#         tasks = Task.objects.filter(period=self).order_by("-date_run")
#         if len(tasks) > 0:
#             return tasks[0].date_run
#         return None
# 
#     def __unicode__(self):
#         return self.title
# 
#     def createTask(self):
#         res = self.common.split(' ', 1)
#         command = res.pop(0)
#         params = "" if len(res) == 0 else res.pop()
#         task = Task.objects.create(title=self.title,
#                                    common=command,
#                                    common_params=params,
#                                    status=Task.STATUS_ENUM_WAIT,
#                                    period=self)
#         return task
# 
#     def recount_all(self):
#         tps = TaskPeriodSchedule.objects.filter(
#             period=self).order_by("date_create")
#         for key, it in enumerate(tps):
#             it.counter = key
#             it.save()
# 
#     def clean_empty(self):
#         tps = TaskPeriodSchedule.objects.filter(
#             period=self).order_by("date_create")
#         for it in tps:
#             count = it.job_set.all().count()
#             if count == 0:
#                 it.delete()
# 
# class TaskPeriodSchedule(models.Model):
#     title = models.CharField(max_length=64)
#     period = models.ForeignKey("TaskPeriod", blank=True, null=True)
#     date_create = models.DateTimeField(
#         _('Date of create'),
#         default=timezone.now)
#     counter = models.BigIntegerField(default=0)
# 
#     class Meta:
#         ordering = ["period_id", "counter"]
# 
#     def __unicode__(self):
#         return "[%d] %s" % (self.counter, self.title)
# 
#     def recount(self):
#         self.counter = TaskPeriodSchedule.object.filter(
#             period=self.period).count()
#         self.save()
# 
#     def delete(self, *args, **kwargs):
#         super(TaskPeriodSchedule, self).delete(*args, **kwargs)
#         self.period.recount_all()
# 
# Path: apps/core/utils/date_helpers.py
# def toUTC(dt):
#     ''' accept string or datetime and return datetime in UTC '''
#     dt = date_parse(dt)
#     if dt:
#         offset = dt.utcoffset()
#         if offset:
#             dt = dt - offset
#             return dt.replace(tzinfo=dateutil.tz.tzutc())
#     return None


import json
import logging
import os
import re
import git
from django.utils import timezone
from datetime import datetime, timedelta
from urlparse import urlparse
from xml.dom.minidom import parseString
from dateutil.parser import parse
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import Q
from django.template import Context, Template
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from elasticsearch import Elasticsearch
from taggit.managers import TaggableManager
from apps.core.signals import recipe_changed, recipe_finished
from apps.taskomatic.models import TaskPeriod, TaskPeriodSchedule
from validators import validator_dir_exists
from apps.core.utils.date_helpers import toUTC
WARN = 3
FAIL = 4
PASS = 5
NEW = 6
CANCEL = 7
SCHEDULED = 8
PANIC = 9
FAILINSTALL = 10
SKIP = 11
RESULT_CHOICES = (
    (UNKNOW, "unknow"),
    (ABOART, "aborted"),
    (CANCEL, "cancelled"),
    (WAIT, "waiting"),
    (SCHEDULED, "scheduled"),
    (NEW, "new"),
    (WARN, "warn"),
    (WARN, "warning"),
    (FAIL, "fail"),
    (PASS, "pass"),
    (PANIC, "panic"),
    (FAILINSTALL, "failinstall"),
    (SKIP, "skip"),
)

NONE = 0
WAIVED = 11
USERSTATUS_CHOICES = (
    (NONE, u"none"),
    (WAIVED, u"waived"),

# Path: apps/taskomatic/models.py
# class TaskPeriod(models.Model):
#     title = models.CharField(max_length=64)
#     label = models.SlugField(max_length=64, unique=True,
#                              help_text="Label must be same for command 'schedule --schedule-label [label]'")
#     common = models.CharField(_("Command"), max_length=128,
#                               help_text="All allowed <a href=\"https://github.com/SatelliteQE/GreenTea/wiki/Commands\">commands</a>. Example: \'beaker schedule --schedule-label daily\'")
#     date_last = models.DateTimeField(
#         _('Date of last run'),
#         null=True,
#         blank=True)
#     is_enable = models.BooleanField(default=False)
#     cron = models.CharField(max_length=64, default="*  *  *  *  *")
#     position = models.SmallIntegerField(default=0)
# 
#     class Meta:
#         ordering = ["position", "title"]
# 
#     def get_previous_run(self):
#         tasks = Task.objects.filter(period=self).order_by("-date_run")
#         if len(tasks) > 0:
#             return tasks[0].date_run
#         return None
# 
#     def __unicode__(self):
#         return self.title
# 
#     def createTask(self):
#         res = self.common.split(' ', 1)
#         command = res.pop(0)
#         params = "" if len(res) == 0 else res.pop()
#         task = Task.objects.create(title=self.title,
#                                    common=command,
#                                    common_params=params,
#                                    status=Task.STATUS_ENUM_WAIT,
#                                    period=self)
#         return task
# 
#     def recount_all(self):
#         tps = TaskPeriodSchedule.objects.filter(
#             period=self).order_by("date_create")
#         for key, it in enumerate(tps):
#             it.counter = key
#             it.save()
# 
#     def clean_empty(self):
#         tps = TaskPeriodSchedule.objects.filter(
#             period=self).order_by("date_create")
#         for it in tps:
#             count = it.job_set.all().count()
#             if count == 0:
#                 it.delete()
# 
# class TaskPeriodSchedule(models.Model):
#     title = models.CharField(max_length=64)
#     period = models.ForeignKey("TaskPeriod", blank=True, null=True)
#     date_create = models.DateTimeField(
#         _('Date of create'),
#         default=timezone.now)
#     counter = models.BigIntegerField(default=0)
# 
#     class Meta:
#         ordering = ["period_id", "counter"]
# 
#     def __unicode__(self):
#         return "[%d] %s" % (self.counter, self.title)
# 
#     def recount(self):
#         self.counter = TaskPeriodSchedule.object.filter(
#             period=self.period).count()
#         self.save()
# 
#     def delete(self, *args, **kwargs):
#         super(TaskPeriodSchedule, self).delete(*args, **kwargs)
#         self.period.recount_all()
# 
# Path: apps/core/utils/date_helpers.py
# def toUTC(dt):
#     ''' accept string or datetime and return datetime in UTC '''
#     dt = date_parse(dt)
#     if dt:
#         offset = dt.utcoffset()
#         if offset:
#             dt = dt - offset
#             return dt.replace(tzinfo=dateutil.tz.tzutc())
#     return None


# Path: apps/core/models.py
import json
import logging
import os
import re
import git
from django.utils import timezone
from datetime import datetime, timedelta
from urlparse import urlparse
from xml.dom.minidom import parseString
from dateutil.parser import parse
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import Q
from django.template import Context, Template
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from elasticsearch import Elasticsearch
from taggit.managers import TaggableManager
from apps.core.signals import recipe_changed, recipe_finished
from apps.taskomatic.models import TaskPeriod, TaskPeriodSchedule
from validators import validator_dir_exists
from apps.core.utils.date_helpers import toUTC

WARN = 3
FAIL = 4
PASS = 5
NEW = 6
CANCEL = 7
SCHEDULED = 8
PANIC = 9
FAILINSTALL = 10
SKIP = 11
RESULT_CHOICES = (
    (UNKNOW, "unknow"),
    (ABOART, "aborted"),
    (CANCEL, "cancelled"),
    (WAIT, "waiting"),
    (SCHEDULED, "scheduled"),
    (NEW, "new"),
    (WARN, "warn"),
    (WARN, "warning"),
    (FAIL, "fail"),
    (PASS, "pass"),
    (PANIC, "panic"),
    (FAILINSTALL, "failinstall"),
    (SKIP, "skip"),
)

NONE = 0
WAIVED = 11
USERSTATUS_CHOICES = (
    (NONE, u"none"),
    (WAIVED, u"waived"),

)