diff options
author | a-e-m <alexemartyn@gmail.com> | 2013-12-09 00:15:50 (GMT) |
---|---|---|
committer | a-e-m <alexemartyn@gmail.com> | 2013-12-09 00:15:50 (GMT) |
commit | b7c818bf00b5c9e23ee97ce6669eb66a9b404562 (patch) | |
tree | 77888ec55153956c9da4622e323762afdd3cf470 /tests | |
parent | d6bffc4691cf1467cf93d527724f7278b418273d (diff) |
Revert to uploading to dinkypage, gists won't work
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_pretty_print.py | 77 |
1 files changed, 32 insertions, 45 deletions
diff --git a/tests/test_pretty_print.py b/tests/test_pretty_print.py index b601c84..675867e 100755 --- a/tests/test_pretty_print.py +++ b/tests/test_pretty_print.py @@ -36,12 +36,11 @@ import subprocess import time import platform try: - from urllib.request import urlopen, Request + from urllib.request import urlopen + from urllib.parse import urlencode except: - from urllib2 import urlopen, Request -import json -import base64 - + from urllib2 import urlopen + from urllib import urlencode def tryread(filename): data = None @@ -363,43 +362,32 @@ def to_html(project_name, startdate, tests, enddate, sysinfo, sysid, makefiles): # --- Web Upload --- -API_URL = 'https://api.github.com/%s' -# Username is personal access token, from https://github.com/settings/applications -# This way, no password is needed -USERNAME = '' # add OpenScad user token -PASSWORD = '' - -def make_auth(username, password): - auth = '%s:%s' % (USERNAME, PASSWORD) - return base64.b64encode(auth.encode()) - -def post_gist(name, content): - gist = '''{ - "description": "", - "public": true, - "files": { - "%s": { - "content": "%s" - } - } - }''' - gist = gist % (name, content) - - req = Request(API_URL % 'gists') - req.add_header('Authorization', b'Basic ' + make_auth(USERNAME, PASSWORD)) +def postify(data): + return urlencode(data).encode() + +def create_page(): + data = { + 'action': 'create', + 'type': 'html' + } try: - result = urlopen(req, data=gist) + response = urlopen('http://www.dinkypage.com', data=postify(data)) except: - print 'Could not upload results' return None - return json.loads(result.read()) - - -def get_raw_urls(result): - files = result.get('files', {}) - for file in files: - yield files[file].get('raw_url').replace('gist.github.com', 'rawgithub.com') - + return response.geturl() + +def upload_html(page_url, title, html): + data = { + 'mode': 'editor', + 'title': title, + 'html': html, + 'ajax': '1' + } + try: + response = urlopen(page_url, data=postify(data)) + except: + return False + return 'success' in response.read().decode() # --- End Web Upload --- @@ -458,13 +446,12 @@ def main(): debug('saving ' + html_filename + ' ' + str(len(html)) + ' bytes') trysave(html_filename, html) - result = post_gist(name=html_basename, content=html) - if result is None: + page_url = create_page() + if upload_html(page_url, title='OpenSCAD test results', html=html): + share_url = page_url.partition('?')[0] + print 'html report uploaded at', share_url + else: print 'could not upload html report' - return - - for url in get_raw_urls(result): - print 'html report uploaded at', url debug('test_pretty_print complete') |