'Creates a a new tko job object from the pb job object.
Uses getter methods on the pb objects to extract all the
attributes and finally constructs a tko job object using the
models.job constructor.
:param
job: a pb job where data is being extracted from.
:return: a tko job object.'

def get_tko_job(self, job):

    fields_dict = self.get_trivial_attr(job, self.job_type_dict)
    fields_dict['tests'] = [self.get_tko_test(test) for test in job.tests]
    fields_dict['keyval_dict'] = dict(((keyval.name, keyval.value) for keyval in job.keyval_dict))
    newjob = models.job(fields_dict['dir'], fields_dict['user'], fields_dict['label'], fields_dict['machine'], fields_dict['queued_time'], fields_dict['started_time'], fields_dict['finished_time'], fields_dict['machine_owner'], fields_dict['machine_group'], fields_dict['aborted_by'], fields_dict['aborted_on'], fields_dict['keyval_dict'])
    newjob.tests.extend(fields_dict['tests'])
    return newjob
