def generate(self, template_list): self.print_message() for i in self.get_images(): i.set_local_root(self.get_local_root(False)) i.set_output_root(self.get_local_output_root(False)) self.hero.set_output_root(self.get_local_output_root(False)) content = util.minify_html(self.generate_html(template_list)) filenames = [] filenames.append(self.path) filenames.append(path.Path('', self.unique_hash + '/index.html')) # for s in self.synonyms: # p = path.Path() # p.copy_from(self.path) # p.set_output_root(os.path.join(util.category_dir(self.category), util.text_to_shortname(s))) # filenames.append(p) for s in self.synonyms: p = path.Path() p.copy_from(self.path) p.set_output_root(os.path.join(util.category_dir(self.category), util.text_to_shortname(s))) os.makedirs(p.get_local_output_root(), exist_ok=True) for filename in filenames: os.makedirs(filename.get_local_output_root(), exist_ok=True) open(filename.get_local_output_path(), 'w').write(content) self.copy_files(self.path)
def set_shortname(self, shortname): shortname = util.text_to_shortname(self.unique) s = shortname[:] i = 0 while True: if self.build.post_shortname_exists(s): s = shortname + str(i+1) i += 1 continue break self.shortname = s if i: print('warning: name ' + shortname + ' already exists, using ' + self.shortname + ' instead.') self.term = util.text_to_shortname(self.shortname) self.path.set_output_root(os.path.join(util.category_dir(self.category), self.shortname))
def get_terms(self): if not self.md: self.get_html_text() terms = self.md.terms + self.terms for i in self.images: terms.extend(i.get_terms()) terms.extend(self.hero.get_terms()) return [util.text_to_shortname(x) for x in terms]
def __init__(self): self.posts = [] self.authors = {} self.template_list = template.TemplateList() self.collect_authors() self.synonyms = {} self.posts = [] self.terms = [] self.collect_posts(['article', 'news', 'update']) self.collect_terms(['term']) for term in self.terms: s = [util.text_to_shortname(x) for x in term.synonyms] for x in s: if x == term.shortname: continue self.synonyms[x] = term.shortname self.term_crossreference()
def parse_key(self, key, value): if key == 'file': self.image_filename = value elif key == 'caption': self.image_caption = value elif key == 'credit': self.image_credit = value elif key == 'license': self.image_license = value elif key == 'type': self.image_type = value elif key == 'gravity': if value in ['top', 'center', 'middle', 'bottom', 'left', 'right']: self.image_gravity = value else: raise util.GenException('invalid gravity "' + value + '"') elif key == 'contains': term = util.text_to_shortname(value) self.image_contains.append(term) self.terms.append(term) else: return False return True
def get_synonyms(self): synonyms = self.synonyms + [] synonyms.append(self.shortname) synonyms.append(self.title) synonyms = list(set([util.text_to_shortname(x) for x in synonyms])) return synonyms
def post_get_by_reference(self, reference): reference = util.text_to_shortname(reference) for post in self.terms + self.posts: if reference in post.get_synonyms(): return post return False
def post_shortname_exists(self, shortname): shortname = util.text_to_shortname(shortname) for post in self.terms + self.posts: if post.shortname == shortname: return post return False
def add_manufacturer(self, value): value = util.text_to_shortname(value) if value in self.manufacturers: return self.manufacturers.append(value) self.term.add_term(value)
def add_location(self, value): value = util.text_to_shortname(value) if value in self.locations: return self.locations.append(value) self.term.add_term(value)
def add_term(self, term): term = util.text_to_shortname(term.strip()) if term not in self.terms: self.terms.append(term)
def add_synonym(self, synonym): synonym = util.text_to_shortname(synonym.strip()) if synonym not in self.synonyms: self.synonyms.append(synonym)
def add_vehicle(self, value): value = util.text_to_shortname(value) if value in self.vehicles: return self.vehicles.append(value) self.term.add_term(value)
def add_stage(self, value): value = util.text_to_shortname(value) if value in self.stage: return self.stages.append(value) self.term.add_term(value)
def has_manufacturer(self, value): value = util.text_to_shortname(value) if value in self.manufacturers: return True