Skip to content

Commit

Permalink
Create dvc command and make it work. Close iterative#20
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpetrov committed Apr 12, 2017
1 parent a33ea34 commit ab80e3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions bin/dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

PYTHONPATH=$DVC_HOME python $DVC_HOME/dvc2.py $@
18 changes: 10 additions & 8 deletions dvc2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function

"""
main entry point / argument parsing for dvc
Expand All @@ -7,17 +8,15 @@

import sys

from dvc import *
from dvc.runtime import Runtime
from dvc.command.data_import import CmdDataImport
from dvc.command.init import CmdInit
from dvc.command.remove import CmdDataRemove
from dvc.command.run import CmdRun
from dvc.command.repro import CmdRepro
from dvc.command.data_sync import CmdDataSync
from dvc.command.data_import import CmdDataImport



def print_usage():
usage = ('',
'These are common dvc commands:',
Expand All @@ -35,13 +34,14 @@ def print_usage():
print('\n'.join(usage))

if __name__ == '__main__':
cmds = ['init', 'run', 'sync', 'data', 'data-sync', 'data-remove', 'data-import', 'cloud', \
cmds = ['init', 'run', 'sync', 'repro', 'data', 'data-sync', 'data-remove', 'data-import', 'cloud', \
'cloud', 'cloud-run', 'cloud-instance-create', 'cloud-instance-remove', 'cloud-instance-describe']
cmds_expand = {'data': ['sync', 'remove', 'import'],
'cloud': ['run', 'instance-create', 'instance-remove', 'instance-describe']
}

if len(sys.argv) < 2 or sys.argv[1] not in cmds:
print('Unimplemented or unrecognized command. ' + ' '.join(sys.argv[1]))
print_usage()
sys.exit(-1)

Expand All @@ -55,17 +55,19 @@ def print_usage():
else:
subcmd = sys.argv[2]

argv_offset = 1 + (0 if subcmd == None else 1)
argv_offset = 2 + (0 if subcmd == None else 1)
if cmd == 'init':
Runtime.run(CmdRun, args_start_loc=2)
Runtime.run(CmdInit, parse_config=False, args_start_loc=2)
elif cmd == 'run':
Runtime.run(CmdDataImport, args_start_loc=2)
Runtime.run(CmdRun, args_start_loc=2)
elif cmd == 'repro':
Runtime.run(CmdRepro, args_start_loc=2)
elif cmd == 'data-sync' or (cmd == 'data' and subcmd == 'sync'):
Runtime.run(CmdDataSync, args_start_loc=argv_offset)
elif cmd == 'data-import' or (cmd == 'data' and subcmd == 'import'):
Runtime.run(CmdDataImport, args_start_loc=argv_offset)
elif cmd == 'data-remove' or (cmd == 'data' and subcmd == 'remove'):
Runtime.run(CmdDataRemove, args_start_loc=argv_offset)
elif cmd == 'cloud-run' or (cmd == 'cloud' and subcmd == 'run'):
print('cloud-run unimplemented')
elif cmd == 'cloud-instance-create' or (cmd == 'cloud' and subcmd == 'instance-create'):
Expand All @@ -75,6 +77,6 @@ def print_usage():
elif cmd == 'cloud-instance-describe' or (cmd == 'cloud' and subcmd == 'instance-describe'):
print('cloud-instance-describe unimplemented')
else:
print('Unimplemented or unrecognized command. sorry!')
print('Unimplemented or unrecognized command. ' + ' '.join(sys.argv[1]))
print_usage()
sys.exit(-1)
4 changes: 2 additions & 2 deletions functest/common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function dvc_info() {
function _init_repo() {
dvc_info 'init reporitory'
git init
dvc-init
dvc init

dvc_info 'import xml files'
mkdir data/xml
dvc-data-import ../$RAW_DATA_LOCAL/* data/xml
dvc data-import ../$RAW_DATA_LOCAL/* data/xml

dvc_info 'copy code'
mkdir code
Expand Down
4 changes: 2 additions & 2 deletions functest/test-repro-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ function run_test() {
mkdir data/tsv

dvc_info 'convert Budget.xml to tsv'
dvc-run --code code/xmltotsv.py python code/xmltotsv.py --extract row/@Id,row/@UserId,row/@Name,row/@Class,row/@TagBased,row/@Date data/xml/Badges.xml data/tsv/Badges.tsv
dvc run --code code/xmltotsv.py python code/xmltotsv.py --extract row/@Id,row/@UserId,row/@Name,row/@Class,row/@TagBased,row/@Date data/xml/Badges.xml data/tsv/Badges.tsv

dvc_info 'modify code'
echo " " >> code/xmltotsv.py
git commit -am 'Change code'

dvc_info 'reproduce tsv convertion code'
dvc-repro data/tsv/Badges.tsv
dvc repro data/tsv/Badges.tsv
}

create_repo
Expand Down

0 comments on commit ab80e3c

Please sign in to comment.