[yt-svn] commit/yt: 5 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Jul 14 06:51:19 PDT 2017


5 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/76f2a7fba49b/
Changeset:   76f2a7fba49b
User:        xarthisius
Date:        2017-06-28 14:51:32+00:00
Summary:     Port curldrop uploader from dxl-tools
Affected #:  2 files

diff -r b8ae5d5e61686d61d691f33ace5397ffcf7f5c35 -r 76f2a7fba49bdfc3e8b408fbedf19ab05187246c yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -63,6 +63,7 @@
     imagebin_api_key = 'e1977d9195fe39e',
     imagebin_upload_url = 'https://api.imgur.com/3/upload',
     imagebin_delete_url = 'https://api.imgur.com/3/image/{delete_hash}',
+    curldrop_upload_url = 'http://use.yt/upload',
     thread_field_detection = 'False',
     ignore_invalid_unit_operation_errors = 'False',
     chunk_size = '1000',

diff -r b8ae5d5e61686d61d691f33ace5397ffcf7f5c35 -r 76f2a7fba49bdfc3e8b408fbedf19ab05187246c yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -34,6 +34,7 @@
     ensure_dir, \
     ensure_list, \
     get_hg_or_git_version, \
+    get_pbar, \
     get_yt_version, \
     mylog, \
     ensure_dir_exists, \
@@ -152,6 +153,25 @@
     return gc
 
 
+class FileStreamer:
+    final_size = None
+    next_sent = 0
+    chunksize = 16*1024*1024
+
+    def __init__(self, f, final_size = None):
+        location = f.tell()
+        f.seek(0, os.SEEK_END)
+        self.final_size = f.tell() - location
+        f.seek(location)
+        self.f = f
+
+    def __iter__(self):
+        pbar = get_pbar("Uploading file", self.final_size)
+        while self.f.tell() < self.final_size:
+            yield self.f.read(self.chunksize)
+            pbar.update(self.f.tell())
+        pbar.finish()
+
 _subparsers = {None: subparsers}
 _subparsers_description = {
     'config': 'Get and set configuration values for yt',
@@ -1159,6 +1179,32 @@
             pprint.pprint(rv)
 
 
+class YTUploadFileCmd(YTCommand):
+    args = (dict(short="file", type=str),)
+    description = \
+        """
+        Upload a file to yt's curldrop.
+
+        """
+    name = "upload"
+
+    def __call__(self, args):
+        try:
+            import requests
+        except ImportError:
+            print("yt {} requires requests to be installed".format(self.name))
+            print("Please install them using your python package manager, e.g.:")
+            print("   pip install requests --user")
+            sys.exit()
+
+        fs = iter(FileStreamer(open(args.file, 'rb')))
+        upload_url = ytcfg.get("yt", "curldrop_upload_url")
+        r = requests.put(upload_url + "/" + os.path.basename(args.file),
+                         data=fs)
+        print()
+        print(r.text)
+
+
 class YTConfigGetCmd(YTCommand):
     subparser = 'config'
     name = 'get'


https://bitbucket.org/yt_analysis/yt/commits/f4bb879f7483/
Changeset:   f4bb879f7483
User:        xarthisius
Date:        2017-06-28 15:03:57+00:00
Summary:     Add docs
Affected #:  2 files

diff -r 76f2a7fba49bdfc3e8b408fbedf19ab05187246c -r f4bb879f7483a0f8ed4e9186ab1cd564837e4d3c doc/source/help/index.rst
--- a/doc/source/help/index.rst
+++ b/doc/source/help/index.rst
@@ -162,10 +162,11 @@
 these steps:
 
 * Identify what it is that went wrong, and how you knew it went wrong.
-* Put your script, errors, and outputs online:
+* Put your script, errors, inputs and outputs online:
 
   * ``$ yt pastebin script.py`` - pastes script.py online
   * ``$ yt upload_image image.png`` - pastes image online
+  * ``$ yt upload my_input.tar`` - pastes my_input.tar online
 
 * Identify which version of the code you’re using.
 

diff -r 76f2a7fba49bdfc3e8b408fbedf19ab05187246c -r f4bb879f7483a0f8ed4e9186ab1cd564837e4d3c doc/source/reference/command-line.rst
--- a/doc/source/reference/command-line.rst
+++ b/doc/source/reference/command-line.rst
@@ -176,6 +176,20 @@
 
    yt pastebin_grab 1768
 
+upload
+++++++
+
+Upload a file to a public curldrop instance. Curldrop is a simple web
+application that allows you to upload and download files straight from your
+Terminal with an http client like e.g. curl. It was initially developed by
+`Kevin Kennell <https://github.com/kennell/curldrop>`_ and later forked and
+adjusted for yt’s needs. After a successful upload you will receive a url that
+can be used to share the data with other people.
+
+.. code-block:: bash
+
+   yt upload my_file.tar.gz
+
 plot
 ++++
 


https://bitbucket.org/yt_analysis/yt/commits/97d67b5b9ba4/
Changeset:   97d67b5b9ba4
User:        xarthisius
Date:        2017-06-28 15:16:52+00:00
Summary:     Update and refactor error messages for commands that require additional modules
Affected #:  2 files

diff -r f4bb879f7483a0f8ed4e9186ab1cd564837e4d3c -r 97d67b5b9ba4fc02ad3e1a4eee5bda92db340259 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -51,7 +51,7 @@
 from yt.utilities.metadata import get_metadata
 from yt.utilities.configure import set_config
 from yt.utilities.exceptions import \
-    YTOutputNotIdentified, YTFieldNotParseable
+    YTOutputNotIdentified, YTFieldNotParseable, YTCommandRequiresModule
 
 # loading field plugins for backward compatibility, since this module
 # used to do "from yt.mods import *"
@@ -136,10 +136,7 @@
     try:
         import girder_client
     except ImportError:
-        print("this command requires girder_client to be installed")
-        print("Please install them using your python package manager, e.g.:")
-        print("   pip install girder_client --user")
-        sys.exit()
+        raise YTCommandRequiresModule('girder_client')
     if not ytcfg.get("yt", "hub_api_key"):
         print("Before you can access the yt Hub you need an API key")
         print("In order to obtain one, either register by typing:")
@@ -592,10 +589,7 @@
         try:
             import requests
         except ImportError:
-            print("yt {} requires requests to be installed".format(self.name))
-            print("Please install them using your python package manager, e.g.:")
-            print("   pip install requests --user")
-            sys.exit()
+            raise YTCommandRequiresModule('requests')
         if ytcfg.get("yt", "hub_api_key") != "":
             print("You seem to already have an API key for the hub in")
             print("{} . Delete this if you want to force a".format(CURRENT_CONFIG_FILE))
@@ -1192,10 +1186,7 @@
         try:
             import requests
         except ImportError:
-            print("yt {} requires requests to be installed".format(self.name))
-            print("Please install them using your python package manager, e.g.:")
-            print("   pip install requests --user")
-            sys.exit()
+            raise YTCommandRequiresModule('requests')
 
         fs = iter(FileStreamer(open(args.file, 'rb')))
         upload_url = ytcfg.get("yt", "curldrop_upload_url")

diff -r f4bb879f7483a0f8ed4e9186ab1cd564837e4d3c -r 97d67b5b9ba4fc02ad3e1a4eee5bda92db340259 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -699,3 +699,16 @@
             if shape != self.grid_dims:
                 msg += "    Field {} has shape {}.\n".format(name, shape)
         return msg
+
+class YTCommandRequiresModule(YTException):
+    def __init__(self, module):
+        self.module = module
+
+    def __str__(self):
+        msg = "This command requires \"%s\" to be installed.\n\n" % self.module
+        msg += "Please install \"%s\" with the package manager " % self.module
+        msg += "appropriate for your python environment, e.g.:\n"
+        msg += "  conda install %s\n" % self.module
+        msg += "or:\n"
+        msg += "  pip install %s\n" % self.module
+        return msg


https://bitbucket.org/yt_analysis/yt/commits/b87c1f245466/
Changeset:   b87c1f245466
User:        ngoldbaum
Date:        2017-06-29 02:22:42+00:00
Summary:     Decrease chunksize, use tqdm directly
Affected #:  1 file

diff -r 97d67b5b9ba4fc02ad3e1a4eee5bda92db340259 -r b87c1f2454669c8061d31c430119a2905247fec2 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -34,7 +34,6 @@
     ensure_dir, \
     ensure_list, \
     get_hg_or_git_version, \
-    get_pbar, \
     get_yt_version, \
     mylog, \
     ensure_dir_exists, \
@@ -44,6 +43,7 @@
 from yt.extern.six import add_metaclass, string_types
 from yt.extern.six.moves import urllib, input
 from yt.extern.six.moves.urllib.parse import urlparse
+from yt.extern.tqdm import tqdm
 from yt.convenience import load
 from yt.visualization.plot_window import \
     SlicePlot, \
@@ -153,7 +153,7 @@
 class FileStreamer:
     final_size = None
     next_sent = 0
-    chunksize = 16*1024*1024
+    chunksize = 100*1024
 
     def __init__(self, f, final_size = None):
         location = f.tell()
@@ -163,11 +163,11 @@
         self.f = f
 
     def __iter__(self):
-        pbar = get_pbar("Uploading file", self.final_size)
-        while self.f.tell() < self.final_size:
-            yield self.f.read(self.chunksize)
-            pbar.update(self.f.tell())
-        pbar.finish()
+        with tqdm(total=self.final_size, desc='Uploading file',
+                  unit='B', unit_scale=True) as pbar:
+            while self.f.tell() < self.final_size:
+                yield self.f.read(self.chunksize)
+                pbar.update(self.chunksize)
 
 _subparsers = {None: subparsers}
 _subparsers_description = {


https://bitbucket.org/yt_analysis/yt/commits/97d66bcd0222/
Changeset:   97d66bcd0222
User:        ngoldbaum
Date:        2017-07-14 13:50:38+00:00
Summary:     Merge pull request #1471 from Xarthisius/uploader

Add wrapper for curl uploader
Affected #:  5 files

diff -r ec4fad03006330ef2c2591ab717527830d8e4ecf -r 97d66bcd02227747896348ca0cfe764867499370 doc/source/help/index.rst
--- a/doc/source/help/index.rst
+++ b/doc/source/help/index.rst
@@ -162,10 +162,11 @@
 these steps:
 
 * Identify what it is that went wrong, and how you knew it went wrong.
-* Put your script, errors, and outputs online:
+* Put your script, errors, inputs and outputs online:
 
   * ``$ yt pastebin script.py`` - pastes script.py online
   * ``$ yt upload_image image.png`` - pastes image online
+  * ``$ yt upload my_input.tar`` - pastes my_input.tar online
 
 * Identify which version of the code you’re using.
 

diff -r ec4fad03006330ef2c2591ab717527830d8e4ecf -r 97d66bcd02227747896348ca0cfe764867499370 doc/source/reference/command-line.rst
--- a/doc/source/reference/command-line.rst
+++ b/doc/source/reference/command-line.rst
@@ -176,6 +176,20 @@
 
    yt pastebin_grab 1768
 
+upload
+++++++
+
+Upload a file to a public curldrop instance. Curldrop is a simple web
+application that allows you to upload and download files straight from your
+Terminal with an http client like e.g. curl. It was initially developed by
+`Kevin Kennell <https://github.com/kennell/curldrop>`_ and later forked and
+adjusted for yt’s needs. After a successful upload you will receive a url that
+can be used to share the data with other people.
+
+.. code-block:: bash
+
+   yt upload my_file.tar.gz
+
 plot
 ++++
 

diff -r ec4fad03006330ef2c2591ab717527830d8e4ecf -r 97d66bcd02227747896348ca0cfe764867499370 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -63,6 +63,7 @@
     imagebin_api_key = 'e1977d9195fe39e',
     imagebin_upload_url = 'https://api.imgur.com/3/upload',
     imagebin_delete_url = 'https://api.imgur.com/3/image/{delete_hash}',
+    curldrop_upload_url = 'http://use.yt/upload',
     thread_field_detection = 'False',
     ignore_invalid_unit_operation_errors = 'False',
     chunk_size = '1000',

diff -r ec4fad03006330ef2c2591ab717527830d8e4ecf -r 97d66bcd02227747896348ca0cfe764867499370 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -43,6 +43,7 @@
 from yt.extern.six import add_metaclass, string_types
 from yt.extern.six.moves import urllib, input
 from yt.extern.six.moves.urllib.parse import urlparse
+from yt.extern.tqdm import tqdm
 from yt.convenience import load
 from yt.visualization.plot_window import \
     SlicePlot, \
@@ -50,7 +51,7 @@
 from yt.utilities.metadata import get_metadata
 from yt.utilities.configure import set_config
 from yt.utilities.exceptions import \
-    YTOutputNotIdentified, YTFieldNotParseable
+    YTOutputNotIdentified, YTFieldNotParseable, YTCommandRequiresModule
 
 # loading field plugins for backward compatibility, since this module
 # used to do "from yt.mods import *"
@@ -135,10 +136,7 @@
     try:
         import girder_client
     except ImportError:
-        print("this command requires girder_client to be installed")
-        print("Please install them using your python package manager, e.g.:")
-        print("   pip install girder_client --user")
-        sys.exit()
+        raise YTCommandRequiresModule('girder_client')
     if not ytcfg.get("yt", "hub_api_key"):
         print("Before you can access the yt Hub you need an API key")
         print("In order to obtain one, either register by typing:")
@@ -152,6 +150,25 @@
     return gc
 
 
+class FileStreamer:
+    final_size = None
+    next_sent = 0
+    chunksize = 100*1024
+
+    def __init__(self, f, final_size = None):
+        location = f.tell()
+        f.seek(0, os.SEEK_END)
+        self.final_size = f.tell() - location
+        f.seek(location)
+        self.f = f
+
+    def __iter__(self):
+        with tqdm(total=self.final_size, desc='Uploading file',
+                  unit='B', unit_scale=True) as pbar:
+            while self.f.tell() < self.final_size:
+                yield self.f.read(self.chunksize)
+                pbar.update(self.chunksize)
+
 _subparsers = {None: subparsers}
 _subparsers_description = {
     'config': 'Get and set configuration values for yt',
@@ -572,10 +589,7 @@
         try:
             import requests
         except ImportError:
-            print("yt {} requires requests to be installed".format(self.name))
-            print("Please install them using your python package manager, e.g.:")
-            print("   pip install requests --user")
-            sys.exit()
+            raise YTCommandRequiresModule('requests')
         if ytcfg.get("yt", "hub_api_key") != "":
             print("You seem to already have an API key for the hub in")
             print("{} . Delete this if you want to force a".format(CURRENT_CONFIG_FILE))
@@ -1159,6 +1173,29 @@
             pprint.pprint(rv)
 
 
+class YTUploadFileCmd(YTCommand):
+    args = (dict(short="file", type=str),)
+    description = \
+        """
+        Upload a file to yt's curldrop.
+
+        """
+    name = "upload"
+
+    def __call__(self, args):
+        try:
+            import requests
+        except ImportError:
+            raise YTCommandRequiresModule('requests')
+
+        fs = iter(FileStreamer(open(args.file, 'rb')))
+        upload_url = ytcfg.get("yt", "curldrop_upload_url")
+        r = requests.put(upload_url + "/" + os.path.basename(args.file),
+                         data=fs)
+        print()
+        print(r.text)
+
+
 class YTConfigGetCmd(YTCommand):
     subparser = 'config'
     name = 'get'

diff -r ec4fad03006330ef2c2591ab717527830d8e4ecf -r 97d66bcd02227747896348ca0cfe764867499370 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -699,3 +699,16 @@
             if shape != self.grid_dims:
                 msg += "    Field {} has shape {}.\n".format(name, shape)
         return msg
+
+class YTCommandRequiresModule(YTException):
+    def __init__(self, module):
+        self.module = module
+
+    def __str__(self):
+        msg = "This command requires \"%s\" to be installed.\n\n" % self.module
+        msg += "Please install \"%s\" with the package manager " % self.module
+        msg += "appropriate for your python environment, e.g.:\n"
+        msg += "  conda install %s\n" % self.module
+        msg += "or:\n"
+        msg += "  pip install %s\n" % self.module
+        return msg

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.


More information about the yt-svn mailing list