File:  [Repository] / lise / lise.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Fri Apr 23 16:25:09 2004 UTC (20 years, 2 months ago) by wischi
Branches: MAIN
CVS tags: HEAD
new version

    1: import xml.parsers.expat
    2: import re
    3: import OFS.Image
    4: from types import *
    5: from OFS.Image import Image
    6: from OFS.Folder import Folder
    7: from OFS.SimpleItem import SimpleItem
    8: from OFS.Image import manage_addFile
    9: from OFS.Image import File
   10: from OFS.DTMLDocument import addDTMLDocument
   11: from Globals import DTMLFile, MessageDialog, package_home
   12: from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
   13: from Products.PageTemplates.ZopePageTemplate import manage_addPageTemplate
   14: import os
   15: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   16: from Products.PageTemplates.PageTemplate import PageTemplate
   17: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
   18: import string
   19: import urllib
   20: import xml.dom.minidom
   21: from urllib import quote
   22: 
   23: 
   24: ###   G L O B A L S   ###
   25: allobjects = []
   26: pagearray = []
   27: objindex = 0
   28: currobj = 0
   29: currchapter = 0
   30: tagstr = ""
   31: counter = 1      # counts pages/pictures
   32: counterid = 1    # counts IDs
   33: 
   34: onpage = 0
   35: onpagename = 0
   36: onpageindex = 0
   37: onpageurl = 0
   38: onchapter = 0
   39: onchaptername = 0
   40: onstart = 0
   41: onstartname = 0
   42: onstartindex = 0
   43: onstarturl = 0
   44: onend = 0
   45: onendname = 0
   46: onendindex = 0
   47: onendurl = 0
   48: gbaseurl = ''
   49: gpictpath = ''
   50: errstr = ''
   51: 
   52: 
   53: 
   54: class lise(Folder):
   55: 	"The class lise"
   56: 	
   57: 	meta_type = 'lise'
   58: 	
   59: 	manage_options=(
   60: 		{'label': 'Contents', 'action': 'manage_main'},
   61: 		{'label': 'Welcome', 'action': 'index_html'},
   62: 		{'label': 'Schedule', 'action': 'schedule_html'},
   63: 		{'label': 'Edit Schedule', 'action': 'manage_editScheduleForm'},
   64: 	)
   65: 
   66: 	def __init__(self, id, title):
   67: 		"Initialize a new instance of lise class"
   68: 		self.id = id
   69: 		self.title = title
   70: 		self.freetext = 'hoho'
   71: 		self.schedule = 'schedule'
   72: 		self.xml = 'xml'
   73: 		self.xmlpath = 'xmlpath'
   74: 		self.xmlfilename = 'xmlfilename'
   75: 		self.link = ''
   76: 			
   77: 	def manage_editSchedule(self, title, schedule, RESPONSE=None):
   78: 		"Change attributes of a lise instance"
   79: 		self.title = title
   80: 		self.schedule = schedule
   81: 		if RESPONSE is not None:
   82: 			return MessageDialog(
   83: 				title='Edited',
   84: 				message='<strong>%s</strong> has been edited.'%self.id,
   85: 				action='./schedule_html'
   86: 			)
   87: 
   88: 	schedule_html = DTMLFile('dtml/schedule_html', globals())
   89: 	manage_editScheduleForm = DTMLFile('dtml/manage_editScheduleForm', globals())
   90: 
   91: 		
   92: # ZOPE interface
   93: manage_addliseForm = DTMLFile('dtml/manage_addliseForm', globals())
   94: 
   95: 
   96: class MAIN_layoutTemplate(ZopePageTemplate):
   97:     """Create a layout Template"""
   98: 
   99:     meta_type="MAIN_layoutTemplate"
  100: 
  101:     def __init__(self, id, text=None, content_type=None, MainType=None):
  102:         self.id = str(id)
  103: 
  104:         self.ZBindings_edit(self._default_bindings)
  105:         if text is None:
  106:             self._default_content_fn = os.path.join(package_home(globals()),
  107:                                                'dtml/main.zpt')
  108:             text = open(self._default_content_fn).read()
  109:         self.pt_edit(text, content_type)
  110: 
  111:     
  112:         """change form"""
  113:         
  114:         
  115: def manage_addNAIN_layoutTemplateForm(self):
  116:     """Form for adding"""
  117:     pt = PageTemplateFile('Products/lise/dtml/main.zpt').__of__(self)
  118:     return pt()
  119: 
  120: 
  121: def manage_addlise(self, id, title, pictpath, baseurl, file, RESPONSE = None):
  122: 	"add a lise instance in a folder."
  123: 	global allobjects
  124: 	global objindex
  125: 	global currchapter
  126: 	global currobj
  127: 	global tagstr
  128: 	global onpage
  129: 	global onpagename
  130: 	global onpageindex
  131: 	global onpageurl
  132: 	global onchapter
  133: 	global onchaptername
  134: 	global onstart
  135: 	global onstartname
  136: 	global onstartindex
  137: 	global onstarturl
  138: 	global onend
  139: 	global onendname
  140: 	global onendindex
  141: 	global onendurl
  142: 	global pagearray
  143: 	global errstr
  144: 	global counterid
  145: 	global gbaseurl
  146: 	global gpictpath
  147: 	
  148: 	allobjects = []
  149: 	pagearray = []
  150: 	filenames = []
  151: 	fnames = []
  152: 	id = str(id)
  153: 	title = str(title)
  154: 
  155: 	gpictpath = str(pictpath)
  156: 
  157: 	thelen = len(gpictpath)
  158: 	if thelen > 0:
  159: 		fnames = os.listdir(gpictpath)
  160: 		thelen = len(filenames)
  161: 		j = 0
  162: 		for i in fnames:
  163: 			if i[0] <> '.':
  164: 				normalize_whitespace(i)
  165: #				filenames.append('file://' + gpictpath + '/' + i)
  166: 				if gpictpath[-1] == '/':
  167: 					filenames.append('file://' + gpictpath + i)
  168: 				else:
  169: 					filenames.append('file://' + gpictpath + '/' + i)
  170: 	else:
  171: 		filenames.append('no_fuckingPicture')
  172: 
  173: 	newObj = lise(id, title) # create new lise object
  174: 	self._setObject(id, newObj) # put it into zope
  175: 	if RESPONSE is not None:
  176: 		RESPONSE.redirect('manage_main')
  177: 	link = self.absolute_url() + '/' + id # path of new lise object
  178: 	object = getattr(self, id) # get the new lise object
  179: 	RESPONSE.redirect(link) # set path to new lise object
  180: 	
  181: 	errid = 'standard_error_message'
  182: 	error_html = DTMLFile('dtml/standard_error_message',globals())
  183: 	addDTMLDocument(object, errid, '', error_html)
  184: 	errobj = getattr(object, errid) # reference this object
  185: 	
  186: 	lisescript = manage_addExternalMethod(object, 'liseScript','liseScript','lise.liseScript','liseScript')
  187: 	
  188: 	id2 = id + '.xml'
  189: 	manage_addFile(object, id2, file, title, 'text/xml') # create new xml file
  190: 	object2 = getattr(object, id2) # reference this object
  191: 	link2 = self.absolute_url() + '/' + id + '/' + id + '.xml' # path of xml file
  192: 
  193: 	objarr = []
  194: 	retval = ''
  195: 	thelen = 42
  196: 	newObj.xmlpath = str(thelen)
  197: 	
  198: 	p = xml.parsers.expat.ParserCreate()
  199: 	taghandler = TagHandler()
  200: 	p.StartElementHandler = taghandler.expat_start_element
  201: 	p.EndElementHandler = taghandler.expat_endElement
  202: 	p.CharacterDataHandler = taghandler.characters
  203: 	p.Parse(str(object2.data))
  204: 	
  205: 	if IsStr(baseurl):
  206: 		gbaseurl = str(baseurl)
  207: 
  208: 	#### lšschen nicht vergessen ###
  209: #	gbaseurl = 'http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=permanent/shipbuilding/bougu_traite_1746&dw=400&dh=400&pn='
  210: 
  211: 	for i in allobjects:
  212: 		if hasattr(i, 'typestr'):
  213: 			if i.typestr == 'chapter':
  214: 				i.parseobjects()
  215: 
  216: 	counterid = 1
  217: 	for i in allobjects:
  218: 		if hasattr(i, 'typestr'):
  219: 			if i.typestr == 'chapter':
  220: 				i.CreateChapter()
  221: 			if i.typestr == 'page':
  222: 				i.CreatePage(i.chapterindex)
  223: 		
  224: 
  225: 	pacount = 0
  226: 	for i in pagearray:
  227: 		if i.type == 'C':
  228: 			i.picturelink = 'this_is the_no_fucking_picture_error'
  229: 			i.pictindex = 0
  230: 			for j in range(pacount, len(pagearray)):
  231: 				if pagearray[j].type == 'P':
  232: 					if len(pagearray[j].picturelink) > 0:
  233: 						i.picturelink = pagearray[j].picturelink
  234: 						break
  235: 					if IsInt(pagearray[j].pictindex):
  236: 						i.pictindex = pagearray[j].pictindex
  237: 						break
  238: 		pacount = pacount + 1
  239: 	
  240: 	mainid = 'main'
  241: 	main_html = PageTemplateFile('dtml/main.zpt',globals()).__of__(self)
  242: 	manage_addPageTemplate(object, mainid, '', main_html)
  243: #	addDTMLDocument(object, mainid, '', main_html)
  244: 	mainobj = getattr(object, mainid) # reference this object
  245: 	setattr(mainobj, 'pagelist', pagearray)
  246: 	setattr(mainobj, 'filenames', filenames)
  247: 	if IsStr(pagearray[0].picturelink):
  248: 		setattr(mainobj, 'currpict', pagearray[0].picturelink)
  249: 	else:
  250: 		setattr(mainobj, 'currpict', filenames[int(pagearray[0].id)])
  251: 	
  252: #	sdmid = 'sdm'
  253: #	sdm = SessionDataManager(sdmid)
  254: #	object._setObject(sdmid, sdm) # put it into lise folder
  255: 	
  256: 	if(len(errstr) > 0):
  257: 		newObj.freetext = self.absolute_url() + '/' + id + '/standard_error_message'
  258: 		errobj.error_message = errstr + '<br><br><h3>by babes</h3>'
  259: 		RESPONSE.redirect(self.absolute_url() + '/' + id + '/standard_error_message')
  260: 	else:
  261: 		RESPONSE.redirect(self.absolute_url() + '/' + id + '/main?theid=1')
  262: 
  263: 
  264: 
  265: ########################################################################################
  266: class Error_DTML(SimpleItem):
  267: 	"the ERROR message"
  268: 	meta_type = 'error_message'
  269: 	
  270: 	def __init__(self, id):
  271: 		self.id = id
  272: 
  273: 
  274: ########################################################################################
  275: class TagHandler:
  276: 	def __init__(self):
  277: 		self.tags={}
  278: 		self.name=""
  279: 		self.index = ""
  280: 		self.url = ""
  281: 		self.startname = ""
  282: 		self.startindex = 0
  283: 		self.starturl = ""
  284: 		self.endname = ""
  285: 		self.endindex = 0
  286: 		self.endurl = ""
  287: 		self.chapterindex = 0
  288: 		self.currentchapter = 0
  289: 
  290: 
  291: 	def expat_start_element(self, name, attrs):
  292: 		global allobjects
  293: 		global objindex
  294: 		global currchapter
  295: 		global currobj
  296: 		global tagstr
  297: 		global onpage
  298: 		global onpagename
  299: 		global onpageindex
  300: 		global onpageurl
  301: 		global onchapter
  302: 		global onchaptername
  303: 		global onstart
  304: 		global onstartname
  305: 		global onstartindex
  306: 		global onstarturl
  307: 		global onend
  308: 		global onendname
  309: 		global onendindex
  310: 		global onendurl
  311: 		global errstr
  312: 		
  313: 		if name == 'page':
  314: 			onstart = False
  315: 			onpage = True
  316: 			currobj = PageObject()
  317: 			if onchapter:
  318: 				thelen = len(currchapter.chapterobjects)
  319: 				if thelen > 0:
  320: 					currobj.prevref = currchapter.chapterobjects[thelen - 1]
  321: 					currchapter.chapterobjects[thelen - 1].nextref = currobj
  322: 				currchapter.chapterobjects.append(currobj)
  323: 				currobj.chapterindex = currchapter.chapterindex
  324: 			else:
  325: 				thelen = len(allobjects)
  326: 				if thelen > 0:
  327: 					currobj.prevref = allobjects[thelen - 1]
  328: 					allobjects[thelen - 1].nextref = currobj
  329: 				allobjects.append(currobj)
  330: 		
  331: 		if name == 'chapter':
  332: 			onstart = False
  333: 			onend = False
  334: 			currobj = ChapterObject(objindex)
  335: 			objindex += 1
  336: 			if onchapter:
  337: 				currobj.upref = currchapter
  338: 				thelen = len(currchapter.chapterobjects)
  339: 				if thelen > 0:
  340: 					currobj.prevref = currchapter.chapterobjects[thelen - 1]
  341: 					currchapter.chapterobjects[thelen - 1].nextref = currobj
  342: 				currchapter.chapterobjects.append(currobj)
  343: 			else:
  344: 				allobjects.append(currobj)
  345: 				onchapter = True
  346: 			currchapter = currobj
  347: 		
  348: 		if name == 'name':
  349: 			tagstr = ""
  350: 			if onpage:
  351: 				onpagename = True
  352: 			else:
  353: 				if onchapter:
  354: 					if (not onstart) and (not onend):
  355: 						onchaptername = True
  356: 					else:
  357: 						if onstart:
  358: 							onstartname = True
  359: 						if onend:
  360: 							onendname = True
  361: 				else:
  362: 					errstr = errstr + 'ERROR in XML file: \"&lt;name&gt; tag outside &lt;page&gt; or &lt;chapter&gt;\"<br>'
  363: 			
  364: 		if name == 'index':
  365: 			tagstr = ""
  366: 			if onpage:
  367: 				onpageindex = True
  368: 			else:
  369: 				if onchapter:
  370: 					if onstart:
  371: 						if not onend:
  372: 							onstartindex = True
  373: 						else:
  374: 							onendindex = True
  375: 					else:
  376: 						errstr = errstr + 'ERROR in XML file: \"&lt;index&gt; tag inside chapter but outside &lt;start&gt; or &lt;end>\"<br>'
  377: 				else:
  378: 					errstr = errstr + 'ERROR in XML file: \"&lt;index&gt; tag outside &lt;page&gt; or &lt;chapter&gt;\"<br>'
  379: 			
  380: 		if name == 'url':
  381: 			tagstr = ""
  382: 			if onpage:
  383: 				onpageurl = True
  384: 			else:
  385: 				if onchapter:
  386: 					if onstart:
  387: 						if not onend:
  388: 							onstarturl = True
  389: 						else:
  390: 							onendurl = True
  391: 					else:
  392: 						errstr = errstr + 'ERROR in XML file: \"&lt;url&gt; tag inside chapter but outside &lt;start&gt; or &lt;end&gt;\"<br>'
  393: 				else:
  394: 					errstr = errstr + 'ERROR in XML file: \"&lt;url&gt; tag outside &lt;page&gt; or &lt;chapter&gt;\"<br>'
  395: 		
  396: 		if name == 'start':
  397: 			if onchapter:
  398: 				onstart = True
  399: 				currobj = StartEndObject()
  400: 				thelen = len(currchapter.chapterobjects)
  401: 				if thelen > 0:
  402: 					currobj.prevref = currchapter.chapterobjects[thelen - 1]
  403: 					currchapter.chapterobjects[thelen - 1].nextref = currobj
  404: 				currchapter.chapterobjects.append(currobj)
  405: 			else:
  406: 				errstr = errstr + 'ERROR in XML file: \"&lt;start&gt; tag outside &lt;chapter&gt;\"<br>'
  407: 			
  408: 		if name == 'end':
  409: 			if onchapter:
  410: 				if onstart:
  411: 					onend = True
  412: 				else:
  413: 					errstr = errstr + 'ERROR in XML file: \"&lt;end&gt; tag without &lt;start&gt;\"<br>'
  414: 			else:
  415: 				errstr = errstr + 'ERROR in XML file: \"&lt;end&gt; tag outside &lt;chapter&gt;\"<br>'
  416: 	
  417: 	
  418: 	def characters(self, ch):
  419: 		global tagstr
  420: 		tagstr += ch
  421: 
  422: 
  423: 	def expat_endElement(self, name):
  424: 		global allobjects
  425: 		global objindex
  426: 		global currchapter
  427: 		global currobj
  428: 		global tagstr
  429: 		global onpage
  430: 		global onpagename
  431: 		global onpageindex
  432: 		global onpageurl
  433: 		global onchapter
  434: 		global onchaptername
  435: 		global onstart
  436: 		global onstartname
  437: 		global onstartindex
  438: 		global onstarturl
  439: 		global onend
  440: 		global onendname
  441: 		global onendindex
  442: 		global onendurl
  443: 		global errstr
  444: 		
  445: #		errstr = errstr + 'end: ' + name + ':<br>'
  446: 		if name == 'page':
  447: 			onpage = False
  448: 			
  449: 		if name == 'chapter':
  450: 			objindex -= 1
  451: 			if objindex <= 0:
  452: 				onchapter = False
  453: 				currchapter = 0
  454: 			else:
  455: 				currchapter = currchapter.upref
  456: 			
  457: 		if name == 'name':
  458: 			tagstr = normalize_whitespace(tagstr)
  459: 			if onpagename:
  460: 				onpagename = False
  461: 				currobj.name = tagstr
  462: 			if onchaptername:
  463: 				if currobj.typestr == 'chapter':
  464: 					currobj.name = tagstr
  465: 				onchaptername = False
  466: 			if onstartname:
  467: 				if currobj.typestr == 'start':
  468: 					currobj.startname = tagstr
  469: 				onstartname = False
  470: 			if onendname:
  471: 				if currobj.typestr == 'start':
  472: 					currobj.endname = tagstr
  473: 				onendname = False
  474: 			
  475: 		if name == 'index':
  476: 			tagstr = normalize_whitespace(tagstr)
  477: 			if onpageindex:
  478: 				if IsInt(tagstr):
  479: 					currobj.index = int(tagstr) - 1
  480: 				else:
  481: 					errstr = errstr + 'ERRRRROR: cannot extract number from page index.<br>'
  482: 				onpageindex = False
  483: 				
  484: 			if onstartindex:
  485: 				if IsInt(tagstr):
  486: 					currobj.startindex = int(tagstr) - 1
  487: 				else:
  488: 					errstr = errstr + 'ERRRRROR: cannot extract startnumber from startindex.<br>'
  489: 				onstartindex = False
  490: 				
  491: 			if onendindex:
  492: 				if IsInt(tagstr):
  493: 					currobj.endindex = int(tagstr) - 1
  494: 				else:
  495: 					errstr = errstr + 'ERRRRROR: cannot extract endnumber from endindex.<br>'
  496: 				onendindex = False
  497: 			
  498: 		if name == 'url':
  499: 			tagstr = normalize_whitespace(tagstr)
  500: 			if onpageurl:
  501: 				currobj.url = tagstr
  502: 				onpageurl = False
  503: 			if onstarturl:
  504: 				currobj.starturl = tagstr
  505: 				onstarturl = False
  506: 			if onendurl:
  507: 				currobj.endurl = tagstr
  508: 				onendurl = False
  509: 			
  510: 		if name == 'end':
  511: 			onstart = False
  512: 			onend = False
  513: 
  514: 
  515: ########################################################################################
  516: def normalize_whitespace(text):
  517:     "Remove redundant whitespace from a string"
  518:     return ' '.join(text.split())
  519: 
  520: 
  521: ########################################################################################
  522: def IsInt(str):
  523: 	""" Is the given string an Integer? """
  524: 	try: int(str)
  525: 	except ValueError:
  526: 		return 0
  527: 	else:
  528: 		return 1
  529: 
  530: ########################################################################################
  531: def IsStr(str):
  532: 	""" Is the given string really a string? """
  533: 	try: str + ''
  534: 	except: return 0
  535: 	else: return 1
  536: 
  537: ########################################################################################
  538: class PageObject:
  539: 	def __init__(self):
  540: 		self.name = ""
  541: 		self.index = 0
  542: 		self.pictindex = 0
  543: 		self.url = ""
  544: 		self.isselected = False
  545: 		self.typestr = "page"
  546: 		self.chapterindex = 0
  547: 		self.prevref = 0
  548: 		self.nextref = 0
  549: 		self.chapref = 0
  550: 		
  551: 	def CreatePage(self, level):
  552: 		global counter
  553: 		global counterid
  554: 		global gbaseurl
  555: 		global gpicpath
  556: 		global pagearray
  557: 		global errstr
  558: 		
  559: 		self.chapterindex = level
  560: 		pageelement = PageElement()
  561: 		pageelement.id = str(counterid)
  562: 		pageelement.type = "P"
  563: 		pageelement.name = self.name
  564: 		if IsStr(self.url):
  565: 			if len(self.url) > 0:
  566: 				if IsStr(gbaseurl):
  567: 					if len(gbaseurl) > 0:
  568: 						if gbaseurl[-1] == '/':
  569: 							pageelement.picturelink = gbaseurl + self.url
  570: 						else:
  571: 							pageelement.picturelink = gbaseurl + '/' + self.url
  572: 				else:
  573: 					pageelement.picturelink = self.url
  574: 			else:
  575: 				if IsStr(gbaseurl):
  576: 					pageelement.picturelink = gbaseurl
  577: 		else:
  578: 			pageelement.picturelink = gbaseurl
  579: 			
  580: 		pageelement.level = self.chapterindex
  581: 
  582: 		if IsInt(self.index):
  583: 			if int(self.index) >= 0:
  584: 				pageelement.pictindex = int(self.index)
  585: 				if IsStr(pageelement.picturelink):
  586: 					if len(pageelement.picturelink) > 0:
  587: 						pageelement.picturelink = pageelement.picturelink + str(self.index + 1)
  588: 				
  589: 			else:
  590: 				pageelement.pictindex = '9999'
  591: 		else:
  592: 			pageelement.pictindex = '9999'
  593: 
  594: 		if pageelement.level == 0:
  595: 			pageelement.open = 1
  596: 		else:
  597: 			pageelement.open = 0
  598: 			
  599: 		pagearray.append(pageelement)
  600: 		counter = counter + 1
  601: 		counterid = counterid + 1
  602: 
  603: 
  604: ########################################################################################
  605: class ChapterObject:
  606: 	def __init__(self, chapterindex):
  607: 		self.name = ""
  608: 		self.typestr = "chapter"
  609: 		self.chapterindex = chapterindex
  610: 		self.isselected = False
  611: 		self.isopen = False
  612: 		self.prevref = 0
  613: 		self.nextref = 0
  614: 		self.upref = 0
  615: 		self.chapterobjects = []
  616: 		self.pages_subchapters = []
  617: 		
  618: 	def parseobjects(self):
  619: 		thelen = len(self.chapterobjects)
  620: 		if hasattr(self, 'chapterobjects'):
  621: 			count = 0
  622: 			for i in self.chapterobjects:
  623: 				count += 1
  624: 				if hasattr(self, 'typestr'):
  625: 					if i.typestr == 'page':
  626: 						self.pages_subchapters.append(i)
  627: 					if i.typestr == 'chapter':
  628: 						i.parseobjects()
  629: 					if i.typestr == 'start':
  630: 						i.startindex = int(i.startindex)
  631: 						if i.startindex > 0:
  632: 							i.endindex = int(i.endindex)
  633: 							if i.endindex > 0:
  634: 								if i.endindex < i.startindex:
  635: 									errstr = errstr + 'ERROR in XML file: \"&lt;start&gt; index bigger then &lt;end&gt; index.\"<br>'
  636: 							else:
  637: 								startfound = False
  638: 								for j in range(count, len(self.chapterobjects)):
  639: 									if self.chapterobjects[j].typestr == 'start':
  640: 										startfound = True
  641: 										i.endindex = self.chapterobjects[j].startindex - 1
  642: 										break
  643: 									if self.chapterobjects[j].typestr == 'page':
  644: 										i.endindex = self.chapterobjects[j].index - 1	
  645: 										startfound = True
  646: 										break
  647: 										
  648: 								if not startfound:
  649: 									errstr = errstr + 'ERROR in XML file: \"&lt;start&gt; tag in chapter has no end-tag.\"<br>'
  650: #						print ' startname: ', i.startname
  651: #						print 'startindex: ', i.startindex
  652: #						print '    endurl: ', i.starturl
  653: #						print '   endname: ', i.endname
  654: #						print '  endindex: ', i.endindex
  655: #						print '    endurl: ', i.endurl, '\n'
  656: 
  657: 	def CreateChapter(self):
  658: 		global counter
  659: 		global counterid
  660: 		global gbaseurl
  661: 		global pagearray
  662: 		global errstr
  663: 
  664: 		thelen = len(self.chapterobjects)
  665: 		chapelement = PageElement()
  666: 		chapelement.name = self.name
  667: 		chapelement.id = counterid
  668: 		chapelement.type = "C"
  669: 		chapelement.level = self.chapterindex
  670: 		chapelement.open = 0
  671: 		chapelement.picturelink = ''
  672: 		chapelement.pictindex = 9999;
  673: 		pagearray.append(chapelement)
  674: 		counterid = counterid + 1
  675: 		if hasattr(self, 'chapterobjects'):
  676: 			count = 0
  677: 			for i in self.chapterobjects:
  678: 				count += 1
  679: 				if hasattr(self, 'typestr'):
  680: 					if i.typestr == 'page':
  681: 						i.CreatePage(self.chapterindex + 1)
  682: 					if i.typestr == 'chapter':
  683: 						i.CreateChapter()
  684: 					if i.typestr == 'start':
  685: 						namenumber = counter
  686: 						nameprev = ""
  687: 						urlstart = 0
  688: 						urlend = 0
  689: 						if i.startname != '':
  690: 							t = re.search(r'\d*$', i.startname)
  691: 							if not IsInt(t.group(0)):
  692: 								t = re.sub('(\..*$)', '', s)
  693: 								t = re.search(r'\d*$', t)
  694: 								if IsInt(t.group(0)):
  695: 									namenumber = int(t.group(0))
  696: 									nameprev = re.sub(r'\d*$', '', i.startname)
  697: 								else:
  698: 									errstr = errstr + 'ERRRRROR: cannot extract startnumber.<br>'
  699: 							else:
  700: 								namenumber = int(t.group(0))
  701: 								nameprev = re.sub(r'\d*$', '', i.startname)
  702: 
  703: 						if ( (i.startindex > 0) and (i.endindex > 0) and (i.endindex > i.startindex) ):
  704: 							currcount = 0
  705: 							for j in range(i.startindex, i.endindex + 1):
  706: 								currnumber = namenumber + currcount
  707: 								pageelement = PageElement()
  708: 								pageelement.name = nameprev + str(currnumber)
  709: 								pageelement.level = self.chapterindex + 1
  710: 								pageelement.id = counterid
  711: 								pageelement.type = "P"
  712: 								pageelement.open = 0
  713: 								pageelement.pictindex = j
  714: 								pageelement.picturelink = gbaseurl + str(j)
  715: 								pagearray.append(pageelement)
  716: 								currlen = len(pagearray)
  717: 								if pagearray[currlen - 2].type == 'C':
  718: 									pagearray[currlen - 2].pictindex = j
  719: 									pagearray[currlen - 2].picturelink = gbaseurl + str(j)
  720: 								counter = counter + 1
  721: 								counterid = counterid + 1
  722: 								currcount = currcount + 1
  723: 						else:
  724: 							t = re.search(r'\d*$', i.starturl)
  725: 							if not IsInt(t.group(0)):
  726: 								t = re.sub('(\..*$)', '', s)
  727: 								t = re.search(r'\d*$', t)
  728: 								if IsInt(t.group(0)):
  729: 									urlstart = int(t.group(0))
  730: 								else:
  731: 									errstr = errstr + 'ERRRRROR: cannot extract number from starturl.<br>'
  732: 							else:
  733: 								urlstart = int(t.group(0))
  734: 							t = re.search(r'\d*$', i.endurl)
  735: 							if not IsInt(t.group(0)):
  736: 								t = re.sub('(\..*$)', '', s)
  737: 								t = re.search(r'\d*$', t)
  738: 								if IsInt(t.group(0)):
  739: 									urlend = int(t.group(0))
  740: 								else:
  741: 									errstr = errstr + 'ERRRRROR: cannot extract from endnumber.<br>'
  742: 							else:
  743: 								urlend = int(t.group(0))
  744: 							if ( (urlstart > 0) and (urlend > 0) and (urlend > urlstart) ):
  745: 								for j in range(urlstart, urlend):
  746: 									pageelement = PageElement()
  747: 									currnumber = namenumber + j
  748: 									pageelement.name = nameprev + str(currnumber)
  749: 									pageelement.level = self.chapterindex + 1
  750: 									pageelement.id = counterid
  751: 									pageelement.type = "P"
  752: 									pageelement.open = 0
  753: 									pageelement.pictindex = j
  754: 									pageelement.picturelink = gbaseurl + str(j)
  755: 									pagearray.append(pageelement)
  756: 
  757: 									counter = counter + 1
  758: 									counterid = counterid + 1
  759: 		
  760: 
  761: ########################################################################################
  762: class StartEndObject:
  763: 	def __init__(self):
  764: 		self.startname = ""
  765: 		self.startindex = 0
  766: 		self.starturl = ""
  767: 		self.endname = ""
  768: 		self.endindex = 0
  769: 		self.endurl = ""
  770: 		self.typestr = "start"
  771: 		self.prevref = 0
  772: 		self.nextref = 0
  773: 		self.chapref = 0
  774: 		
  775: 
  776: ########################################################################################
  777: class PageElement:
  778: 	def __init__(self):
  779: 		self.id = ""
  780: 		self.type = ""
  781: 		self.name = ""
  782: 		self.picturelink = ""
  783: 		self.pictindex = 0
  784: 		self.level = 0
  785: 		self.open = 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>