#!/usr/bin/env python
# subm - runs submfg in the background for non-Cygwin Windows or if there is no alias
#
# Author: David Mastronarde
#
# $Id: subm,v 937343107256 2023/02/19 22:44:16 mast $

progname = 'subm'
prefix = 'ERROR: ' + progname + ' - '

# load System Libraries
import sys, os

#
# Setup runtime environment
if os.getenv('IMOD_DIR') != None:
   IMOD_DIR = os.environ['IMOD_DIR']
   if sys.platform == 'cygwin' and sys.version_info[0] > 2:
      IMOD_DIR = IMOD_DIR.replace('\\', '/')
      if IMOD_DIR[1] == ':' and IMOD_DIR[2] == '/':
         IMOD_DIR = '/cygdrive/' + IMOD_DIR[0].lower() + IMOD_DIR[2:]
   sys.path.insert(0, os.path.join(IMOD_DIR, 'pylib'))
   from imodpy import *
   addIMODbinIgnoreSIGHUP()
else:
   sys.stdout.write(prefix + " IMOD_DIR is not defined!\n")
   sys.exit(1)

#
# load IMOD Libraries
from pip import exitError, setExitPrefix
setExitPrefix(prefix)
args = ['submfg']
if 'win32' in sys.platform:
   args = ['submfg.cmd']

if len(sys.argv) > 1:
   args += sys.argv[1:]

bkgdProcess(args, None, 'stdout')
sys.exit(0)
