def main(rawArguments): # Project/root directory can be set on a different ways. # On the first place from command line arguments. # # Search directory in array of arguments. # Examined cases: # 1. runapp ~/dir -opts -- -appOpts => ['-opts', '--', '-appOpts'] # 2. runapp -opts ~/dir -- -appOpts => ['-opts', '--', '-appOpts'] # 3. runapp -opts -- ~/dir -appOpts => ['-opts', '--', '~/dir', '-appOpts'] # 4. runapp -opts -- -appOpts ~/dir => ['-opts', '--', '-appOpts', '~/dir'] # 5. runapp -opts ~/dir => ['-opts'] # 6. runapp ... ( without dir ) # 7. runapp -opts ~/dir -appOpts => ['-opts', '--', '-appOpts'] # # Try find first encountered non-option value and split them. # Then will be wrong in case 7 (-appOpts will be joined to -opts ) # sol: Replace found value with end mark char(separator) only then if end mark will not found. # bug: runapp ~/dir -opts => runapp -- -opts !!! # And its index is greater then zero. # e.q runapp -opts ~/dir ... # # to case 1. Default parser recognize it as a the arguments for the external application (all to appArguments) # conclusion is that non-option value will be treated as end mark # val = resolveNonOptionFromList(rawArguments) # If path has been found in command line arguments then initialize it. # If true then overwrite current system env var if val: initConfigurationFile(val[0]) else: # If PROJECT_DIR is set in sys env then apply it. os.chdir(FSUtil.check_path(Config.getProjectDir())) appOptions, appArguments = parseArguments(rawArguments) # Read config should be before cmdl parsing # Allow us to overriding parameters defined in config file # Is useful for testing app, when i wants quick change variable if Config.isJar() == False: readConfig(Config.getConfigFName()) # After loaded configuration, some environment can be changed # synchronize configuration with env. Config.update() initializeCMDLOptions(appOptions) appArguments = Keys.USER_ARGS_TO_APP.fromEnv()+' '+Utils.toString(appArguments) dependency=None jvmArgs = None if Config.isJar() == False: dependency = toCommandLineString(readConfig(Config.getDependencyFName(),"bash-path-parser",False)) if PRINT_DEPENDENCIES_AND_EXIT.fromEnv() : print dependency.replace(":","\n") exitScript(0) jvmArgs = toCommandLineString(readConfig(Config.getJVMArgsFP(),auto_update=False),' ') if not Config.getJavaBinPath(): LOG.error("Java not found, set JAVA_HOME in envirioment variables") exitScript() if Config.isJar() == False: if not Config.getMainClass(): LOG.error("Main class not found. Please set 'MAINCLASS' variable.") exitScript(2) provider = Config.getProvider().lower() execPath = None execArgs = None if provider == "java" or Config.isJar() == True: # Fixed: When path contains white space. C:\\Program Files\... execPath = "\"" + Config.getJavaBinPath() + "\"" if Config.isJar() == False: execArgs = jvmArgs if len(dependency) > 1: execArgs += " -cp "+dependency execArgs += " "+Config.getMainClass()+" "+appArguments else: execArgs = "-jar "+Config.getConfigFName()+" "+appArguments elif provider == "maven": LOG.warn("Maven provider not implenebted yet !") exitScript(0) else: LOG.error("Unrecongnized provider %s !",provider) exitScript(2) globalVariables = env.getExportedVars() LOG.info("%s" % Timer.toString(START_TIME_MS,"Elapsed time of preparing of boot application")) if LOG.isDebug(): LOG.debug("Exec tool: '%s'",Config.getExecTool()) LOG.debug("Exec path: '%s'",execPath) LOG.debug("JVM Parameters: '%s'",jvmArgs) LOG.debug("Main class: '%s'",Config.getMainClass()) LOG.debug("User args: '%s'",appArguments) if LOG.isTrace(): LOG.trace("%s" % commands.getoutput(Config.getJavaBinPath() + " -version") ) LOG.trace("ClassPath: %s" % dependency ) if not Config.isTestingMode(): workingTime = Timer.time() cmd = Utils.toString( (Config.getExecTool(),execPath,execArgs)) process = subprocess.Popen(cmd, shell=True,env=globalVariables) if LOG.isDebug(): LOG.debug("Created new process with PID:%d.",process.pid) signal.signal(signal.SIGINT,trapHandler) process.wait() LOG.info(Timer.toString(workingTime,"Application working time")) if LOG.isDebug(): LOG.debug("The application has finished work ! [exitcode:%d]",process.returncode)
# nbreak set only one time. # no consideration N=0 if method is "insertion": if elapsed_time[0] < elapsed_time[1]: # quick < insertion logger.info("set nbreak={}".format(array.size)) sorter.set_nbreak(array.size) if elapsed_time[0] < elapsed_time[1]: inequality = "<" else: inequality = ">" logger.info("quick={}ms {} insertion={}ms".format( elapsed_time[0], inequality, elapsed_time[1])) # init Timer timer = Timer.getInstance() # logger = Logger.getLogger("DEBUG") logger = Logger.getLogger("INFO") sorter = Sorter.getInstance() # CONSTANTS MAXIMUM_INTEGER = 60000 # limitation integer 0-60000 TOTAL_TIME_IN_SECS = 1 # TOTAL_TIME_IN_SECS = 100 # for experiments # init Array sizes ARR_SIZES = [size for size in range(0, 100, 10)] ARR_SIZES += [size for size in range(100, 1000, 100)] ARR_SIZES += [size for size in range(1000, 5001, 1000)] # generate Array
# Author: Grzegorz (vara) Warywoda # Since: 2010-11-05 22:20:20 CET # import os, sys, commands, time, getopt, optparse, string, signal, subprocess from logger import RALogging from logger.RALogging import RALogger RALogging.initialize() from utils import Utils from utils.Utils import OSUtil, FSUtil, Timer from configuration.Configuration import Config,Keys,env, KeyEntry from configuration.Parser import ParserManger START_TIME_MS = Timer.time() VERSION = "1.0.0" USAGE_FP = os.path.dirname(Config.getScriptRootPath())+os.sep+"usage.txt" #RALogger.setRootDebugLevel() LOG = RALogging.getLogger("runapp") #LOG.setLevel(RALogging.DEBUG) PRINT_DEPENDENCIES_AND_EXIT = KeyEntry("PRINT_DEPENDENCIES_AND_EXIT") Keys.registerKey(PRINT_DEPENDENCIES_AND_EXIT) def exitScript(exitCode=0): wait = env.getEnvInt(Keys.WAIT_ON_EXIT)