Source code for CDTK.an_runall

#*  **************************************************************************
#*
#*  CDTK, Chemical Dynamics Toolkit
#*  A modular system for chemical dynamics applications and more
#*
#*  Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016
#*  Oriol Vendrell, DESY, <oriol.vendrell@desy.de>
#*
#*  Copyright (C) 2017, 2018, 2019
#*  Ralph Welsch, DESY, <ralph.welsch@desy.de>
#*
#*  Copyright (C) 2020, 2021, 2022, 2023
#*  Ludger Inhester, DESY, ludger.inhester@cfel.de
#*
#*  This file is part of CDTK.
#*
#*  CDTK is free software: you can redistribute it and/or modify
#*  it under the terms of the GNU General Public License as published by
#*  the Free Software Foundation, either version 3 of the License, or
#*  (at your option) any later version.
#*
#*  This program is distributed in the hope that it will be useful,
#*  but WITHOUT ANY WARRANTY; without even the implied warranty of
#*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#*  GNU General Public License for more details.
#*
#*  You should have received a copy of the GNU General Public License
#*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#*
#*  **************************************************************************

import os
import os.path
import sys
from optparse import OptionParser

import CDTK.Tools.Utils as uti

[docs] def start(): """ Wrapper for starting the program. Needed for good unit test coding. """ # -------------------------------------------------------------------------- # Parse command line options # -------------------------------------------------------------------------- parser=OptionParser() parser.add_option('-c','--command', dest='command', type='str', default=None, help='Command line to be executed in all trj_xxx directories') opts, args = parser.parse_args(sys.argv[1:]) if not sys.argv[1:]: # called without any option parser.print_help() sys.exit(0) # -------------------------------------------------------------------------- # Obtain list of trj directories # -------------------------------------------------------------------------- dirs = uti.getDirectoryList() # -------------------------------------------------------------------------- # Loop over directories and execute command # -------------------------------------------------------------------------- basedir = os.path.abspath(os.path.curdir) for d in dirs: os.chdir(d) try: os.system(opts.command) except: continue os.chdir(basedir)
if __name__ == "__main__": start()