This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_project.py
71 lines (54 loc) · 1.9 KB
/
new_project.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
import argparse
import requests
import tempfile
import shutil
def process_command_line(argv):
'''Parse the command line and do a first-pass on processing them into a
format appropriate for the rest of the script.'''
parser = argparse.ArgumentParser(formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument(
"--top", required=True,
help="Topology file to submit.")
parser.add_argument(
"--mdp", required=True,
help="MDP file to submit.")
parser.add_argument(
"--gro", required=True,
help="Conformation file to submit.")
parser.add_argument(
"-n", "--project-name", required=True,
help="The name to give the project.")
parser.add_argument(
"--gromppery", required=True,
help="The location (including port) for the gromppery.")
args = parser.parse_args(argv[1:])
assert os.path.isfile(args.top)
assert os.path.isfile(args.gro)
assert os.path.isfile(args.mdp)
return args
def main(argv=None):
args = process_command_line(argv)
with tempfile.TemporaryDirectory() as tmpdirname:
files = {}
for filetype in ['top', 'gro', 'mdp']:
new_filename = os.path.join(
tmpdirname, args.project_name+'.'+filetype)
shutil.copy(
getattr(args, filetype),
new_filename)
files[filetype] = open(new_filename, 'rb')
r = requests.post(
args.gromppery+'/api/tprs/',
files=files,
data={'name': args.project_name})
if r.status_code != 201:
print('Failed to submit project!')
print("Response was code {code} with content {content}.".format(
code=r.status_code, content=r.content))
return 1
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))