GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — processing-docs/java_generate/utils.py at master · processing/processing-docs Expand file tree/ Copy pathutils.pyMore file actions 90 lines (68 loc) · 2.3 KB / Copy pathutils.pyFile metadata and controls90 lines (68 loc) · 2.3 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 #!/usr/bin/env python # encoding: utf-8 import sys import os import re def main(): #directory = 'api_examples' directory = '../content/api_en' for root, dirs, files in os.walk(directory): for name in files: # convertTags(os.path.join(root,name), 'c', 'kbd') # moveFile(root,name) addCDATA( os.path.join(root, name) ) #addCDATADescription( os.path.join( root, name ) ) def moveFile(root, name): data = open(os.path.join(root,name),'r').read() include = re.compile(r'<subcategory>((Primitive)|(Composite)|(Relational Operators)|(Iteration)|(Conditionals)|(Logical Operators))').match if(include(data)): print "Moving " + os.path.join(root,name) + "to root" + "include/" + name os.rename(os.path.join(root,name), root + "include/" + name) def addCDATADescription(f): if(f[-3:] == 'xml'): xml = open(f, 'r') txt = xml.read() pattern = re.compile(r'(<description>(?!<\!\[CDATA))([\s\S]+?)(</description>)', re.MULTILINE) txt = re.sub( pattern, r'\1<![CDATA[\2]]>\3', txt) xml.close() xml = open(f, 'w') xml.write(txt) xml.close() def addCDATA(f): if(f[-3:] == 'xml'): xml = open(f, 'r') txt = xml.read() # pattern = re.compile(r'(<description>(?!<\!\[CDATA))([\s\S]+?)(</description>)', re.MULTILINE) # pattern = re.compile(r'(<syntax>(?!<\!\[CDATA))([\s\S]+?)(</syntax>)', re.MULTILINE) pattern = re.compile(r'(<code>(?!<\!\[CDATA))([\s\S]+?)(</code>)', re.MULTILINE) txt = re.sub( pattern, r'\1<![CDATA[\2]]>\3', txt) # pattern = re.compile(r'(<code>(?!<\!\[CDATA))([\s\S]+?)(</code>)', re.MULTILINE) # txt = re.sub( pattern, r'\1<![CDATA[\2]]>\3', txt) xml.close() xml = open(f, 'w') xml.write(txt) xml.close() def convertTags(f, pName, newName): xml = open(f, 'r') txt = xml.read() reString = '(<'+ pName + '>)([\s\S]+?)(</' + pName + r'>)' pattern = re.compile( reString, re.MULTILINE) txt = re.sub(pattern, r'<' + newName + r'>\2</'+ newName +'>', txt) xml.close() xml = open(f, 'w') xml.write(txt) xml.close() def removeCDATA(f): xml = open(f, 'r') txt = xml.read() pattern = re.compile(r'<\!\[CDATA\[', re.MULTILINE) txt = re.sub( pattern, r'', txt) pattern = re.compile(r'\]\]>') txt = re.sub(pattern, r'', txt) xml.close() xml = open(f, 'w') xml.write(txt) xml.close() print "wrote: " + f if __name__ == '__main__': main() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |