Exemple #1
0
    def get_corrective_test(self, comment):
        c_text = ")"

        tmpl = template.load("correction")
        tmpl["correction_text"] = c_text
        tmpl["xkcd_link_text"] = cfg.COMMENT_XKCD_COMIC_LINK_TEXT
        tmpl["xkcd_link"] = cfg.COMMENT_XKCD_COMIC_LINK
        tmpl["bottom_text"] = cfg.COMMENT_BOTTOM_TEXT
        tmpl["pre_link_text"] = cfg.COMMENT_PRE_LINK_TEXT

        return tmpl.built()
 def get_corrective_test(self, comment):
     c_text = ")"
     
     tmpl = template.load("correction")
     tmpl["correction_text"] = c_text
     tmpl["xkcd_link_text"] = cfg.COMMENT_XKCD_COMIC_LINK_TEXT
     tmpl["xkcd_link"] = cfg.COMMENT_XKCD_COMIC_LINK
     tmpl["bottom_text"] = cfg.COMMENT_BOTTOM_TEXT
     tmpl["pre_link_text"] = cfg.COMMENT_PRE_LINK_TEXT
     
     return tmpl.built()
Exemple #3
0
def main():
    global webpage_template
    args = parse_args()
    path = Path_Reformatter(src=args.skel, dest=args.webdir)

    template.load(args.url)

    master_index = dict()
    master_anomaly = dict()

    config = load_config(os.path.join(path.dir_src, "config.json"))

    for path_src, dirs, files in os.walk(path.dir_src):
        if not os.path.exists(path.dest(path.SRC, path_src)):
            os.mkdir(path.dest(path.SRC, path_src))

        # build an index of files to display
        index = []
        path_mutual = path.mutual(path.SRC, path_src)
        if path_mutual in master_index:
            index = master_index[path_mutual]

        # get a list of files already in the destination, to delete anything unexpected.
        listing = None
        if path_mutual in master_anomaly:
            listing = master_anomaly[path_mutual]
        else:
            listing = os.listdir(path.dest(path.MUTUAL, path_mutual))

        has_defaulthtml = False

        print("/" + path.mutual(path.SRC, path_src))

        for dir in dirs:
            if dir in listing: listing.remove(dir)
            destpath = os.path.join(path.dest(path.SRC, path_src), dir)
            if os.path.isfile(destpath):
                os.remove(destpath)
            index.append({
                "name": dir,
                "type": "dir",
                "mime": "Directory",
                "size": 0
            })

        for file in files:
            ext = os.path.splitext(file)[1]
            mutualpath = path.mutual(path.SRC, os.path.join(path_src, file))

            if mutualpath in config["files"]:
                if "action" in config["files"][mutualpath]:
                    if config["files"][mutualpath]["action"] == "ignore":
                        continue
                    if config["files"][mutualpath]["action"] == "raw":
                        path.copy_file(mutualpath)
                        if not "listed" in config["files"][
                                mutualpath] or config["files"][mutualpath][
                                    "listed"]:
                            index.append({
                                "name":
                                file,
                                "type":
                                "file",
                                "mime":
                                mimetypes.guess_type(mutualpath)[0],
                                "size":
                                os.path.getsize(
                                    path.dest(path.MUTUAL, mutualpath))
                            })
                        if file in listing: listing.remove(file)
                        continue

                if "forcetype" in config["files"][mutualpath]:
                    ext = "." + config["files"][mutualpath]["forcetype"]

            if file in listing: listing.remove(file)

            if ext in [".html", ".htm", ".md"]:
                newname = file[:-len(ext)] + ".html"
                if newname in listing: listing.remove(newname)
                if newname + ".json" in listing:
                    listing.remove(newname + ".json")
                path_dest = path.dest(path.MUTUAL,
                                      mutualpath)[:-len(ext)] + ".html"

                page = None
                if ext == ".md":
                    page = template.Markdown(name=newname,
                                             pwd=path.absolute(
                                                 path.SRC, path_src))
                else:
                    page = template.Html(name=newname,
                                         pwd=path.absolute(path.SRC, path_src))

                with open(path.src(path.MUTUAL, mutualpath), 'r') as fd:
                    page.parse(fd.read())

                with open(path_dest, 'w') as fd:
                    fd.write(page.render(minify=args.minify))

                with open(path_dest + ".json", 'w') as fd:
                    fd.write(json.dumps(page.as_dict(minify=args.minify)))

                index.append({
                    "name": newname,
                    "type": "html",
                    "mime": "text/html",
                    "size": os.path.getsize(path_dest)
                })

            elif ext in [".jpeg", ".jpg", ".png", ".svg"]:
                path.copy_file(mutualpath)
                index.append({
                    "name":
                    file,
                    "type":
                    "file",
                    "mime":
                    mimetypes.guess_type(mutualpath)[0],
                    "size":
                    os.path.getsize(path.dest(path.MUTUAL, mutualpath))
                })

            elif ext in [".txt", ".conf"]:
                path.copy_file(mutualpath)
                index.append({
                    "name":
                    file,
                    "type":
                    "file",
                    "mime":
                    "text/plain",
                    "size":
                    os.path.getsize(path.dest(path.MUTUAL, mutualpath))
                })

            else:
                print("Found unknown file {}, type: {}".format(
                    mutualpath, mimetypes.guess_type(mutualpath)))

        master_index[path_mutual] = index
        master_anomaly[path_mutual] = listing

    # generate index pages
    pathobj = Path_Reformatter(src="", dest=args.webdir)
    for key in master_index:
        added_files = create_index_page(pathobj, key, master_index[key],
                                        args.redirect)
        for file in added_files:
            if file in master_anomaly[key]: master_anomaly[key].remove(file)

    # delete anomilies
    for dir in master_anomaly:
        for anomaly in master_anomaly[dir]:
            delete_with_extreme_prejudice(
                os.path.join(path.dest(path.MUTUAL, dir), anomaly))
Exemple #4
0
 def GET(self):
     html = template.load('index.html')
     links = [href(path) for path in glob.glob('static/data/*')]
     links = '\n<br/>'.join(links)
     html = html.format(links)
     return html
	def GET(self):
		return template.load("index.jade").render(activetab='bla1')