Browse Source

Move pad pulling into own function

pull/8/head
Luke Murphy 5 years ago
parent
commit
b82f39a42d
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 90
      etherpump/commands/pull.py

90
etherpump/commands/pull.py

@ -163,19 +163,7 @@ def build_argument_parser(args):
return parser return parser
def get_padids(args, info, data):
def main(args):
p = build_argument_parser(args)
args = p.parse_args(args)
raw_ext = ".raw.txt"
if args.no_raw_ext:
raw_ext = ""
info = loadpadinfo(args.padinfo)
data = {}
data['apikey'] = info['apikey']
if args.padid: if args.padid:
padids = args.padid padids = args.padid
elif args.glob: elif args.glob:
@ -188,18 +176,12 @@ def main(args):
info['localapiurl'] + 'listAllPads?' + urlencode(data) info['localapiurl'] + 'listAllPads?' + urlencode(data)
)['data']['padIDs'] )['data']['padIDs']
padids.sort() padids.sort()
numpads = len(padids) return padids
# maxmsglen = 0
count = 0
progress_kwargs = {}
if not istty():
progress_kwargs.update(dict(disable=True))
progress_pads = tqdm(iterable=padids, total=len(padids), **progress_kwargs)
for i, padid in enumerate(progress_pads): def handle_pad(args, index, padid, data, info, raw_ext):
if args.skip != None and i < args.skip: if args.skip != None and index < args.skip:
continue return
data['padID'] = padid data['padID'] = padid
p = padpath(padid, args.pub, args.group, args.fix_names) p = padpath(padid, args.pub, args.group, args.fix_names)
@ -219,9 +201,7 @@ def main(args):
with open(metapath) as f: with open(metapath) as f:
meta.update(json.load(f)) meta.update(json.load(f))
revisions = getjson( revisions = getjson(
info['localapiurl'] info['localapiurl'] + 'getRevisionsCount?' + urlencode(data)
+ 'getRevisionsCount?'
+ urlencode(data)
)['data']['revisions'] )['data']['revisions']
if meta['revisions'] == revisions and not args.force: if meta['revisions'] == revisions and not args.force:
skip = True skip = True
@ -230,18 +210,12 @@ def main(args):
meta['padid'] = padid meta['padid'] = padid
versions = meta["versions"] = [] versions = meta["versions"] = []
versions.append( versions.append(
{ {"url": padurlbase + quote(padid), "type": "pad", "code": 200,}
"url": padurlbase + quote(padid),
"type": "pad",
"code": 200,
}
) )
if revisions == None: if revisions is None:
meta['revisions'] = getjson( meta['revisions'] = getjson(
info['localapiurl'] info['localapiurl'] + 'getRevisionsCount?' + urlencode(data)
+ 'getRevisionsCount?'
+ urlencode(data)
)['data']['revisions'] )['data']['revisions']
else: else:
meta['revisions'] = revisions meta['revisions'] = revisions
@ -287,9 +261,7 @@ def main(args):
break break
if skip: if skip:
continue return
count += 1
if args.output: if args.output:
print(padid) print(padid)
@ -321,7 +293,7 @@ def main(args):
p + ".meta.json", p + ".meta.json",
) )
) )
continue return
########################################## ##########################################
## ENFORCE __PUBLISH__ MAGIC WORD ## ENFORCE __PUBLISH__ MAGIC WORD
@ -335,7 +307,7 @@ def main(args):
p + ".meta.json", p + ".meta.json",
) )
) )
continue return
ver["path"] = p + raw_ext ver["path"] = p + raw_ext
ver["url"] = quote(ver["path"]) ver["url"] = quote(ver["path"])
@ -394,8 +366,6 @@ def main(args):
} }
) )
# links.append({"href":"/", "rel":"search", "type":"text/html", "title":"Index"})
if args.all or args.dhtml: if args.all or args.dhtml:
data['startRev'] = "0" data['startRev'] = "0"
html = getjson( html = getjson(
@ -409,7 +379,6 @@ def main(args):
html = html['data']['html'] html = html['data']['html']
ver["path"] = p + ".diff.html" ver["path"] = p + ".diff.html"
ver["url"] = quote(ver["path"]) ver["url"] = quote(ver["path"])
# doc = html5lib.parse(html, treebuilder="etree", override_encoding="utf-8", namespaceHTMLElements=False)
doc = html5lib.parse( doc = html5lib.parse(
html, treebuilder="etree", namespaceHTMLElements=False html, treebuilder="etree", namespaceHTMLElements=False
) )
@ -426,10 +395,7 @@ def main(args):
file=f, file=f,
) )
except TypeError: except TypeError:
# Malformed / incomplete response, record the message (such as "internal error") in the metadata and write NO file!
ver["message"] = html["message"] ver["message"] = html["message"]
# with open(ver["path"], "w") as f:
# print ("""<pre>{0}</pre>""".format(json.dumps(html, indent=2)), file=f)
# Process text, html, dhtml, all options # Process text, html, dhtml, all options
if args.all or args.html: if args.all or args.html:
@ -445,16 +411,11 @@ def main(args):
html, treebuilder="etree", namespaceHTMLElements=False html, treebuilder="etree", namespaceHTMLElements=False
) )
html5tidy( html5tidy(
doc, doc, indent=True, title=padid, scripts=args.script, links=links,
indent=True,
title=padid,
scripts=args.script,
links=links,
) )
with open(ver["path"], "w") as f: with open(ver["path"], "w") as f:
print( print(
ET.tostring(doc, method="html", encoding="unicode"), ET.tostring(doc, method="html", encoding="unicode"), file=f,
file=f,
) )
# output meta # output meta
@ -465,3 +426,26 @@ def main(args):
ver["url"] = quote(metapath) ver["url"] = quote(metapath)
with open(metapath, "w") as f: with open(metapath, "w") as f:
json.dump(meta, f, indent=2) json.dump(meta, f, indent=2)
def main(args):
p = build_argument_parser(args)
args = p.parse_args(args)
raw_ext = ".raw.txt"
if args.no_raw_ext:
raw_ext = ""
info = loadpadinfo(args.padinfo)
data = {}
data['apikey'] = info['apikey']
padids = get_padids(args, info, data)
progress_kwargs = {}
if not istty():
progress_kwargs.update(dict(disable=True))
progress_pads = tqdm(iterable=padids, total=len(padids), **progress_kwargs)
for index, padid in enumerate(progress_pads):
handle_pad(args, index, padid, data, info, raw_ext)

Loading…
Cancel
Save