diff --git a/actions/pm-build-rawmodel b/actions/pm-build-rawmodel index aed752bc1d236b559327676a108933ffd933e55b..29486cf6478dca87982adf01363813d5a8e48dd8 100755 --- a/actions/pm-build-rawmodel +++ b/actions/pm-build-rawmodel @@ -1,8 +1,8 @@ #!/usr/bin/env ost -import argparse +import os, argparse from promod3 import meld -from promod3.core import argcheck +from promod3.core import argcheck, helper ### CHANGELOG - START # 2013-11-07 - created @@ -13,6 +13,7 @@ from promod3.core import argcheck # 2 - template structure file has unsupported file extension # 3 - alignment file does not exist # 4 - alignment file has unsupported file extension +# 5 - failed to write results to file ### EXIT STATUS - END ### SETUP - START @@ -69,6 +70,8 @@ aln = io.LoadAlignment(opts.alignment_file) aln.AttachView(1, tpl.CreateFullView()) result = meld.BuildRawModel(aln) io.SavePDB(result.model, opts.model_file) +if not os.path.isfile(opts.model_file): + helper.MsgErrorAndExit("Failed to write model file '%s'." % opts.model_file, 5) ### MAIN - END diff --git a/core/doc/CMakeLists.txt b/core/doc/CMakeLists.txt index 9e2491f7391d3d314e532871bb3a73cb71002a69..9097ded5ff93bfbb08f439827b0a83a10965d0c1 100644 --- a/core/doc/CMakeLists.txt +++ b/core/doc/CMakeLists.txt @@ -1,6 +1,7 @@ set(CORE_RST index.rst argcheck.rst +helper.rst ) add_doc_source(NAME core RST ${CORE_RST}) diff --git a/core/doc/helper.rst b/core/doc/helper.rst new file mode 100644 index 0000000000000000000000000000000000000000..c790f0ab5a8f3c4465f858bcbbd89c5264035444 --- /dev/null +++ b/core/doc/helper.rst @@ -0,0 +1,36 @@ +:mod:`~promod3.core.helper` - Shared functionality for the everything +================================================================================ + +.. currentmodule:: promod3.core.helper + +Introduction +-------------------------------------------------------------------------------- + +We collect functions here, which should be useful in many places but would make +rather empty modules left alone. + + +Messages +-------------------------------------------------------------------------------- + +.. testcode:: helper + :hide: + + from promod3.core import helper + + try: + helper.MsgErrorAndExit("Something failed!", 1) + except SystemExit, e: + if e.code == 1: + pass + else: + raise + +.. doctest:: helper + + from promod3.core import helper + + helper.MsgErrorAndExit("Something failed!", 1) + +.. autofunction:: MsgErrorAndExit + diff --git a/core/doc/index.rst b/core/doc/index.rst index 4ec3a4454ab9ecafa019186d2b6f9a3b665b206e..896ac2e6f2b5724b846046ef6adab708133c0383 100644 --- a/core/doc/index.rst +++ b/core/doc/index.rst @@ -4,11 +4,14 @@ .. module:: promod3.core :synopsis: Basic functionality, supporting standard tasks in your code. -This module gathers functions and classes which are not devoted to homology modeling per se but cover standard programming issues. +This module gathers functions and classes which are not devoted to homology +modeling per se but cover standard programming issues. .. toctree:: :maxdepth: 2 argcheck + helper + .. LocalWords: promod se toctree maxdepth argcheck diff --git a/core/pymod/CMakeLists.txt b/core/pymod/CMakeLists.txt index d1400c33f2e41e8b66c05660e5aadfd3b052f65b..8a6a110f4078a3bda0e810f4c19f02fb795f9fa3 100644 --- a/core/pymod/CMakeLists.txt +++ b/core/pymod/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PROMOD3_CORE_FILES __init__.py argcheck.py) +set(PROMOD3_CORE_FILES __init__.py argcheck.py helper.py) pymod(NAME core PY ${PROMOD3_CORE_FILES} IN_DIR core __init__.py OUTPUT_DIR "promod3") diff --git a/core/pymod/core/argcheck.py b/core/pymod/core/argcheck.py index 86cff3c7e39f6f4cb79065ba96760b562f4fcd62..8907d4134bc9c1b17ffec98344c49b1eb2e859d2 100644 --- a/core/pymod/core/argcheck.py +++ b/core/pymod/core/argcheck.py @@ -4,10 +4,7 @@ Basic helpers for arguments. import os, sys import ost - -def _MsgErrorAndExit(msg, exit_status): - ost.LogError(msg) - sys.exit(exit_status) +import helper def FileExists(prefix, exit_status, file): ''' @@ -29,7 +26,7 @@ def FileExists(prefix, exit_status, file): missing. ''' if not os.path.exists(file): - _MsgErrorAndExit('%s file does not exist: %s\n' % (prefix, file), + helper.MsgErrorAndExit('%s file does not exist: %s\n' % (prefix, file), exit_status) def FileExtension(prefix, exit_status, file, extensions, gz=False): @@ -74,14 +71,16 @@ def FileExtension(prefix, exit_status, file, extensions, gz=False): filename, fileext = os.path.splitext(filename) if not gz: extension_string = ', '.join(extensions) - _MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, file)+ + helper.MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, + file)+ 'Allowed extensions are: %s\n' % extension_string, exit_status) if fileext == '': extension_string = ', '.join(extensions) if gz: extension_string += ', ' + '.gz, '.join(extensions) + '.gz' - _MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, file)+ + helper.MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, + file)+ 'Allowed extensions are: %s\n' % extension_string, exit_status) fileext = fileext[1:].lower() @@ -94,7 +93,8 @@ def FileExtension(prefix, exit_status, file, extensions, gz=False): extension_string = ', '.join(extensions) if gz: extension_string += ', ' + '.gz, '.join(extensions) + '.gz' - _MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, file)+ + helper.MsgErrorAndExit('%s file extension not supported: %s. ' % (prefix, + file)+ 'Allowed extensions are: %s\n' % extension_string, exit_status) diff --git a/core/pymod/core/helper.py b/core/pymod/core/helper.py new file mode 100644 index 0000000000000000000000000000000000000000..7f5871d5b6432502d94d48abac8658dc8fbfa873 --- /dev/null +++ b/core/pymod/core/helper.py @@ -0,0 +1,27 @@ +""" +Uncategorised functions which may come handy at several places. +""" + +import sys +import ost + +def MsgErrorAndExit(msg, exit_status): + ''' + Send a messages to the |ost_s| :ost_docs:`error log <base/logging/>` and exit + the Python interpreter. + + :param msg: The message. + :type msg: :class:`str` + + :param exit_status: Exit code, ends up in ``$?`` in the shell. ``0`` is + traditionally reserved to successful commands. + :type exit_status: :class:`int` + + :returns: No return value, exits script with value ``exit_status``. + ''' + ost.LogError(msg) + sys.exit(exit_status) + +__all__ = ( + 'MsgErrorAndExit', +) diff --git a/doc/conf.py.in b/doc/conf.py.in index 79fcf5ce42cb4264bda10c693fa8ddb46bbb7859..1cc6b9e8be37f81e1c1a964d2304cc44881b9efa 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -29,7 +29,11 @@ sys.path.insert(1, '@OST_ROOT@/@LIB_DIR@/python@PYTHON_VERSION@/site-packages') # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', 'sphinx.ext.extlinks'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', 'sphinx.ext.todo', + 'sphinx.ext.coverage', 'sphinx.ext.pngmath', + 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', + 'sphinx.ext.extlinks'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -252,7 +256,9 @@ intersphinx_mapping = {'python': ('@PYTHON_DOC_URL@', None), # -- ProMod3 specific configuration -------------------------------------------- extlinks = {'py_docs' : ('@PYTHON_DOC_URL@/%s', - 'Python documentation')} + 'Python documentation'), + 'ost_docs' : ('@OST_DOC_URL@/%s', + 'OpenStructure documentation')} # The _nameattr is a bit ugly: we want to have __name__ formatted as Python # attribute but Sphinx does not go with calling :attr: inside extlinks. To keep # the Python url prefix, we define sth here.