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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a0f55e
commit 7f74b0d
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import shutil | ||
|
||
from django.conf import settings | ||
from django.test import override_settings | ||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
|
||
from tprs.models import Project | ||
from . import new_project as script | ||
|
||
|
||
@override_settings(MEDIA_ROOT=os.path.join(settings.BASE_DIR, 'test-media')) | ||
class ClientTests(StaticLiveServerTestCase): | ||
|
||
def setUp(self): | ||
shutil.copytree( | ||
os.path.join(settings.BASE_DIR, 'testdata'), | ||
os.path.join(settings.MEDIA_ROOT, 'testdata')) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(settings.MEDIA_ROOT) | ||
|
||
def test_run(self): | ||
|
||
PROJ_NAME = 'new-project' | ||
|
||
testdata_dir = os.path.join(settings.BASE_DIR, 'testdata') | ||
|
||
self.assertEqual(Project.objects.filter(name=PROJ_NAME).count(), 0) | ||
|
||
self.assertEquals(0, script.main([ | ||
'new_project.py', | ||
'--project-name', PROJ_NAME, | ||
'--top', os.path.join(testdata_dir, 'plcg_sh2_wt.top'), | ||
'--mdp', os.path.join(testdata_dir, 'plcg_sh2_wt.mdp'), | ||
'--gro', os.path.join(testdata_dir, 'plcg_sh2_wt.gro'), | ||
'--gromppery', self.live_server_url])) | ||
|
||
self.assertEqual(Project.objects.filter(name=PROJ_NAME).count(), 1) | ||
|
||
proj = Project.objects.get(name=PROJ_NAME) | ||
|
||
for filetype in ['top', 'mdp', 'gro']: | ||
self.assertEqual( | ||
os.path.basename(getattr(proj, filetype).name), | ||
'.'.join([PROJ_NAME, filetype])) |