[yt-svn] commit/yt: ngoldbaum: Merged in xarthisius/yt (pull request #2119)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Apr 20 11:13:17 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/454b81690191/
Changeset: 454b81690191
Branch: yt
User: ngoldbaum
Date: 2016-04-20 18:13:09+00:00
Summary: Merged in xarthisius/yt (pull request #2119)
Enhance commandline image upload/delete
Affected #: 3 files
diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed doc/source/reference/command-line.rst
--- a/doc/source/reference/command-line.rst
+++ b/doc/source/reference/command-line.rst
@@ -80,6 +80,7 @@
requested), for one or more datasets (default field is
Density)
update Update the yt installation to the most recent version
+ delete_image Delete image from imgur.com.
upload_image Upload an image to imgur.com. Must be PNG.
@@ -264,3 +265,10 @@
uploads it anonymously to the website `imgur.com <http://imgur.com/>`_ and
provides you with a link to share with your collaborators. Note that the
image *must* be in the PNG format in order to use this function.
+
+delete_image
+++++++++++++
+
+The image uploaded using ``upload_image`` is assigned with a unique hash that
+can be used to remove it. This subcommand provides an easy way to send a delete
+request directly to the `imgur.com <http://imgur.com/>`_.
diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -57,6 +57,9 @@
local_standard_filename = 'local001',
answer_tests_url = 'http://answers.yt-project.org/{1}_{2}',
sketchfab_api_key = 'None',
+ imagebin_api_key = 'e1977d9195fe39e',
+ imagebin_upload_url = 'https://api.imgur.com/3/upload',
+ imagebin_delete_url = 'https://api.imgur.com/3/image/{delete_hash}',
thread_field_detection = 'False',
ignore_invalid_unit_operation_errors = 'False',
chunk_size = '1000',
diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1049,6 +1049,39 @@
else:
_print_failed_source_update(opts.reinstall)
+
+class YTDeleteImageCmd(YTCommand):
+ args = (dict(short="delete_hash", type=str),)
+ description = \
+ """
+ Delete image from imgur.com.
+
+ """
+ name = "delete_image"
+ def __call__(self, args):
+ headers = {'Authorization':
+ 'Client-ID {}'.format(ytcfg.get("yt", "imagebin_api_key"))}
+
+ delete_url = ytcfg.get("yt", "imagebin_delete_url")
+ req = urllib.request.Request(
+ delete_url.format(delete_hash=args.delete_hash),
+ headers=headers, method='DELETE')
+ try:
+ response = urllib.request.urlopen(req).read().decode()
+ except urllib.error.HTTPError as e:
+ print("ERROR", e)
+ return {'deleted': False}
+
+ rv = json.loads(response)
+ if 'success' in rv and rv["success"]:
+ print("\nImage successfully deleted!\n")
+ else:
+ print()
+ print("Something has gone wrong! Here is the server response:")
+ print()
+ pprint.pprint(rv)
+
+
class YTUploadImageCmd(YTCommand):
args = (dict(short="file", type=str),)
description = \
@@ -1062,15 +1095,16 @@
if not filename.endswith(".png"):
print("File must be a PNG file!")
return 1
+ headers = {'Authorization':
+ 'Client-ID {}'.format(ytcfg.get("yt", "imagebin_api_key"))}
+
image_data = base64.b64encode(open(filename, 'rb').read())
- api_key = 'e1977d9195fe39e'
- headers = {'Authorization': 'Client-ID %s' % api_key}
parameters = {'image': image_data, type: 'base64',
'name': filename,
'title': "%s uploaded by yt" % filename}
data = urllib.parse.urlencode(parameters).encode('utf-8')
- req = urllib.request.Request('https://api.imgur.com/3/upload', data=data,
- headers=headers)
+ req = urllib.request.Request(
+ ytcfg.get("yt", "imagebin_upload_url"), data=data, headers=headers)
try:
response = urllib.request.urlopen(req).read().decode()
except urllib.error.HTTPError as e:
@@ -1078,18 +1112,12 @@
return {'uploaded':False}
rv = json.loads(response)
if 'data' in rv and 'link' in rv['data']:
- delete_cmd = (
- "curl -X DELETE -H 'Authorization: Client-ID {secret}'"
- " https://api.imgur.com/3/image/{delete_hash}"
- )
print()
print("Image successfully uploaded! You can find it at:")
print(" %s" % (rv['data']['link']))
print()
print("If you'd like to delete it, use the following")
- print(" %s" %
- delete_cmd.format(secret=api_key,
- delete_hash=rv['data']['deletehash']))
+ print(" yt delete_image %s" % rv['data']['deletehash'])
print()
else:
print()
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160420/be02dac9/attachment-0001.htm>
More information about the yt-svn
mailing list