NCAR / lrose-core

Core C/C++ code for LROSE.
https://www.eol.ucar.edu/content/lidar-radar-open-software-environment
Other
92 stars 51 forks source link

lrose install Python 3 compatibility for MacOS #46

Closed nguy closed 4 years ago

nguy commented 6 years ago

I recently installed lrose from binaries, specifically lrose-20180430.bin.mac_osx.tgz. I found that the install_bin_release.py worked with Python 2, but not Python 3. I ported this over to allow installation using Python 2 or 3 and thought it might be of interest for others. I'm not sure where this file exists, so I'll paste here for now. If you would like a PR, point me to the directory where this is stored.

#!/usr/bin/env python

#===========================================================================
#
# Install a binary release
# Should be run from within the untarred directory
#
#===========================================================================

from __future__ import print_function
import os
import sys
import shutil
import subprocess
from optparse import OptionParser
import time
from datetime import datetime
from datetime import date
from datetime import timedelta
import glob
from sys import platform

def main():

    # globals

    global thisScriptName
    thisScriptName = os.path.basename(__file__)

    global options
    global runDir
    global installDir
    global dateStr
    global timeStr
    global debugStr
    global releaseName

    global package
    global version
    global srcRelease

    global ostype

    # parse the command line

    usage = "usage: %prog [options]"
    homeDir = os.environ['HOME']
    prefixDefault = '/usr/local/lrose'

    parser = OptionParser(usage)
    parser.add_option('--debug',
                      dest='debug', default=False,
                      action="store_true",
                      help='Set debugging on')
    parser.add_option('--verbose',
                      dest='verbose', default=False,
                      action="store_true",
                      help='Set verbose debugging on')
    parser.add_option('--prefix',
                      dest='prefix', default=prefixDefault,
                      help='Directory for installation')

    (options, args) = parser.parse_args()

    if (options.verbose):
        options.debug = True

    debugStr = " "
    if (options.verbose):
        debugStr = " --verbose "
    elif (options.debug):
        debugStr = " --debug "

    installDir = options.prefix

    # runtime

    now = time.gmtime()
    nowTime = datetime(now.tm_year, now.tm_mon, now.tm_mday,
                       now.tm_hour, now.tm_min, now.tm_sec)
    dateStr = nowTime.strftime("%Y%m%d")
    timeStr = nowTime.strftime("%Y%m%d%H%M%S")
    dateTimeStr = nowTime.strftime("%Y/%m/%d-%H:%M:%S")
    runDir = os.getcwd()

    # read in release info

    readReleaseInfoFile()

    # get the OS type - x86_64, i686, macosx_64

    getOsType()

    # let users know what we are doing

    print("****************************************************\n"
          "  Running %s\n"
          "  Installing %s binary release\n"
          "  OS type: %s\n"
          ""
          "  NCAR, Boulder, CO, USA\n"
          ""
          "  %s\n"
          ""
          "****************************************************\n"
          "  dateStr: %s\n"
          "  runDir: %s\n"
          "  installDir: %s\n"
          "  platform: %s\n"
          "  package: %s\n"
          "  version: %s\n"
          "  srcRelease: %s\n"
          "****************************************************"
          %(thisScriptName, package, ostype, dateTimeStr, dateStr,
            runDir, installDir, platform, package, version, srcRelease),
          file=sys.stderr)

    # create the install dir

    if (os.path.isdir(installDir) == False):
        os.makedirs(installDir)

    # do the install

    if (os.path.isdir("bin")):
        shellCmd("rsync -av bin " + installDir)

    if (os.path.isdir("lib")):
        shellCmd("rsync -av lib " + installDir)

    if (os.path.isdir("include")):
        shellCmd("rsync -av include " + installDir)

    if (os.path.isdir("share")):
        shellCmd("rsync -av share " + installDir)

    #--------------------------------------------------------------------
    # done

    print("  **************************************************")
    print("  *** Done installing binary release ***")
    print("  *** installed in dir: " + installDir + " ***")
    print("  **************************************************")

    sys.exit(0)

########################################################################
# read release information file

def readReleaseInfoFile():

    global package
    global version
    global srcRelease

    package = "unknown"
    version = "unknown"
    srcRelease = "unknown"

    # open info file

    releaseInfoPath = "ReleaseInfo.txt"
    if (options.verbose):
 #       print(("==>> reading info file: %s"% releaseInfoPath), file=sys.stderr)
        print("==>> reading info file: " + releaseInfoPath, file=sys.stderr)

    info = open(releaseInfoPath, 'r')

    # read in lines

    lines = info.readlines()

    # close

    info.close()

    # decode lines

    if (len(lines) < 1):
        print(("ERROR reading info file: %s"% releaseInfoPath), file=sys.stderr)
        print("  No contents", file=sys.stderr)
        sys.exit(1)

    for line in lines:
        line = line.strip()
        toks = line.split(":")
        if (options.verbose):
            print(("  line: %s"% line), file=sys.stderr)
            print(("  toks: %s"% toks), file=sys.stderr)
        if (len(toks) == 2):
            if (toks[0] == "package"):
                package = toks[1]
            if (toks[0] == "version"):
                version = toks[1]
            if (toks[0] == "release"):
                srcRelease = toks[1]

    if (options.verbose):
        print("==>> done reading info file: %s"% releaseInfoPath, file=sys.stderr)

########################################################################
# get the OS type

def getOsType():

    global ostype

    if (platform == "darwin"):
        ostype = "mac_osx"
        return

    ostype = "x86_64"
    tmpFile = os.path.join("/tmp", "ostype." + timeStr + ".txt")

    shellCmd("uname -a > " + tmpFile)
    f = open(tmpFile, 'r')
    lines = f.readlines()
    f.close()

    if (len(lines) < 1):
        print("ERROR getting OS type"
              "  'uname -a' call did not succeed", file=sys.stderr)
        sys.exit(1)

    for line in lines:
        line = line.strip()
        if (options.verbose):
            print("  line: %s"% line, file=sys.stderr)
        if (line.find("x86_64") > 0):
            ostype = "x86_64"
        elif (line.find("i686") > 0):
            ostype = "i686"

########################################################################
# Run a command in a shell, wait for it to complete

def shellCmd(cmd):

    if (options.debug):
        print("running cmd: %s ....."% cmd, file=sys.stderr)

    try:
        retcode = subprocess.check_call(cmd, shell=True)
        if retcode != 0:
            print("Child exited with code: %s"% retcode, file=sys.stderr)
            sys.exit(1)
        else:
            if (options.verbose):
                print("Child returned code: %s"% retcode, file=sys.stderr)
    except OSError as e:
        print("Execution failed: ", e, file=sys.stderr)
        sys.exit(1)

    if (options.debug):
        print(".... done", file=sys.stderr)

########################################################################
# Run - entry point

if __name__ == "__main__":
   main()
mike-dixon commented 4 years ago

All build scripts should now run with both python2 and python3.

niranjanakella commented 4 years ago

Hello, I am currently running windows can you please tell me how can i use the lrose titan on it.

mike-dixon commented 4 years ago

Hi We are working on testing out LROSE on the Windows Linux sub-system, but so far we have not succeeded in getting it to install and run. Mike

On Sun, Jul 12, 2020 at 6:43 AM niranjanstudy06 notifications@github.com wrote:

Hello, I am currently running windows can you please tell me how can i use the lrose titan on it.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/NCAR/lrose-core/issues/46#issuecomment-657216977, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTOD7YHGNWQ24JSANGN3WTR3GVXFANCNFSM4E7QOC6Q .