-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
39 lines (33 loc) · 1004 Bytes
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import argparse
import subprocess
import sys
def parse_args():
parser = argparse.ArgumentParser(description='Upload book data to server.')
parser.add_argument('filename', metavar='filename', type=str,
help='The file name of book data.')
parser.add_argument('--host', dest='host', type=str,
help='The name of host to which upload book data.')
args = parser.parse_args()
if not args.host:
print 'host need to be specified.'
parser.print_help()
return None
return args
def main():
args = parse_args()
if not args:
return -1
cmd = ['appcfg.py',
'upload_data',
'--config_file=bulkloader.yaml',
'--filename=' + args.filename,
'--kind=Book',
'--url=http://%s/_ah/remote_api' % args.host]
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
print 'Command failed: ' + ' '.join(cmd)
return -1
return 0
if __name__ == '__main__':
sys.exit(main())