Skip to content
Snippets Groups Projects
Commit 46213f56 authored by Bienchen's avatar Bienchen Committed by BIOPZ-Johner Niklaus
Browse files

Started helper module

parent 13c230ed
No related branches found
No related tags found
No related merge requests found
#!/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
......
set(CORE_RST
index.rst
argcheck.rst
helper.rst
)
add_doc_source(NAME core RST ${CORE_RST})
: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
......@@ -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
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")
......@@ -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)
......
"""
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',
)
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment