[yt-svn] commit/yt: 6 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Apr 20 11:13:19 PDT 2016
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/c3614f50759e/
Changeset: c3614f50759e
Branch: yt
User: xarthisius
Date: 2016-04-07 16:52:44+00:00
Summary: Add a 'delete_image' subcommand for a convenient image deletion from imagebin
Affected #: 1 file
diff -r d5af145f1ac7993c2f94c2a4cc0d75824d019f98 -r c3614f50759e13a85d56d38aefe280e667b703aa yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1061,6 +1061,37 @@
print("updating to the newest changeset.")
print()
+class YTDeleteImageCmd(YTCommand):
+ args = (dict(short="delete_hash", type=str),)
+ description = \
+ """
+ Delete image from imgur.com.
+
+ """
+ name = "delete_image"
+ def __call__(self, args):
+ delete_hash = args.delete_hash
+ api_key = 'e1977d9195fe39e'
+ headers = {'Authorization': 'Client-ID %s' % api_key}
+ delete_url = 'https://api.imgur.com/3/image/{delete_hash}'
+ req = urllib.request.Request(
+ delete_url.format(delete_hash=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()
+
+
class YTUploadImageCmd(YTCommand):
args = (dict(short="file", type=str),)
description = \
@@ -1090,18 +1121,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()
https://bitbucket.org/yt_analysis/yt/commits/eb46a94c88fe/
Changeset: eb46a94c88fe
Branch: yt
User: xarthisius
Date: 2016-04-07 17:07:09+00:00
Summary: Move api_key and urls for image upload/delete to config. This will allow to switch to mediagoblin by editing defaults in the future
Affected #: 2 files
diff -r c3614f50759e13a85d56d38aefe280e667b703aa -r eb46a94c88fec68657953471e4e5d936a76d153a 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 c3614f50759e13a85d56d38aefe280e667b703aa -r eb46a94c88fec68657953471e4e5d936a76d153a yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1061,6 +1061,7 @@
print("updating to the newest changeset.")
print()
+
class YTDeleteImageCmd(YTCommand):
args = (dict(short="delete_hash", type=str),)
description = \
@@ -1070,12 +1071,12 @@
"""
name = "delete_image"
def __call__(self, args):
- delete_hash = args.delete_hash
- api_key = 'e1977d9195fe39e'
- headers = {'Authorization': 'Client-ID %s' % api_key}
- delete_url = 'https://api.imgur.com/3/image/{delete_hash}'
+ 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=delete_hash),
+ delete_url.format(delete_hash=args.delete_hash),
headers=headers, method='DELETE')
try:
response = urllib.request.urlopen(req).read().decode()
@@ -1105,15 +1106,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:
https://bitbucket.org/yt_analysis/yt/commits/ab7d9c5b177a/
Changeset: ab7d9c5b177a
Branch: yt
User: xarthisius
Date: 2016-04-07 19:09:38+00:00
Summary: Add server response
Affected #: 1 file
diff -r eb46a94c88fec68657953471e4e5d936a76d153a -r ab7d9c5b177a14368284b69fddc13f7177f99b69 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1091,6 +1091,7 @@
print()
print("Something has gone wrong! Here is the server response:")
print()
+ pprint.pprint(rv)
class YTUploadImageCmd(YTCommand):
https://bitbucket.org/yt_analysis/yt/commits/9988be109243/
Changeset: 9988be109243
Branch: yt
User: xarthisius
Date: 2016-04-07 19:24:01+00:00
Summary: update docs
Affected #: 1 file
diff -r ab7d9c5b177a14368284b69fddc13f7177f99b69 -r 9988be109243a794185e23c699048766f7608d51 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,9 @@
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/>`_.
https://bitbucket.org/yt_analysis/yt/commits/ac856c691d6e/
Changeset: ac856c691d6e
Branch: yt
User: xarthisius
Date: 2016-04-07 19:27:13+00:00
Summary: Fix sphinx syntax
Affected #: 1 file
diff -r 9988be109243a794185e23c699048766f7608d51 -r ac856c691d6e47e589340e3421d1ba84e5bcd49c doc/source/reference/command-line.rst
--- a/doc/source/reference/command-line.rst
+++ b/doc/source/reference/command-line.rst
@@ -268,6 +268,7 @@
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/>`_.
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/93bd29b7/attachment-0001.htm>
More information about the yt-svn
mailing list