Пример #1
0
        print(name, F)
        a = source_xml.createElement(r'a')
        a.setAttribute(
            r'href',
            'http://www.sagemath.org/src-old' + F.replace(src_old, ''))
        a.appendChild(source_xml.createTextNode(name))
        td.appendChild(a)
        tr.appendChild(td)

        td = source_xml.createElement(r'td')
        td.appendChild(source_xml.createTextNode('%s MB' % size))
        tr.appendChild(td)

        td = source_xml.createElement(r'td')
        td.appendChild(source_xml.createTextNode(date))
        tr.appendChild(td)

        table_body.appendChild(tr)
        release -= 1


initContent()
writeToSource()

#print(source_xml.toxml())
#xml.dom.ext.PrettyPrint(source_xml, open(src_html, 'w'))

source_xml.writexml(utils.UnicodeFileWriter(open(src_html, "w")))

#utils.delFirstLine(src_html)
Пример #2
0

# read through ack.xml
for c in ack.getElementsByTagName("contributor"):
    print(c.getAttribute("name"), ">>>", end="")
    if c.hasAttribute("location"):
        addGeo(c.getAttribute("location"))
    else:
        print("  <--- UNKNOWN LOCATION !!!")

print()
print("This is now written to file %s:" % geocode_xml_outfn)
print(out.toprettyxml())

#xml.dom.ext.PrettyPrint(out, open(geocode_xml_outfn, "w"))
out.writexml(utils.UnicodeFileWriter(open(geocode_xml_outfn, "w")), newl="\n")

print()
print("calculating statistics and writing to description")
nbContribs, nbPlaces = getStatistics()

print()
print(
    "now writing table entries for search engines and javascript disabled ones"
)
writeToDevmap()

print("file written to %s" % devmap_tmpl)
#xml.dom.ext.PrettyPrint(devmap, open(devmap_xml, "w"))
#devmap.writexml(utils.UnicodeFileWriter(open(devmap_tmpl, "w")), newl="\n")
# utils.delFirstLine(devmap_xml)
Пример #3
0
def index(root, strip):
    """
    main method, walks through all sub directories,
    for each of them, reads the md5 sums from $md5file
    writes and entry for the table for each file
    below the md5 sum if available or calls for calculating it
    in the end, writes the index.html files for each dir
    """
    for dir, dirs, files in os.walk(root):
        print 'Directory %s' % dir
        if dir == '.' or dir.endswith('meta'):
           continue

        listxml = minidom.parse(outfile)
        el = listxml.getElementsByTagName(u'div')
        output = None
        for e in el:
            if e.getAttribute(u'id') == u'output':
                output = e
                break
        title = listxml.getElementsByTagName(u'title')[0]
        keep = len(dir) - len(root) + len(strip)
        shortdir = dir[-keep:]
        title.appendChild(listxml.createTextNode('SageMath Download - %s' % shortdir))
        
        table = listxml.createElement(u'table')

        table.appendChild(getTableHeaderDir(listxml, shortdir))
        #siblings = [ d for d in os.listdir('..') if os.path.isdir(os.path.join('..', d)) ]
        #table.appendChild(getTableHeaderSiblings(listxml, siblings))

        if notesfile in files:
           table.appendChild(getNotesText(listxml, dir))
           files.remove(notesfile)
  
        tr = getTableRowDir(listxml, dirs)
        table.appendChild(tr)

        #no files (only index.html, hence > 1), no need to list them 
        if len(files) > 1:

          table.appendChild(getTableHeader(listxml))
    
          knownMd5 = readMD5(dir) #reads file

          even = True # even/odd for different backgrounds of table rows
          filesKey = lambda fn:os.path.getmtime(os.path.join(dir,fn))
          for fn in sorted(files, reverse=True, key = filesKey):
              even = not even
              if fn in [listfile, md5file, notesfile]:
                  continue
              f = os.path.join(dir, fn)
              tr = getTableRow(listxml, f, fn, shortdir, even)
              table.appendChild(tr)

              if knownMd5 is not None:# and (os.path.getsize(f) / 1024.0 / 1024.0) > MIN_SIZE:
                isNewer = os.path.getmtime(f) > knownMd5['__MTIME__']
                if isNewer:
                  delMd5Entry(dir, fn)
                if knownMd5.has_key(fn) and not isNewer:
                  trMd5 = getMd5Row(listxml, knownMd5[fn], shortdir, fn, f)
                else:
                  trMd5 = getMd5Row(listxml, calcMd5(dir, fn), shortdir, fn, f)
              else:
                trMd5 = getMd5Row(listxml, None, shortdir, fn, f)
              table.appendChild(trMd5)
            

        output.appendChild(table)
        output.appendChild(trackPageView(listxml, shortdir))
        output_file = os.path.join(dir, listfile)
        if os.path.exists(output_file):
          listxml.writexml(utils.UnicodeFileWriter( open(output_file, "w")))
          print 'written to: %s' % output_file
        else:
          print 'WARNING: file %s does not exist and hence directory information is not written to it' % output_file