Still very ugly, will likely scrap it a rebuild from scratch

This commit is contained in:
Malphaet 2017-03-17 01:14:02 +01:00
parent fcfe2a434f
commit 4bda52a4c1
3 changed files with 34 additions and 25 deletions

View File

@ -78,7 +78,7 @@ class WebPage(object):
else:
if filter_lang=="*":
return self.variables[varname].values()[0]
raise KeyError("The variable "+varname+" doens't exist in the language "+filter_lang)
raise KeyError("The variable "+varname+" doens't exist in the language "+filter_lang)
def export(self):
"Export the Webobject in every language"

View File

@ -4,7 +4,7 @@ from tree_parser import *
import re,traceback
re_vars=re.compile(".*\#_(?P<variable>.*)_\#|.*\#\#(?P<section>.*)\#\#")
re_vars=re.compile(".*\#_(?P<variable>.*)_\#")
class HTMLPage(object):
"Basic HTML object"
@ -27,18 +27,11 @@ class HTMLPage(object):
for line in self.model.splitlines():
#print line
try:
variable,section=re_vars.match(line).groups()
variable=re_vars.match(line).groups()[0]
if variable!=None:
#print line,re_vars.match(line),variable
#print self.node.config_file
#print self.node.get_variable(variable,lang),variable
line=line.replace("#_"+variable+"_#",self.node.get_variable(variable,lang))
#print line
elif section!=None:
pass
except AttributeError:
pass#print " > No match"
pass
except:
print traceback.print_exc()
self.html+=line
@ -67,8 +60,13 @@ class DualContainer(Container):
class DualData(Data):
"Dual view"
pass
def __init__(self,name,node):
super(DualData,self).__init__(name,node)
def replace(self,lang):
self.html=self.model
self.html=self.html.replace("#_content_#",self.node.get_content("fr"))
self.html=self.html.replace("#_name_#",self.node.get_variable("title","fr"))
def DataType(ext):
"Return some kind of general types depending on the extention"
@ -89,16 +87,22 @@ def makeContainer(node):
c.replace("fr")
return c
def makeMakeContent(node):
def makeData(node):
c=DualData(node.name,node)
c.load("generator/model/dual_page.html")
c.replace("fr")
return c
def makePage(node,cont,data):
c=DualData(node.name,node)
c.replace("fr")
cont.export()
c=DualData(node.name,node.tree)
c.load("generator/model/dual_container.html")
print cont.export()
print data.export()
print c.export()
if __name__ == '__main__':
makeContainer(makeWebsite("sites/example_website"))
site=makeWebsite("sites/example_website")
cont=makeContainer(site)
data=makeData(site.tree.get_node("index","fr"))
makePage(site,cont,data)

View File

@ -16,6 +16,7 @@ class WebTree(object):
def make_tree(self):
"Walk the directory and subdirectories and make the tree from it, note that the WebTree only have one Subtree, containing other subtrees"
self.tree=WebSubTree(self.website_path,"")
self.tree.parent_node=self
def get_config(self):
"Get the basic config from the website"
@ -79,10 +80,14 @@ class WebSubTree(WebTree):
path=os.path.join(self.path,f)
if os.path.isdir(name):
var,lang=file_parser.create_lang(f)
self.subtree=file_parser.add_to_table(var,lang,WebSubTree(self.website_path,path),self.subtree)
new=WebSubTree(self.website_path,path)
new.parent_node=self
self.subtree=file_parser.add_to_table(var,lang,new,self.subtree)
else:
var,lang=file_parser.create_lang(os.path.splitext(f)[0])
self.nodes=file_parser.add_to_table(var,lang,WebNode(self.website_path,path),self.nodes)
new=WebNode(self.website_path,path)
new.parent_node=self
self.nodes=file_parser.add_to_table(var,lang,new,self.nodes)
#print self, self.subtree
#print self.nodes
@ -93,16 +98,16 @@ class WebSubTree(WebTree):
def get_node(self,name,filter_lang=""):
"Get a node with a specific name"
if name in self.nodes:
if filter_lang!="": #No specific lang, so all langs are returned, should disapear soon I think
return self.nodes
if filter_lang=="": #No specific lang, so all langs are returned, should disapear soon I think
return self.nodes[name]
if filter_lang in self.nodes[name]:
return self.nodes[filter_lang]
return self.nodes["*"] # specific language unavailable, all languages returned, better luck here
return self.nodes[name][filter_lang]
return self.nodes[name]["*"] # specific language unavailable, all languages returned, better luck here
raise IndexError("The node "+name+" doesn't exist")
def get_content(self,name,filter_lang=""):
"Get the content of the node in the specified language"
return get_node(name,filter_lang).get_content(filter_lang)
return self.get_node(name,filter_lang).get_content(filter_lang)
def print_webtree(self,prefix=""):
"Print the tree and recuse"
@ -131,7 +136,7 @@ class WebNode(WebSubTree):
def get_variable(self,varname,filter_lang):
"Get the corresponding variable, first in the Webnode, then the config and repeating up until the Root"
try:
return self.config_file.get_variable(varname,filter_lang)
return self.parse.get_variable(varname,filter_lang)
except:
try:
return self.config_file.get_variable(varname,filter_lang)