migrated individual commands

This commit is contained in:
Michael Murtaugh 2015-09-17 18:43:17 +02:00
parent 5d798275e6
commit 44a152f99d
10 changed files with 130 additions and 119 deletions

2
.gitignore vendored
View File

@ -3,5 +3,3 @@ build/
*~ *~
venv/ venv/
padinfo.json padinfo.json
*.json
!padinfo.sample.json

View File

@ -1,29 +0,0 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--startrev", type=int, default=0, help="starting revision")
p.add_argument("--endrev", type=int, default=None, help="ending revision, default: last")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
args = p.parse_args()
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
data['startRev'] = "{0}".format(args.startrev)
if args.endrev != None:
data['endRev'] = "{0}".format(args.endrev)
requesturl = apiurl+'createDiffHTML?'+urlencode(data)
if args.showurl:
print requesturl
else:
print json.load(urlopen(requesturl))['data']['html']

30
etherdump/commands/diffhtml.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
def main(args):
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--startrev", type=int, default=0, help="starting revision")
p.add_argument("--endrev", type=int, default=None, help="ending revision, default: last")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
args = p.parse_args(args)
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
data['startRev'] = "{0}".format(args.startrev)
if args.endrev != None:
data['endRev'] = "{0}".format(args.endrev)
requesturl = apiurl+'createDiffHTML?'+urlencode(data)
if args.showurl:
print requesturl
else:
print json.load(urlopen(requesturl))['data']['html']

View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
def main(args):
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
p.add_argument("--format", default="lines", help="output format, can be: lines, json; default: lines")
args = p.parse_args(args)
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'listAuthorsOfPad?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']['authorIDs']
if args.format == "json":
print json.dumps(results)
else:
for r in results:
print r.encode("utf-8")

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
def main(args):
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
args = p.parse_args(args)
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'getRevisionsCount?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']['revisions']
print results

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
def main(args):
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
p.add_argument("--format", default="text", help="output format, can be: text, json; default: text")
args = p.parse_args(args)
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'getText?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']
if args.format == "json":
print json.dumps(results)
else:
print results['text'].encode("utf-8")
# To save to file run:
# python gettext.py > copy.txt

View File

@ -1,26 +0,0 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
p.add_argument("--list", default=False, action="store_true", help="display one per line")
args = p.parse_args()
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'getRevisionsCount?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']['revisions']
print results

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
p.add_argument("--text", default=False, action="store_true", help="text output (not json)")
args = p.parse_args()
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'getText?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']
if args.text:
print results['data'].encode("utf-8")
else:
print json.dump(results)
# To save to file run:
# python gettext.py > copy.txt

View File

@ -1,30 +0,0 @@
#!/usr/bin/env python
from argparse import ArgumentParser
import json
from urllib import urlencode
from urllib2 import urlopen, HTTPError, URLError
p = ArgumentParser("")
p.add_argument("padid", help="the padid")
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json")
p.add_argument("--showurl", default=False, action="store_true")
p.add_argument("--list", default=False, action="store_true", help="display one per line")
args = p.parse_args()
with open(args.padinfo) as f:
info = json.load(f)
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {}
data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8")
requesturl = apiurl+'listAuthorsOfPad?'+urlencode(data)
if args.showurl:
print requesturl
else:
results = json.load(urlopen(requesturl))['data']['authorIDs']
if args.list:
for r in results:
print r
else:
print json.dumps(results)

8
padinfo.sample.json Normal file
View File

@ -0,0 +1,8 @@
{
"protocol": "http",
"port": 9001,
"hostname": "localhost",
"apiversion": "1.2.9",
"apiurl": "/api/",
"apikey": "8f55f9ede1b3f5d88b3c54eb638225a7bb71c64867786b608abacfdb7d418be1"
}