#!/usr/bin/env python3

#optparse is deprecated in favor of argparse as of Python 2.7. However,
# since 2.7 is not always present on many systems, at this writing,
# it is safer to stick with optparse for now. It should be easy
# to change later, since the syntax is very similar between argparse and optparse.
from optparse import OptionParser

import os
import os.path
import stat
import subprocess
import sys
import re
import shutil


'''
Update_birch.py - Set environment variables for BioLegato Helper Applications

Synopsis: Update_birch.py
  
@modified: April  13, 2020
@author: Brian Fristensky
@contact: frist@cc.umanitoba.ca  
'''

blib = os.environ.get("BIRCHPYLIB")
sys.path.append(blib)

from birchlib import Birchmod


PROGRAM = "Update_birch.py : "
USAGE = "\n\tUSAGE: Update_birch.py"

DEBUG = True
if DEBUG :
    print('Debugging mode on')

BM = Birchmod(PROGRAM, USAGE)


#======================== MAIN PROCEDURE ==========================
def main():
    """
        Called when not in documentation mode.
        """

# Download getbirch.jar
GetbirchURL = "http://home.cc.umanitoba.ca/~psgendb/birchhomedir/FTP/BIRCH/getbirch.jar"
BM.wget(GetbirchURL,"getbirch.jar")

# Run getbirch.jar
# Redirect stderr to stdout	
p = subprocess.Popen(["java", "-jar", "getbirch.jar"],stderr=subprocess.STDOUT)
p.wait()


if (BM.documentor() or "-test" in sys.argv):
    pass
else:
    main()
