├── README.md ├── LICENSE ├── .gitignore └── NeosClient.py /README.md: -------------------------------------------------------------------------------- 1 | # Python XML-RPC client for NEOS Server 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 NEOS-Server 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /NeosClient.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (c) 2017 NEOS-Server 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | Python source code - Python XML-RPC client for NEOS Server 25 | """ 26 | 27 | import argparse 28 | import os 29 | import sys 30 | import time 31 | try: 32 | import xmlrpc.client as xmlrpclib 33 | except ImportError: 34 | import xmlrpclib 35 | 36 | parser = argparse.ArgumentParser() 37 | parser.add_argument("action", help="specify XML file name or queue for action") 38 | parser.add_argument("--server", default="https://neos-server.org:3333", help="URL to NEOS Server XML-RPC interface") 39 | parser.add_argument("--username", default=os.environ.get("NEOS_USERNAME", None), help="username for NEOS Server user account") 40 | parser.add_argument("--password", default=os.environ.get("NEOS_PASSWORD", None), help="password for NEOS Server user account") 41 | args = parser.parse_args() 42 | 43 | neos = xmlrpclib.ServerProxy(args.server) 44 | 45 | alive = neos.ping() 46 | if alive != "NeosServer is alive\n": 47 | sys.stderr.write("Could not make connection to NEOS Server\n") 48 | sys.exit(1) 49 | 50 | if args.action == "queue": 51 | msg = neos.printQueue() 52 | sys.stdout.write(msg) 53 | else: 54 | xml = "" 55 | try: 56 | xmlfile = open(args.action, "r") 57 | buffer = 1 58 | while buffer: 59 | buffer = xmlfile.read() 60 | xml += buffer 61 | xmlfile.close() 62 | except IOError as e: 63 | sys.stderr.write("I/O error(%d): %s\n" % (e.errno, e.strerror)) 64 | sys.exit(1) 65 | if args.username and args.password: 66 | (jobNumber, password) = neos.authenticatedSubmitJob(xml, args.username, args.password) 67 | else: 68 | (jobNumber, password) = neos.submitJob(xml) 69 | sys.stdout.write("Job number = %d\nJob password = %s\n" % (jobNumber, password)) 70 | if jobNumber == 0: 71 | sys.stderr.write("NEOS Server error: %s\n" % password) 72 | sys.exit(1) 73 | else: 74 | offset = 0 75 | status = "" 76 | while status != "Done": 77 | time.sleep(1) 78 | (msg, offset) = neos.getIntermediateResults(jobNumber, password, offset) 79 | sys.stdout.write(msg.data.decode()) 80 | status = neos.getJobStatus(jobNumber, password) 81 | msg = neos.getFinalResults(jobNumber, password) 82 | sys.stdout.write(msg.data.decode()) 83 | 84 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 85 | --------------------------------------------------------------------------------