Barely made any progress, but at least I'm back

This commit is contained in:
Maximilien Rigaut 2017-08-24 20:32:38 +02:00
parent e57cf0f878
commit 7a9eb77c4a
2 changed files with 43 additions and 11 deletions

View File

@ -101,6 +101,7 @@ class WebSubTree(WebTree):
self.subtree={}
self.nodes={}
# This generator is deeply flawed, and should create temp nodes every time it meets a _lang folder then split from it
for f in os.listdir(self.full_path):
name=os.path.join(self.full_path,f)
path=os.path.join(self.path,f)
@ -129,7 +130,7 @@ class WebSubTree(WebTree):
return self.nodes[name]
if filter_lang in self.nodes[name]:
return self.nodes[name][filter_lang]
return self.nodes[name]["*"] # specific language unavailable, all languages returned, better luck here
return self.nodes[name]["*"] # Specific language unavailable, all languages returned, better luck here
raise IndexError("The node "+name+" doesn't exist")
def get_next_subtree(self,filter_lang="*"):
@ -144,6 +145,7 @@ class WebSubTree(WebTree):
return self.subtree[name]
if filter_lang in self.subtree[name]:
return self.subtree[name][filter_lang]
#print self.subtree[name]
return self.subtree[name]["*"] # specific language unavailable, all languages returned, better luck here
raise IndexError("The tree "+subtree+" doesn't exist")
@ -196,9 +198,17 @@ class WebNode(WebSubTree):
def get_content(self,filter_lang):
"""Output the content of the node, in the correct language
(note that you shouldn't ask directly a node for it's content, rather a Subtree for a node in the correct language)"""
if filter_lang in self.content:
try:
return self.content[filter_lang]
return self.content["*"]
except KeyError:
if "*" in self.content:
return self.content["*"]
else:
return ""
# if I'm asking for "*" am I asking for ANY lang or EVERY lang or ONLY "*" ?
# for now this code will return ONLY the common part aka "*" and return an empty string if there is no common part
except:
raise KeyError("Can't access lang ({}) in node ({})".format(filter_lang,self))
def makeWebsite(website):
"Take a string of the folder name containing the website, will proceed to generate all needed Objects and return the Webtree"

View File

@ -2,18 +2,40 @@
# Copyleft (c) 2016 Cocobug All Rights Reserved.
import argparse
import argparse,os,sys
from generator import *
def vprint(*x):
if args.verbose:
print(x)
parser = argparse.ArgumentParser(description='Website on-the-fly & static generator')
subparsers = parser.add_subparsers(help='Commands')
#subparsers = parser.add_subparsers(help='Commands')
# create the parser for the "a" command
#parser_a = subparsers.add_parser('a', help='a help')
#parser_a.add_argument('bar', type=int, help='bar help')
# The argparse should look like this:
# vkyweb.py PATH_TO_WEBSITE --update(only update) --verbose(show as much as possible) --dry(don't actually write anything) -d(destination if not current folder) -m(custom model) -l(only use theese languages)
parser.add_argument('website_path',metavar="path_to_the_website",type=str,help="Path to the website to parse")
parser.add_argument("--verbose",action="store_true",help="Verbosity to display")
parser.add_argument('--update',action="store_true",help="Only update, don't rewrite")
parser.add_argument("--dry",action="store_true",help="Dry run, don't write anything")
parser.add_argument("-d",metavar="destination",type=str,default=".",help="Destination to write to")
parser.add_argument("-l",metavar="langs",type=str,nargs="+",help="List of langs to generate the site to")
args=parser.parse_args()
s=tree_parser.makeWebsite("sites/example_website")
container=model.makeContainer(s)
# Make tree
if not (os.path.exists(args.website_path)):
if args.verbose:
print "O"
print("Path {} does not exist".format(args.website_path))
sys.exit()
website=tree_parser.makeWebsite(args.website_path)
#website.print_webtree(lang="fr",prefix=" * ")
s.print_webtree(" > ")
# Walk & generate
if args.verbose:
print("Website will be generated in {}".format(args.l))
#for every lang, do a mix of print_webtree and makeContainer
#container=model.makeContainer(s)