diff --git a/datalad/plugin/export_archive.py b/datalad/plugin/export_archive.py index 4a7543e1b7..0add289645 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). To generate that + file in a different directory, provide an existing directory as the + file name.""", constraints=EnsureStr() | EnsureNone()), archivetype=Parameter( args=("-t", "--archivetype"), @@ -106,8 +108,11 @@ def _filter_tarinfo(ti): '.' if compression else '', compression) if archivetype == 'tar' else '') + default_filename = "datalad_{.id}".format(dataset) if filename is None: - filename = "datalad_{}".format(dataset.id) + filename = default_filename # in current directory + elif path.exists(filename) and path.isdir(filename): + 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 b2c8792c7a..898380c12a 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,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, @@ -267,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.") 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