[yt-svn] commit/yt: ngoldbaum: Merged in jzuhone/yt (pull request #2471)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Jan 6 11:15:40 PST 2017
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/276ece4b97fb/
Changeset: 276ece4b97fb
Branch: yt
User: ngoldbaum
Date: 2017-01-06 19:15:14+00:00
Summary: Merged in jzuhone/yt (pull request #2471)
Download files from command line using "yt download" and "supp_data_dir" config option
Affected #: 4 files
diff -r 6dc7c9a92d34f3e3319e37ebc1448899742f247a -r 276ece4b97fbac9af28f5b1aebf0a177b2eae954 doc/source/reference/command-line.rst
--- a/doc/source/reference/command-line.rst
+++ b/doc/source/reference/command-line.rst
@@ -276,6 +276,34 @@
$ yt hub start
$ yt hub start /user/xarthisius/Public
+download
+~~~~~~~~
+
+This subcommand downloads a file from http://yt-project.org/data. Using ``yt download``,
+one can download a file to:
+
+* ``"test_data_dir"``: Save the file to the location specified in
+ the ``"test_data_dir"`` configuration entry for test data.
+* ``"supp_data_dir"``: Save the file to the location specified in
+ the ``"supp_data_dir"`` configuration entry for supplemental data.
+* Any valid path to a location on disk, e.g. ``/home/jzuhone/data``.
+
+Examples:
+
+.. code-block:: bash
+
+ $ yt download apec_emissivity_v2.h5 supp_data_dir
+
+.. code-block:: bash
+
+ $ yt download GasSloshing.tar.gz test_data_dir
+
+.. code-block:: bash
+
+ $ yt download ZeldovichPancake.tar.gz /Users/jzuhone/workspace
+
+If the configuration values ``"test_data_dir"`` or ``"supp_data_dir"`` have not
+been set by the user, an error will be thrown.
Config helper
~~~~~~~~~~~~~
diff -r 6dc7c9a92d34f3e3319e37ebc1448899742f247a -r 276ece4b97fbac9af28f5b1aebf0a177b2eae954 doc/source/reference/configuration.rst
--- a/doc/source/reference/configuration.rst
+++ b/doc/source/reference/configuration.rst
@@ -109,6 +109,8 @@
to stdout rather than stderr
* ``skip_dataset_cache`` (default: ``'False'``): If true, automatic caching of datasets
is turned off.
+* ``supp_data_dir`` (default: ``'/does/not/exist'``): The default path certain
+ submodules of yt look in for supplemental data files.
.. _plugin-file:
diff -r 6dc7c9a92d34f3e3319e37ebc1448899742f247a -r 276ece4b97fbac9af28f5b1aebf0a177b2eae954 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -67,6 +67,7 @@
ignore_invalid_unit_operation_errors = 'False',
chunk_size = '1000',
xray_data_dir = '/does/not/exist',
+ supp_data_dir = '/does/not/exist',
default_colormap = 'arbre',
ray_tracing_engine = 'embree',
)
diff -r 6dc7c9a92d34f3e3319e37ebc1448899742f247a -r 276ece4b97fbac9af28f5b1aebf0a177b2eae954 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -36,7 +36,8 @@
mylog, \
ensure_dir_exists, \
update_hg, \
- enable_plugins
+ enable_plugins, \
+ download_file
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
@@ -1310,6 +1311,45 @@
print("Identified %s records output to %s" % (
len(records), args.output))
+class YTDownloadData(YTCommand):
+
+ args = (dict(short="filename", action="store", type=str,
+ help="The name of the file to download"),
+ dict(short="location", action="store", type=str,
+ help="The location in which to place the file, can be "
+ "\"supp_data_dir\", \"test_data_dir\", or any valid "
+ "path on disk. "),
+ dict(longname="--clobber", short="-c",
+ help="Output full contents of parameter file",
+ action="store_true", default=False),
+ )
+ description = \
+ """
+ Download a file from http://yt-project.org/data and save it to a
+ particular location. Files can be saved to the locations provided
+ by the "test_data_dir" or "supp_data_dir" configuration entries, or
+ any valid path to a location on disk.
+ """
+ name = "download"
+
+ def __call__(self, args):
+ data_url = "http://yt-project.org/data/%s" % args.filename
+ if args.location in ["test_data_dir", "supp_data_dir"]:
+ data_dir = ytcfg.get("yt", args.location)
+ if data_dir == "/does/not/exist":
+ raise RuntimeError("'%s' is not configured!" % args.location)
+ else:
+ data_dir = args.location
+ if not os.path.exists(data_dir):
+ print("The directory '%s' does not exist. Creating..." % data_dir)
+ os.mkdir(data_dir)
+ data_file = os.path.join(data_dir, args.filename)
+ if os.path.exists(data_file) and not args.clobber:
+ raise IOError("File '%s' exists and clobber=False!" % data_file)
+ fn = download_file(data_url, data_file)
+ if not os.path.exists(fn):
+ raise IOError("The file '%s' did not download!!" % args.filename)
+
def run_main():
args = parser.parse_args()
# The following is a workaround for a nasty Python 3 bug:
@@ -1320,7 +1360,7 @@
except AttributeError:
parser.print_help()
sys.exit(0)
-
+
args.func(args)
if __name__ == "__main__": run_main()
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