[pypy-svn] rev 1485 - pypy/trunk/doc/funding/tools
stephan at codespeak.net
stephan at codespeak.net
Tue Sep 30 20:11:10 CEST 2003
Author: stephan
Date: Tue Sep 30 20:11:10 2003
New Revision: 1485
Modified:
pypy/trunk/doc/funding/tools/format.py
pypy/trunk/doc/funding/tools/zipmod.py
Log:
some changes. format doesn't work yet
Modified: pypy/trunk/doc/funding/tools/format.py
==============================================================================
--- pypy/trunk/doc/funding/tools/format.py (original)
+++ pypy/trunk/doc/funding/tools/format.py Tue Sep 30 20:11:10 2003
@@ -15,6 +15,21 @@
self.text = text
self.index = 0
+ def extractTagName(self,txt):
+ txt = txt.strip()
+ if not txt.startswith('<'):
+ return ''
+ if txt.find('/') != -1:
+ return ''
+ i = txt.find(' ')
+ if i != -1:
+ tagname = txt[1:i]
+ else:
+ tagname = txt[1:-1]
+
+ #print >> sys.stderr,tagname
+ return tagname
+
def start(self,txt):pass
def stop(self,txt):pass
def empty(self,txt):pass
@@ -62,8 +77,7 @@
super(format,self).__init__(*argl,**argd)
self.level = 0
self.outbuf = []
- self.stack = []
-
+
def __str__(self):
self.parse()
return '\n'.join(self.outbuf)
@@ -132,7 +146,6 @@
elem = txt[1:i]
else:
elem = txt[1:-1]
- self.stack.append(elem)
txt = txt.strip()
if txt.startswith('<style:style'):
for tab in self.tabnames:
@@ -145,9 +158,7 @@
txt = txt.strip()
if self.inStyle:
self.inStyle = False
- #self.outbuf.append(txt)
- #elem = ''.join(('</',self.stack.pop(),'>'))
- self.outbuf.append('</%s>' % self.stack.pop())
+ self.outbuf.append(txt)
def other(self,txt):
txt = txt.strip()
@@ -166,14 +177,78 @@
if txt:
self.outbuf.append(txt)
+class cut(format):
+ def __init__(self,*argl,**argd):
+ super(cut,self).__init__(*argl,**argd)
+ self.level = 0
+ self.write = True
+ self.stack = []
+
+ def __str__(self):
+ self.parse()
+ return ''.join(self.outbuf)
+
+ def start(self,txt):
+ if self.write:
+ self.outbuf.append(txt)
+ else:
+ self.stack.append(self.extractTagName(txt))
+
+ def other(self,txt):
+ if self.write:
+ self.outbuf.append(txt)
+
+ def stop(self,txt):
+ if self.write:
+ if self.stack and txt.find(self.stack[-1]) != -1:
+ self.stack.pop()
+ else:
+ self.outbuf.append(txt)
+
+ def empty(self,txt):
+ if self.write:
+ self.outbuf.append(txt)
+
+ def any(self,txt):
+ if txt.find('DELETE:BEGIN') != -1:
+ self.initStartCut()
+ elif txt.find('DELETE:END') != -1:
+ self.initStopCut()
+ else:
+ if self.write:
+ self.outbuf.append(txt)
+
+ def initStartCut(self):
+ self.write = False
+ self.level = 0
+ while 1:
+ last = self.outbuf.pop()
+ last = last.strip()
+ if last.startswith('</'):
+ self.level += 1
+ continue
+ elif last.endswith('/>'):
+ continue
+ tag = self.extractTagName(last)
+ print >> sys.stderr,'startCut',last,self.level,tag
+ if tag and not self.level:
+ break
+ elif tag:
+ self.level -= 1
+
+ def initStopCut(self):
+ self.write = True
+
def changeStyle(txt):
- f = format(str(replaceMargin(txt)))
- return str(f)
- #return str(replaceMargin(txt))
+ txt = str(cut(txt))
+ txt = str(replaceMargin(txt))
+ txt = str(format(txt))
+ return txt
if __name__ == '__main__':
import sys
fn = sys.argv[1]
content = open(fn).read()
- f = format(str(replaceMargin(content)))
+ #f = format(str(replaceMargin(content)))
+ f = str(format(content))
print f
Modified: pypy/trunk/doc/funding/tools/zipmod.py
==============================================================================
--- pypy/trunk/doc/funding/tools/zipmod.py (original)
+++ pypy/trunk/doc/funding/tools/zipmod.py Tue Sep 30 20:11:10 2003
@@ -67,7 +67,9 @@
fs.write(filemap[fn])
# rebuild a copy of the original ZIP file from tmp. dir.
- zip = zipfile.ZipFile(docPath, 'w', zipfile.ZIP_DEFLATED)
+ name,end = os.path.splitext(docPath)
+ newpath = name+'_cp'+end
+ zip = zipfile.ZipFile(newpath, 'w', zipfile.ZIP_DEFLATED)
for fn in filenames:
destPath = os.path.join(tmp, fn.replace('/',os.sep))
zip.write(destPath, fn)
@@ -75,7 +77,7 @@
def filterAll(txt):
txt = changeStyle(txt)
- txt = filter(txt)
+ #txt = filter(txt)
return txt
More information about the Pypy-commit
mailing list