# -*- coding: iso-8859-1 -*-
# pylint: disable-msg=W0611

# ==============================================================================
# COPYRIGHT (C) 1991 - 2003  EDF R&D                  WWW.CODE-ASTER.ORG
# THIS PROGRAM 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 2 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, WRITE TO EDF R&D CODE_ASTER,
#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
# ==============================================================================

"""This file is not used by astk server.
It's an example of using an ASTER_RUN object as a toolbox.
(see `as_....` modules to check syntax)
"""
__revision__ = "$Id: alamain.py 2566 2006-12-08 10:09:20Z courtois $"


import os
import sys

ASTER_ROOT = '/opt/aster'

# add .../ASTK_SERV/lib in import path
astk_serv_root = os.path.join(ASTER_ROOT, 'ASTK', 'ASTK_SERV')
sys.path.append(os.path.join(astk_serv_root, 'lib'))

#-------------------------------------------------------------------------------
def ini_run(astk_serv_root):
   """initialization of the ASTER_RUN object
   """
   from as_run       import ASTER_RUN
   from as_system    import ASTER_SYSTEM
   from as_timer     import ASTER_TIMER
   
   run        = ASTER_RUN(astk_serv_root)
   run.options['debug']   = False
   run.options['verbose'] = False
   run.options['force']   = False
   run.options['num_job'] = '000000'
   
   run.timer  = ASTER_TIMER()
   run.system = ASTER_SYSTEM(run, maxcmdlen=32768)
   run.print_timer = True
   iret = 0
   
   return run

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if __name__ == '__main__':
   
   VERSION    = 'NEW8'
   REPREF     = os.path.join(ASTER_ROOT, VERSION)
   run = ini_run(astk_serv_root)

   #-------------------------------------------------------------------------------
   # Methods to build Code_Aster
   from as_build     import ASTER_BUILD
   from as_config    import ASTER_CONFIG

   # help(ASTER_BUILD)    prints help on available methods

   fconf = os.path.join(REPREF, 'config.txt')

   conf = ASTER_CONFIG(fconf, run)
   build = ASTER_BUILD(run, conf)

   # Compile all files of a directory
   #build.Compil(typ='C', rep='/opt/aster/NEW8/bibc/supervis', repobj='/tmp/Essai/obj', dbg='nodebug')
   
   # Compile a Code_Aster version
   #build.CompilAster(REPREF, repdest='/tmp/Essai')
   
   # Create a library
   #build.Archive(repobj='/tmp/Essai/obj', lib='/tmp/Essai/mylib.a')
   
   # Build an executable
   #build.Link(exe='/tmp/Essai/aster',
   #           lobj=['/tmp/Essai/mylib.a',],
   #           libaster='/opt/aster/NEW8/lib_obj/libaster.a',
   #           libferm = '/opt/aster/NEW8/lib_obj/libferm.a')

   #-------------------------------------------------------------------------------
   # RunAster function
   import as_exec
   as_exec.SetParser(run)
   # as_exec.RunAster(run, 'my_profile.export')
   
   #-------------------------------------------------------------------------------
   # Utility functions
   import as_maintenance
   as_maintenance.SetParser(run)
   # iret, l_v = as_maintenance.GetVersion(run)
   
   #-------------------------------------------------------------------------------
   # ----- module d'information sur les jobs
   import as_job
   as_job.SetParser(run)
   
   #-------------------------------------------------------------------------------
   # ----- module interface avec le REX
   import as_rex
   as_rex.SetParser(run)
   
   #run.Sortie(iret)
