def get_unit_job_log_html(sip_uuid):
    """
    Generate a string containing a HTML table with the jobs of a given unit
    identifier.
    """
    parser = etree.HTMLParser(remove_blank_text=True)
    rows = (Job.objects.filter(sipuuid=sip_uuid).exclude(
        jobtype="Email fail report").order_by("-createdtime",
                                              "-createdtimedec").values_list(
                                                  "jobtype", "currentstep",
                                                  "createdtime"))
    html = HTML.table(rows, header_row=["Type", "Status", "Started"])
    table = etree.fromstring(html, parser).find("body/table")
    default_bgcolor = COLORS.get("default")

    i = 0
    for tr in table.findall("tr"):
        # Ignore header
        if i == 0:
            i += 1
            continue

        status = rows[i - 1][1]
        bgcolor = COLORS.get(status, default_bgcolor)
        tr.set("bgcolor", bgcolor)
        i += 1

    return etree.tostring(table)
def getUnitJobLogHTML(unitIdentifier):
    parser = etree.HTMLParser(remove_blank_text=True)

    sql = """SELECT Jobs.jobType, Jobs.currentStep, Jobs.createdTime, jobUUID
    FROM Jobs 
    WHERE Jobs.SIPUUID = %s
    AND Jobs.jobType != 'Email fail report'
    AND subJobOf = ''
    ORDER BY Jobs.createdTime DESC, Jobs.createdTimeDec DESC;"""

    rows2Temp = databaseInterface.queryAllSQL(sql, (unitIdentifier, ))

    rows2 = []
    for row in rows2Temp:
        newRow = []
        newRow.append(row[0])
        newRow.append(row[1])
        newRow.append(row[2])

        # TODO: Fix issues with duration
        if False:
            try:
                databaseInterface.printErrors = False
                sql = """SELECT SEC_TO_TIME(jobDurationsView.time_from_job_created_till_end_of_processing_in_seconds) FROM  jobDurationsView WHERE jobUUID = %s;"""
                duration = databaseInterface.queryAllSQL(sql, (row[3], ))
                if duration and duration[0] and duration[0][0]:
                    newRow.append(duration[0][0])
                else:
                    newRow.append("-")
                databaseInterface.printErrors = True
            except:
                databaseInterface.printErrors = True
                duration = 0
                newRow.append(0)

        rows2.append(newRow)

    htmlcode2 = HTML.table(rows2,
                           header_row=["Type", "Status",
                                       "Started"])  # TODO: Re-add duration
    t2 = etree.fromstring(htmlcode2, parser).find("body/table")
    i = 0
    for tr in t2.findall("tr"):
        #header row
        if i == 0:
            i += 1
            #tr.set("bgcolor", "#00FF00")
            continue

        #job row
        status = rows2[i - 1][1]
        if status == "Completed successfully":
            tr.set("bgcolor", "#dff0d8")
        elif status == "Failed":
            tr.set("bgcolor", "#f2dede")
        else:
            tr.set("bgcolor", "yellow")
        i += 1

    return etree.tostring(t2)
def get_unit_job_log_html(sip_uuid):
    """
    Generate a string containing a HTML table with the jobs of a given unit
    identifier.
    """
    parser = etree.HTMLParser(remove_blank_text=True)
    rows = Job.objects.filter(
        sipuuid=sip_uuid,
        subjobof='').exclude(jobtype='Email fail report').order_by(
            '-createdtime',
            '-createdtimedec').values_list('jobtype', 'currentstep',
                                           'createdtime')
    html = HTML.table(rows, header_row=['Type', 'Status', 'Started'])
    table = etree.fromstring(html, parser).find('body/table')
    default_bgcolor = COLORS.get('default')

    i = 0
    for tr in table.findall('tr'):
        # Ignore header
        if i == 0:
            i += 1
            continue

        status = rows[i - 1][1]
        bgcolor = COLORS.get(status, default_bgcolor)
        tr.set('bgcolor', bgcolor)
        i += 1

    return etree.tostring(table)
def getUnitStatisticalDataHTML(unitIdentifier):
    fields = [
        "unitType", "Total time processing", "total file size",
        "number of files", "average file size KB", "average file size MB"
    ]
    sql = """SELECT `{fields}` FROM PDI_by_unit WHERE SIP_OR_TRANSFER_UUID = %s;""".format(
        fields="`, `".join(fields))
    rows = databaseInterface.queryAllSQL(sql, (unitIdentifier, ))
    return HTML.table(rows, header_row=fields)
def get_unit_statistical_data_html(unit_type, unit_uuid):
    fields = [
        "Unit type",
        "Total time processing",
        "Total file size",
        "Number of files",
        "Average file size KB",
        "Average file size MB",
    ]
    values = (unit_type, )
    unit_type = unit_type.lower()
    if unit_type not in ("sip", "transfer"):
        raise ValueError("Unexpected value in unit_type: {}".format(unit_type))
    with connection.cursor() as cursor:
        values += get_processing_time(cursor, unit_type, unit_uuid)
        values += get_file_stats(cursor, unit_type, unit_uuid)
    return HTML.table([values], header_row=fields)
def get_unit_statistical_data_html(unit_type, unit_uuid):
    fields = [
        'Unit type',
        'Total time processing',
        'Total file size',
        'Number of files',
        'Average file size KB',
        'Average file size MB',
    ]
    values = (unit_type, )
    unit_type = unit_type.lower()
    if unit_type not in ('sip', 'transfer'):
        raise ValueError('Unexpected value in unit_type: {}'.format(unit_type))
    with connection.cursor() as cursor:
        values += get_processing_time(cursor, unit_type, unit_uuid)
        values += get_file_stats(cursor, unit_type, unit_uuid)
    return HTML.table([values], header_row=fields)
Exemple #7
0
def getContentFor(unitType, unitName, unitIdentifier):
    root = etree.Element("HTML")
    body = etree.SubElement(root, "body")
    parser = etree.HTMLParser(remove_blank_text=True)

    try:
        fields = [
            "unitType", "Total time processing", "total file size",
            "number of files", "average file size KB", "average file size MB"
        ]
        sql = """SELECT `%s` FROM PDI_by_unit WHERE SIP_OR_TRANSFER_UUID = '%s';""" % (
            "`, `".join(fields), unitIdentifier)
        rows = databaseInterface.queryAllSQL(sql)
        htmlcode1 = HTML.table(rows, header_row=fields)
        t1 = etree.fromstring(htmlcode1, parser).find("body/table")
        body.append(t1)

        etree.SubElement(body, "p")
    except:
        pass

    sql = """SELECT Jobs.jobType, Jobs.currentStep, Jobs.createdTime, jobUUID
    FROM Jobs 
    WHERE Jobs.SIPUUID = '%s' 
    AND Jobs.jobType != 'Email fail report'
    AND subJobOf = ''
    ORDER BY Jobs.createdTime DESC, Jobs.createdTimeDec DESC;""" % (
        unitIdentifier)

    rows2Temp = databaseInterface.queryAllSQL(sql)

    rows2 = []
    for row in rows2Temp:
        newRow = []
        newRow.append(row[0])
        newRow.append(row[1])
        newRow.append(row[2])
        try:
            databaseInterface.printErrors = False
            sql = """SELECT SEC_TO_TIME(jobDurationsView.time_from_job_created_till_end_of_processing_in_seconds) FROM  jobDurationsView WHERE jobUUID = '%s';""" % (
                row[3])
            duration = databaseInterface.queryAllSQL(sql)
            if duration and duration[0] and duration[0][0]:
                newRow.append(duration[0][0])
            else:
                newRow.append("-")
            databaseInterface.printErrors = True
        except:
            databaseInterface.printErrors = True
            duration = 0
            newRow.append(0)

        rows2.append(newRow)
    htmlcode2 = HTML.table(
        rows2, header_row=["Type", "Status", "Started", "Duration"])
    t2 = etree.fromstring(htmlcode2, parser).find("body/table")
    i = 0
    for tr in t2.findall("tr"):
        #header row
        if i == 0:
            i += 1
            #tr.set("bgcolor", "#00FF00")
            continue

        #job row
        status = rows2[i - 1][1]
        if status == "Completed successfully":
            tr.set("bgcolor", "#00FF00")
        elif status == "Failed":
            tr.set("bgcolor", "RED")
        else:
            tr.set("bgcolor", "yellow")
        i += 1

    body.append(t2)

    return etree.tostring(root, pretty_print=True)
def getContentFor(unitType, unitName, unitIdentifier):
    root = etree.Element("HTML")
    body = etree.SubElement(root, "body")
    parser = etree.HTMLParser(remove_blank_text=True)
    
    try:
        fields = ["unitType", "Total time processing", "total file size", "number of files", "average file size KB", "average file size MB"]
        sql = """SELECT `%s` FROM PDI_by_unit WHERE SIP_OR_TRANSFER_UUID = '%s';""" % ("`, `".join(fields), unitIdentifier)
        rows = databaseInterface.queryAllSQL(sql)
        htmlcode1 = HTML.table(rows, header_row=fields)
        t1 = etree.fromstring(htmlcode1, parser).find("body/table")  
        body.append(t1)
        
        etree.SubElement(body, "p")
    except:
        pass

        
    sql = """SELECT Jobs.jobType, Jobs.currentStep, Jobs.createdTime, jobUUID
    FROM Jobs 
    WHERE Jobs.SIPUUID = '%s' 
    AND Jobs.jobType != 'Email fail report'
    AND subJobOf = ''
    ORDER BY Jobs.createdTime DESC, Jobs.createdTimeDec DESC;""" % (unitIdentifier)
    
    rows2Temp = databaseInterface.queryAllSQL(sql)

    rows2=[]
    for row in rows2Temp:
        newRow = []
        newRow.append(row[0])
        newRow.append(row[1])
        newRow.append(row[2])
        try:
            databaseInterface.printErrors = False
            sql = """SELECT SEC_TO_TIME(jobDurationsView.time_from_job_created_till_end_of_processing_in_seconds) FROM  jobDurationsView WHERE jobUUID = '%s';""" % (row[3])
            duration = databaseInterface.queryAllSQL(sql)
            if duration and duration[0] and duration[0][0]:
                newRow.append(duration[0][0])
            else:
                newRow.append("-")
            databaseInterface.printErrors = True
        except:
            databaseInterface.printErrors = True
            duration = 0
            newRow.append(0)
        
        
        rows2.append(newRow)
    htmlcode2 = HTML.table(rows2, header_row=["Type", "Status", "Started", "Duration"])
    t2 = etree.fromstring(htmlcode2, parser).find("body/table")
    i = 0  
    for tr in t2.findall("tr"):
        #header row
        if i == 0:
            i+=1
            #tr.set("bgcolor", "#00FF00")
            continue
        
        #job row
        status = rows2[i-1][1]
        if status == "Completed successfully":
            tr.set("bgcolor", "#00FF00")
        elif status == "Failed":
            tr.set("bgcolor", "RED")
        else:
            tr.set("bgcolor", "yellow")
        i+=1
        
    body.append(t2)
    
    return etree.tostring(root, pretty_print=True)