Esempio n. 1
0
    def gen_html(self):
        if self.project_id:
            nodes = HwFarmNodeModel.objects.filter(projects=self.project_id, hidden=False)
        else:
            nodes = HwFarmNodeModel.objects.filter(hidden=False)

        if len(nodes) == 0:
            return None

        now = datetime.datetime.now()
        now_utc = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)

        range_begin = (now - datetime.timedelta(days=7)).replace(hour=0, minute=0, second=0, microsecond=0)
        range_end = (now + datetime.timedelta(days=3)).replace(hour=0, minute=0, second=0, microsecond=0)

        d = ptDoc(header=" ", footer=" ")
        s = d.add_section(ptSection())
        t = s.add_timeline(
            ptTimeline(
                title=None,
                begin=range_begin,
                end=range_end,
                groups_title='Hosts',
                js_opts={
                    'groupsTitle': "'Host'",
                    'groupsWidth': "'100px'",
                    'groupsComments': "'host_status'",
                    'axisOnTop': 'true',
                    'showNavigation': 'true',}))

        since = range_begin - datetime.timedelta(days=60)
        default_end = now + datetime.timedelta(days=1)

        groups = OrderedDict()
        for n in nodes:
            groups[n.id] = n.name
            t.add_task(ptTask("1970-01-01 00:00:00", "1970-01-01 00:00:00", group=n.name))

            locks = HwFarmNodeLockModel.objects.filter(Q(begin__gte=since) | Q(end=None), hw_nodes=n.pk, deleted=False)
            for l in locks:
                hint = l.title
                if l.owner:
                    hint += " (%s)" % l.owner
                hint += " | " + str(l.begin)
                if l.end:
                    hint += " - " + str(l.end)

                end = default_end
                if l.end:
                   end = l.end
                elif l.planned_dur_hrs:
                   end = l.begin + datetime.timedelta(hours=l.planned_dur_hrs)
                   if end < now_utc:
                       end = default_end

                t.add_task(ptTask(l.begin, end, group=n.name, hint=hint, title=l.title,
                                  cssClass='pt_timeline_task_manual' if l.manual else 'pt_timeline_task_auto'))

        return d.gen_html()
    def __init__(self, output_dir, title=''):
        self.pages = OrderedDict()
        self._url2id = {}
        self.output_dir = output_dir
        self.title = title
        self.doc = ptDoc(title=title)

        self.sdir = os.path.join(self.output_dir, 'screenshots')
        if not os.path.exists(self.sdir):
            os.makedirs(self.sdir)