def global_logging_raw_input(prompt): def get_stream(name): if hasattr(sys, name): stream = getattr(sys, name) if isinstance(stream, file): return stream elif isinstance(stream, StreamTeeLogger): return stream.stream if hasattr(sys, '__%s__' % name): stream = getattr(sys, '__%s__' % name) if isinstance(stream, file): return stream return None def check_interactive(stream, name): try: fd = stream.fileno() except: # Could be an AttributeError, an OSError, and IOError, or who # knows what else... return False realfd = {'stdin': 0, 'stdout': 1, 'stderr': 2}[name] return fd == realfd and os.isatty(fd) stdout = get_stream('stdout') stdin = get_stream('stdin') stderr = get_stream('stderr') if stdout is None: raise RuntimeError('raw_input(): lost sys.stdout') if stdin is None: raise RuntimeError('raw_input(): lost sys.stdin') if stderr is None: raise RuntimeError('raw_input(): lost sys.stderr') if (not check_interactive(stdin, 'stdin') or not check_interactive(stdout, 'stdout')): # Use the built-in raw_input(); this will repeat some of the checks # we just did, but will save us from having to reimplement # raw_input() in its entirety retval = builtins._original_raw_input(prompt) else: stdout.flush() infd = pythonapi.PyFile_AsFile(stdin) outfd = pythonapi.PyFile_AsFile(stdout) retval = pythonapi.PyOS_Readline(infd, outfd, str(prompt)) retval = retval.rstrip('\n') if isinstance(sys.stdout, StreamTeeLogger): sys.stdout.log_orig(str(prompt) + retval, echo=False) return retval
libmdname = environ["GROMPY_LIBMD"] if environ.has_key("GROMPY_LIBMDRUN"): libmdrunname = environ["GROMPY_LIBMDRUN"] libc = cdll.LoadLibrary(libcname) libmd = cdll.LoadLibrary(libmdname) libgmx = cdll.LoadLibrary(libgmxname) libmdrun = cdll.LoadLibrary(libmdrunname) # gromacs shuold be compiled with -lfftw3f!!! # libmdrun = cdll.LoadLibrary(environ["HOME"]+"/src/gromacs-4.0.5_TEST/src/kernel/libmdrun0/mdrun.so") # for debugging purposes #FILE * to stderr, stdout pythonapi.PyFile_AsFile.restype = c_void_p stderr = pythonapi.PyFile_AsFile(py_object(sys.stderr)) stdout = pythonapi.PyFile_AsFile(py_object(sys.stdout)) rvec = c_real * 3 dvec = c_double * 3 ivec = c_int * 3 splinevec = c_real * 3 matrix = c_real * 3 * 3 tensor = c_real * 3 * 3 class GMXctypesError(Exception): def __init__(self, value): self.value = value def __str__(self):
def copy_file_pointer(self, f): if not isinstance(f, file): raise TypeError("f has to be a file") self.fp = pythonapi.PyFile_AsFile(py_object(f))
def PrintCxxCompilerInfo(f=pythonapi.PyFile_AsFile(sys.stdout)): lib.ElPrintCxxCompilerInfo(f)
def PrintConfig(f=pythonapi.PyFile_AsFile(sys.stdout)): lib.ElPrintConfig(f)
def PrintVersion(f=pythonapi.PyFile_AsFile(sys.stdout)): lib.ElPrintVersion(f)