Ejemplo n.º 1
0
def jsonDiff(request, file1, file2):
    if not (file1 and file2 and isPathOrTag(file1) and isPathOrTag(file2)):
        summary = { "error": "Not able to generate diff without two valid parameters." }
    else:
        mh = ManifestHandler()
        summaryObj = mh.diff(file1, file2, { 'remote': True })
        summary = summaryObj.toJSON()

    return HttpResponse(summary, content_type="application/json")
Ejemplo n.º 2
0
def tableDiff(request, file1, file2):
    if not file1 or not file2:
        summary = { "error": "Not able to generate diff without two parameters" }
        template = loader.get_template('manifest/error-inner.html')
    elif not (isPathOrTag(file1) and isPathOrTag(file2)):
        summary = { "error": "Malformed parameter. Please cross check that the given input is a path or a string containing A-z, 0-9, _, -." }
        template = loader.get_template('manifest/error-inner.html')
    else:
        mh = ManifestHandler()
        summary = mh.diffAdvanced(file1, file2, { 'remote': True, 'full': False, 'Gerrit': True })
        template = loader.get_template('manifest/diff-as-table.html')

    context = RequestContext(request, { 'file1': file1, 'file2': file2, 'summary': summary, 'format': 'table' })
    return HttpResponse(template.render(context))
Ejemplo n.º 3
0
def diff(request, file1, file2):
    param = {'file1': file1,
             'file2': file2 }

    if not file1 or not file2:
        summary = { "error": "Not able to generate diff without two parameters" }
        template = loader.get_template('manifest/error.html')
    elif not (isPathOrTag(file1) and isPathOrTag(file2)):
        summary = { "error": "Malformed parameter. Please cross check that the given input is a path or a string containing A-z, 0-9, _, -." }
        template = loader.get_template('manifest/error.html')
    else:
        mh = ManifestHandler()
        summary = mh.diff(file1, file2, { 'remote': False, 'full': False })
        param['summary'] = summary
        if summary.error:
            template = loader.get_template('manifest/error.html')
        else:
            template = loader.get_template('manifest/diff.html')

    context = RequestContext(request, param)
    return HttpResponse(template.render(context))
Ejemplo n.º 4
0
def excelDiff(request, file1, file2):
    template = loader.get_template('manifest/error.html')
    if not file1 or not file2:
        err = { "error": "Not able to generate diff without two parameters" }
        context = RequestContext(request, param)
        return HttpResponse(template.render(err))
    elif not (isPathOrTag(file1) and isPathOrTag(file2)):
        err = { "error": "Malformed parameter. Please cross check that the " +\
                         "given input is a path or a string containing A-z, 0-9, _, -." }
        context = RequestContext(request, param)
        return HttpResponse(template.render(err))

    mh = ManifestHandler()
    summary = mh.diffAdvanced(file1, file2, { 
                    'remote': True, 
                    'Gerrit': True, 
                    'UTP': True,
                    'Orca': True,
                 })

    response = HttpResponse(content_type='application/ms-excel')
    name = '--'.join([os.path.basename(file1), os.path.basename(file2) ])
    response['Content-Disposition'] = 'attachment; filename={0}.xls'.format(name)
    wb = xlwt.Workbook(encoding='utf-8')
    wsChanged = wb.add_sheet("Changes with UTP")
    wsChanged2= wb.add_sheet("Changes without UTP")

    styleTableHeader = xlwt.XFStyle()
    styleTableHeader.font.bold = True

    styleTableCell = xlwt.XFStyle()
    styleTableCell.alignment.wrap = 1
    
    #
    # Handling "Changed"
    # -------------------------------------------------------------
    if summary.changes:
        row_num1 = 0
        row_num2 = 0
        columns = [
            ('UTP', 'UTP', 3600, None), #"https://utpreloaded.rds.intel.com/CqUtpSms/?Id={0}"),
            ('title', 'UTP Headline', 20000, None),
            ('p_lev1_name', 'Project', 3000, None),
            ('cq_state', 'UTP Status', 3000, None),
            #('subject', 'Commit Message', 20000, None),
            ('author', 'Committed by', 4000, None),
            ('hash', 'Commit Hash', 9000, None), #"https://opticm6.rds.intel.com/r/#/q/{0},n,z"),
            ('date', 'Commit Date', 3500, None),
            ('repo', 'Commit Repo', 6000, None),
            ('branch', 'Commit Branch', 6000, None),
            ('integration_tag', 'Integration Tag', 6000, None),
            ('integration_date', 'Integration Date', 3500, None),
        ]

        for col_num in xrange(len(columns)):
            wsChanged.write(row_num1, col_num, columns[col_num][1], styleTableHeader)
            wsChanged2.write(row_num2, col_num, columns[col_num][1], styleTableHeader)
            # set column width
            wsChanged.col(col_num).width = columns[col_num][2]
            wsChanged2.col(col_num).width = columns[col_num][2]

        changeDict = summary.changes
        for (repo, changes) in changeDict.iteritems():
            for c in changes:
                if 'UTP' in c and len(c['UTP']) > 0:
                    utp_list = c['UTP']
                    sheet = wsChanged
                    row_num = row_num1
                    row_num1 += len(utp_list)
                else: 
                    utp_list = ['']
                    sheet = wsChanged2
                    row_num = row_num2
                    row_num2 += len(utp_list)

                for utp in utp_list:
                  row_num += 1
                  for col_num in xrange(len(columns)):
                    col_name = columns[col_num][0]
                    if col_name == 'UTP':
                      text = utp
                    elif col_name in c:
                      text = c[ columns[col_num][0] ]
                      if col_name == 'date':
                          text = datetime.datetime.fromtimestamp(int(text)).strftime(settings.STRFTIME_FORMAT)
                      elif col_name == 'integration_date':
                          text = text.strftime(settings.STRFTIME_FORMAT)

                    elif col_name == 'repo':
                      text = repo
                    elif col_name == 'branch' and 'approvals' in c and 'branch' in c['approvals']:
                      text = c['approvals']['branch']
                    else:
                      text = '-'
                    sheet.write(row_num, col_num, text, styleTableCell)

    # 
    # Handling "Added"
    # -------------------------------------------------------------
    if summary.added:
      wsAdded   = wb.add_sheet("Added Repos")
      row_num = 0
      col_num = 0
      columns = [
          (u"Added Repo Name", 10000),
      ]
      for col_num in xrange(len(columns)):
          wsAdded.write(row_num, col_num, columns[col_num][0], styleTableHeader)
          # set column width
          wsAdded.col(col_num).width = columns[col_num][1]

      for name in summary.added: 
          row_num += 1
          wsAdded.write(row_num, 0, name, styleTableCell)
            
    # 
    # Handling "Removed"
    # -------------------------------------------------------------
    if summary.removed:
      wsRemoved = wb.add_sheet("Removed Repos")
      row_num = 0
      col_num = 0
      columns = [
          (u"Removed Repo Name", 10000),
      ]
      for col_num in xrange(len(columns)):
          wsRemoved.write(row_num, col_num, columns[col_num][0], styleTableHeader)
          # set column width
          wsRemoved.col(col_num).width = columns[col_num][1]

      for name in summary.removed: 
          row_num += 1
          wsRemoved.write(row_num, 0, name, styleTableCell)
            

    wb.save(response)
    return response