mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
import: Output as on optional argument (#1351)
* import: Output as on optional argument Close #1335 * Use tempfile to prevent circular dependencies
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
720fda0772
commit
c6b8be8f8a
@@ -176,6 +176,7 @@ def parse_args(argv=None):
|
||||
"`dvc remote` commands). ")
|
||||
import_parser.add_argument(
|
||||
'out',
|
||||
nargs='?',
|
||||
help='Output.')
|
||||
import_parser.set_defaults(func=CmdImport)
|
||||
|
||||
|
||||
+14
-1
@@ -1,3 +1,10 @@
|
||||
import os
|
||||
|
||||
try:
|
||||
from urlparse import urlparse
|
||||
except ImportError:
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.command.base import CmdBase
|
||||
from dvc.logger import Logger
|
||||
@@ -6,7 +13,13 @@ from dvc.logger import Logger
|
||||
class CmdImport(CmdBase):
|
||||
def run(self):
|
||||
try:
|
||||
self.project.imp(self.args.url, self.args.out)
|
||||
default_out = os.path.basename(
|
||||
urlparse(self.args.url).path
|
||||
)
|
||||
|
||||
out = self.args.out or default_out
|
||||
|
||||
self.project.imp(self.args.url, out)
|
||||
except DvcException as ex:
|
||||
Logger.error('Failed to import {}'.format(self.args.url), ex)
|
||||
return 1
|
||||
|
||||
+19
-4
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import stat
|
||||
import shutil
|
||||
import tempfile
|
||||
from uuid import uuid4
|
||||
|
||||
from dvc.main import main
|
||||
from dvc.command.imp import CmdImport
|
||||
@@ -11,14 +13,27 @@ from tests.basic_env import TestDvc
|
||||
|
||||
class TestCmdImport(TestDvc):
|
||||
def test(self):
|
||||
ret = main(['import',
|
||||
self.FOO, 'import'])
|
||||
ret = main(['import', self.FOO, 'import'])
|
||||
self.assertEqual(ret, 0)
|
||||
self.assertTrue(os.path.exists('import.dvc'))
|
||||
|
||||
ret = main(['import',
|
||||
'non-existing-file', 'import'])
|
||||
ret = main(['import', 'non-existing-file', 'import'])
|
||||
self.assertNotEqual(ret, 0)
|
||||
|
||||
def test_unsupported(self):
|
||||
ret = main(['import', 'unsupported://path', 'import_unsupported'])
|
||||
self.assertNotEqual(ret, 0)
|
||||
|
||||
class TestDefaultOutput(TestDvc):
|
||||
def test(self):
|
||||
tmpdir = self.mkdtemp()
|
||||
filename = str(uuid4())
|
||||
tmpfile = os.path.join(tmpdir, filename)
|
||||
|
||||
with open(tmpfile, 'w') as fd:
|
||||
fd.write('content')
|
||||
|
||||
ret = main(['import', tmpfile])
|
||||
self.assertEqual(ret, 0)
|
||||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename).read(), 'content')
|
||||
|
||||
Reference in New Issue
Block a user