示例#1
0
def setupProxy(sitRootPath=None, sitProxyPath=None):
    """
        Convenience-wrapper to create a default proxy directory.

        WARNING: If a proxy already exists, it will be DELETED !

        You may specify the absolute paths for the SIT root- and/or
        proxy directories. If omitted, typical defaults will be used.
    """
    from ToolBOSCore.Storage import ProxyDir
    from ToolBOSCore.Storage import SIT

    if not sitRootPath:
        sitRootPath = SIT.getDefaultRootPath()

    if not sitProxyPath:
        sitProxyPath = SIT.getDefaultProxyPath()

    Any.requireIsTextNonEmpty(sitRootPath)
    Any.requireIsTextNonEmpty(sitProxyPath)
    Any.requireIsDir(sitRootPath)

    # delete existing proxy if it exists, it might be screwed up
    if os.path.exists(sitProxyPath):
        logging.info('cleaning existing proxy in %s' % sitProxyPath)
        FastScript.remove(sitProxyPath)

    logging.info('creating proxy directory... (this may take some time)')
    logging.info('SIT Root:  %s' % sitRootPath)
    logging.info('SIT Proxy: %s' % sitProxyPath)
    ProxyDir.createProxyDir(sitRootPath, sitProxyPath, verbose=False)
if not sourced:
    print("\nPlease run the following command first:")
    print("source /hri/sit/latest/DevelopmentTools/ToolBOSCore/3.3/BashSrc\n")
    sys.exit(-1)

from ToolBOSCore.Settings import ToolBOSSettings
from ToolBOSCore.Settings import UserSetup
from ToolBOSCore.Storage import SIT
from ToolBOSCore.Util import ArgsManagerV2
from ToolBOSCore.Util import FastScript

#----------------------------------------------------------------------------
# Default settings
#----------------------------------------------------------------------------

sitRootPath = SIT.getDefaultRootPath()
sitProxyPath = SIT.getDefaultProxyPath()
shell = FastScript.getEnv('SHELL')
version = ToolBOSSettings.packageVersion
subtitle = '~ Welcome to ToolBOS SDK %s ~' % version

#----------------------------------------------------------------------------
# Commandline parsing
#----------------------------------------------------------------------------

# Replace the username in the sitProxyPath by a generic placeholder so that
# the unittests relying on the consistent output will pass, see TBCORE-1378.

userName = FastScript.getCurrentUserName()
sitProxyPathHelp = sitProxyPath.replace(userName, '<user>')
#----------------------------------------------------------------------------
# Commandline parsing
#----------------------------------------------------------------------------


logging.basicConfig( level=logging.DEBUG )


# TBCORE-1215: consider $SIT as default root path if present (and not a proxy)

sitEnvVar = FastScript.getEnv( 'SIT' )

if sitEnvVar:

    if ProxyDir.isProxyDir( sitEnvVar ):
        sitRootPath  = SIT.getDefaultRootPath()
    else:
        sitRootPath  = sitEnvVar

else:
    sitRootPath = SIT.getDefaultRootPath()


sitProxyPath     = SIT.getDefaultProxyPath()
sitVersion       = SIT.getVersion()


# Replace the username in the sitProxyPath by a generic placeholder so that
# the unittests relying on the consistent output will pass, see TBCORE-1378.
#
# Also replace a particular SIT build identifier.