# Path: pytorque/models.py
# class PBSServer(models.Model):
#     time = models.DateTimeField(
#         default=datetime.now)#auto_now_add=True sets datetime with creating object, not with every modifying action
# 
#     name = models.CharField(max_length=100)
#     state = models.CharField(max_length=20)
#     total_jobs = models.IntegerField()
#     running_jobs = models.IntegerField()
#     queued_jobs = models.IntegerField()
#     pbs_version = models.CharField(max_length=10)
# 
# class PBSQueue(models.Model):
#     server = models.ForeignKey(PBSServer)#, blank=True, null=True, on_delete=models.SET_NULL
#     time = models.DateTimeField(default=datetime.now)
# 
#     name = models.CharField(default='', max_length=100, blank=True, null=True)
#     type = models.CharField(default='', max_length=20, blank=True, null=True)
#     total_jobs = models.IntegerField(default=0)
#     running_jobs = models.IntegerField(default=0)
#     queued_jobs = models.IntegerField(default=0)
#     resource_walltime = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_nodes = models.IntegerField(default=0)
# 
# class PBSJob(models.Model):
#     user = models.ForeignKey(User)
#     queue = models.ForeignKey(PBSQueue)
#     time = models.DateTimeField(default=datetime.now)
# 
#     jobId = models.CharField(default='', max_length=50, blank=True, null=True)
#     name = models.CharField(default='', max_length=100, blank=True, null=True)
#     owner = models.CharField(default='', max_length=100, blank=True, null=True)
#     state = models.CharField(default='', max_length=10, blank=True, null=True)
#     queue_raw = models.CharField(default='', max_length=100, blank=True, null=True)
# 
#     start_time = models.DateTimeField(default=datetime.now, blank=True, null=True)
#     resource_cput = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_mem = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_vmem = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_walltime = models.CharField(default='', max_length=20, blank=True, null=True)


from datetime import  datetime
from PBSQuery import PBSQuery, PBSError
from django.contrib.auth.models import User
from pytorque.models import PBSServer, PBSQueue, PBSJob
import time
import pbs
                    customServer.total_jobs = TorqueService._listToInt(pbsServer[pbs.ATTR_total])
                except KeyError:
                    pass
                try:
                    customServer.running_jobs = int(TorqueService._strToDict(pbsServer[pbs.ATTR_count][0])['Running'])
                except KeyError:
                    pass
                try:
                    customServer.queued_jobs = int(TorqueService._strToDict(pbsServer[pbs.ATTR_count][0])['Queued'])
                except KeyError:
                    pass
                try:
                    customServer.pbs_version = TorqueService._listToStr(pbsServer[pbs.ATTR_pbsversion], '|')
                except KeyError:
                    pass

                resultServers.append(customServer)
        except PBSError as pbsErr:
            print(pbsErr)

        return resultServers

    @staticmethod
    def getModelQueues(pbsServer):
        resultQueues = []
        pQuery = PBSQuery()

        try:
            queues = pQuery.getqueues()
            for queueName, pbsQueue in queues.items():

# Path: pytorque/models.py
# class PBSServer(models.Model):
#     time = models.DateTimeField(
#         default=datetime.now)#auto_now_add=True sets datetime with creating object, not with every modifying action
# 
#     name = models.CharField(max_length=100)
#     state = models.CharField(max_length=20)
#     total_jobs = models.IntegerField()
#     running_jobs = models.IntegerField()
#     queued_jobs = models.IntegerField()
#     pbs_version = models.CharField(max_length=10)
# 
# class PBSQueue(models.Model):
#     server = models.ForeignKey(PBSServer)#, blank=True, null=True, on_delete=models.SET_NULL
#     time = models.DateTimeField(default=datetime.now)
# 
#     name = models.CharField(default='', max_length=100, blank=True, null=True)
#     type = models.CharField(default='', max_length=20, blank=True, null=True)
#     total_jobs = models.IntegerField(default=0)
#     running_jobs = models.IntegerField(default=0)
#     queued_jobs = models.IntegerField(default=0)
#     resource_walltime = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_nodes = models.IntegerField(default=0)
# 
# class PBSJob(models.Model):
#     user = models.ForeignKey(User)
#     queue = models.ForeignKey(PBSQueue)
#     time = models.DateTimeField(default=datetime.now)
# 
#     jobId = models.CharField(default='', max_length=50, blank=True, null=True)
#     name = models.CharField(default='', max_length=100, blank=True, null=True)
#     owner = models.CharField(default='', max_length=100, blank=True, null=True)
#     state = models.CharField(default='', max_length=10, blank=True, null=True)
#     queue_raw = models.CharField(default='', max_length=100, blank=True, null=True)
# 
#     start_time = models.DateTimeField(default=datetime.now, blank=True, null=True)
#     resource_cput = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_mem = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_vmem = models.CharField(default='', max_length=20, blank=True, null=True)
#     resource_walltime = models.CharField(default='', max_length=20, blank=True, null=True)


# Path: pytorque/libs/torque_service.py
from datetime import  datetime
from PBSQuery import PBSQuery, PBSError
from django.contrib.auth.models import User
from pytorque.models import PBSServer, PBSQueue, PBSJob
import time
import pbs

                    customServer.total_jobs = TorqueService._listToInt(pbsServer[pbs.ATTR_total])
                except KeyError:
                    pass
                try:
                    customServer.running_jobs = int(TorqueService._strToDict(pbsServer[pbs.ATTR_count][0])['Running'])
                except KeyError:
                    pass
                try:
                    customServer.queued_jobs = int(TorqueService._strToDict(pbsServer[pbs.ATTR_count][0])['Queued'])
                except KeyError:
                    pass
                try:
                    customServer.pbs_version = TorqueService._listToStr(pbsServer[pbs.ATTR_pbsversion], '|')
                except KeyError:
                    pass

                resultServers.append(customServer)
        except PBSError as pbsErr:
            print(pbsErr)

        return resultServers

    @staticmethod
    def getModelQueues(pbsServer):
        resultQueues = []
        pQuery = PBSQuery()

        try:
            queues = pQuery.getqueues()
            for queueName, pbsQueue in queues.items():

                customQueue = PBSQueue(server=pbsServer, name=queueName)