python3 all the way
This commit is contained in:
parent
454e42ac8d
commit
5280ad2f5e
@ -4,12 +4,6 @@ import sys, json, re, os, time
|
||||
from datetime import datetime
|
||||
import dateutil.parser
|
||||
|
||||
try:
|
||||
# python2
|
||||
from urllib2 import urlopen, URLError, HTTPError
|
||||
from urllib import urlencode
|
||||
from urlparse import urlparse, urlunparse
|
||||
except ImportError:
|
||||
# python3
|
||||
from urllib.parse import urlparse, urlunparse, urlencode, quote
|
||||
from urllib.request import urlopen, URLError, HTTPError
|
||||
@ -18,6 +12,8 @@ from jinja2 import FileSystemLoader, Environment
|
||||
from pppadump.commands.common import *
|
||||
from time import sleep
|
||||
import dateutil.parser
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
"""
|
||||
index:
|
||||
@ -283,17 +279,38 @@ def main (args):
|
||||
p["text"] = f.read()
|
||||
except FileNotFoundError:
|
||||
p['text'] = ''
|
||||
|
||||
# ADD IN LINK TO PAD AS "link"
|
||||
for v in linkversions:
|
||||
if v in versions_by_type:
|
||||
vdata = versions_by_type[v]
|
||||
try:
|
||||
if v == "pad" or os.path.exists(vdata["path"]):
|
||||
if v == "pad":
|
||||
p["link"] = absurl(vdata["url"], linkbase)
|
||||
break
|
||||
except KeyError as e:
|
||||
pass
|
||||
|
||||
# Not sure this goes here but fixing relpaths with output is quite nice...
|
||||
if args.output:
|
||||
outpath = Path(args.output).parent
|
||||
for v in p["versions"]:
|
||||
if v["type"] != "pad":
|
||||
vpath = Path(v["path"])
|
||||
try:
|
||||
# 2 types (pathlib or os.path)
|
||||
# v["path"] = vpath.parent.relative_to(outpath).joinpath(vpath.name)
|
||||
v["path"] = os.path.join(os.path.relpath(vpath.parent, outpath), vpath.name)
|
||||
|
||||
# path or url??? if it's a file based publishing ethos, it should be path non?
|
||||
# puttting this here since templates are using url...
|
||||
v["url"] = v["path"]
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
if args.output:
|
||||
with open(args.output, "w") as f:
|
||||
print (template.render(vars(args)), file=f)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user