From 337768bf6413d90ce3c8bda41ce4d935804b1062 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 31 Jul 2018 18:14:43 -0400 Subject: [PATCH 1/4] ENH+BF: make it possible to export_to_figshare without cd'ing Done by allowing export-archive --filename=directorypath/ so we could point to the directory where the tarball could be located --- datalad/plugin/export_archive.py | 11 ++++++++--- datalad/plugin/export_to_figshare.py | 10 +++++++--- datalad/plugin/tests/test_export_archive.py | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/datalad/plugin/export_archive.py b/datalad/plugin/export_archive.py index 4a7543e1b7..269639a9d4 100644 --- a/datalad/plugin/export_archive.py +++ b/datalad/plugin/export_archive.py @@ -12,7 +12,7 @@ from datalad.interface.base import Interface from datalad.interface.base import build_doc - +from datalad.support import path @build_doc class ExportArchive(Interface): @@ -37,7 +37,9 @@ class ExportArchive(Interface): nargs='?', doc="""File name of the generated TAR archive. If no file name is given the archive will be generated in the current directory and - will be named: datalad_.(tar.*|zip).""", + will be named: datalad_.(tar.*|zip). If an existing + directory provided as filename, such file will be generated under + that directory.""", constraints=EnsureStr() | EnsureNone()), archivetype=Parameter( args=("-t", "--archivetype"), @@ -106,8 +108,11 @@ def _filter_tarinfo(ti): '.' if compression else '', compression) if archivetype == 'tar' else '') + filename_tmpl = "datalad_{.id}".format(dataset) if filename is None: - filename = "datalad_{}".format(dataset.id) + filename = filename_tmpl # in current directory + elif path.exists(filename) and path.isdir(filename): + filename = path.join(filename, filename_tmpl) # under given directory if not filename.endswith(file_extension): filename += file_extension diff --git a/datalad/plugin/export_to_figshare.py b/datalad/plugin/export_to_figshare.py index b2c8792c7a..6ccab3d717 100644 --- a/datalad/plugin/export_to_figshare.py +++ b/datalad/plugin/export_to_figshare.py @@ -165,8 +165,8 @@ class ExportToFigshare(Interface): metavar="PATH", nargs='?', doc="""File name of the generated ZIP archive. If no file name is - given the archive will be generated in the current directory and - will be named: datalad_.zip.""", + given the archive will be generated in the top directory + of the dataset and will be named: datalad_.zip.""", constraints=EnsureStr() | EnsureNone()), no_annex=Parameter( args=("--no-annex",), @@ -230,7 +230,11 @@ def __call__(dataset, filename=None, missing_content='error', no_annex=False, raise RuntimeError( "Paranoid authors of DataLad refuse to proceed in a dirty repository" ) - lgr.info("Exporting current tree as an archive since figshare does not support directories") + lgr.info( + "Exporting current tree as an archive since figshare " + "does not support directories") + if filename is None: + filename = dataset.path archive_out = next( export_archive( dataset, diff --git a/datalad/plugin/tests/test_export_archive.py b/datalad/plugin/tests/test_export_archive.py index ea8811ac13..f5c8d3f05e 100644 --- a/datalad/plugin/tests/test_export_archive.py +++ b/datalad/plugin/tests/test_export_archive.py @@ -110,3 +110,8 @@ def test_zip_archive(path): time.sleep(1.1) ds.export_archive(filename='my', archivetype='zip') assert_equal(md5sum('my.zip'), custom1_md5) + + # should be able to export without us cd'ing to that ds directory + ds.export_archive(filename=ds.path, archivetype='zip') + default_name = 'datalad_{}.zip'.format(ds.id) + assert_true(os.path.exists(os.path.join(ds.path, default_name))) \ No newline at end of file From 0d54343c225b8c1fc270fa3182d4c391b5ef2ce2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 1 Aug 2018 10:15:39 -0400 Subject: [PATCH 2/4] DOC: export_archive: Reword PATH's description [ci skip] --- datalad/plugin/export_archive.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datalad/plugin/export_archive.py b/datalad/plugin/export_archive.py index 269639a9d4..eb09e679e3 100644 --- a/datalad/plugin/export_archive.py +++ b/datalad/plugin/export_archive.py @@ -37,9 +37,9 @@ class ExportArchive(Interface): nargs='?', doc="""File name of the generated TAR archive. If no file name is given the archive will be generated in the current directory and - will be named: datalad_.(tar.*|zip). If an existing - directory provided as filename, such file will be generated under - that directory.""", + will be named: datalad_.(tar.*|zip). To generate that + file in a different directory, provide an existing directory as the + file name.""", constraints=EnsureStr() | EnsureNone()), archivetype=Parameter( args=("-t", "--archivetype"), From ab7fe17e0a9b30eb611f9af86439f30e90ee2d98 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 1 Aug 2018 19:00:01 -0400 Subject: [PATCH 3/4] RF(minor): renamed a variable and added information about destination to log thanks @kyleam for review --- datalad/plugin/export_archive.py | 6 +++--- datalad/plugin/export_to_figshare.py | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/datalad/plugin/export_archive.py b/datalad/plugin/export_archive.py index eb09e679e3..0add289645 100644 --- a/datalad/plugin/export_archive.py +++ b/datalad/plugin/export_archive.py @@ -108,11 +108,11 @@ def _filter_tarinfo(ti): '.' if compression else '', compression) if archivetype == 'tar' else '') - filename_tmpl = "datalad_{.id}".format(dataset) + default_filename = "datalad_{.id}".format(dataset) if filename is None: - filename = filename_tmpl # in current directory + filename = default_filename # in current directory elif path.exists(filename) and path.isdir(filename): - filename = path.join(filename, filename_tmpl) # under given directory + filename = path.join(filename, default_filename) # under given directory if not filename.endswith(file_extension): filename += file_extension diff --git a/datalad/plugin/export_to_figshare.py b/datalad/plugin/export_to_figshare.py index 6ccab3d717..b5976f620a 100644 --- a/datalad/plugin/export_to_figshare.py +++ b/datalad/plugin/export_to_figshare.py @@ -230,11 +230,13 @@ def __call__(dataset, filename=None, missing_content='error', no_annex=False, raise RuntimeError( "Paranoid authors of DataLad refuse to proceed in a dirty repository" ) - lgr.info( - "Exporting current tree as an archive since figshare " - "does not support directories") if filename is None: filename = dataset.path + lgr.info( + "Exporting current tree as an archive under %s since figshare " + "does not support directories", + filename + ) archive_out = next( export_archive( dataset, From 231f6b2a30b4b78b9bee61369ffb11f646d3c45f Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 1 Aug 2018 19:03:28 -0400 Subject: [PATCH 4/4] BF(PY3): list the map! --- datalad/plugin/export_to_figshare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalad/plugin/export_to_figshare.py b/datalad/plugin/export_to_figshare.py index b5976f620a..898380c12a 100644 --- a/datalad/plugin/export_to_figshare.py +++ b/datalad/plugin/export_to_figshare.py @@ -273,7 +273,7 @@ def __call__(dataset, filename=None, missing_content='error', no_annex=False, else: article_id = int(ui.question( "Which of the articles should we upload to.", - choices=map(str, figshare.get_article_ids()) + choices=list(map(str, figshare.get_article_ids())) )) if not article_id: raise ValueError("We need an article to upload to.")