Create dvc command and make it work. Close #20

This commit is contained in:
Dmitry Petrov
2017-04-11 23:22:37 -07:00
parent a33ea34e8f
commit ab80e3c4a7
4 changed files with 17 additions and 12 deletions
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
PYTHONPATH=$DVC_HOME python $DVC_HOME/dvc2.py $@
+10 -8
View File
@@ -1,4 +1,5 @@
from __future__ import print_function
"""
main entry point / argument parsing for dvc
@@ -7,9 +8,8 @@ NB: for ${REASONS}, cannot be named dvc.py. trust me.
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
@@ -17,7 +17,6 @@ from dvc.command.data_sync import CmdDataSync
from dvc.command.data_import import CmdDataImport
def print_usage():
usage = ('',
'These are common dvc commands:',
@@ -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)
@@ -55,17 +55,19 @@ if __name__ == '__main__':
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'):
@@ -75,6 +77,6 @@ if __name__ == '__main__':
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)
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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