def sendemail(logfile,message):
    filesystemutils.logprint(logfile, 'sendemail', 'message to be sent: '+message, SCRIPTNAME)
    sendemail = u'{}/SquishTests/lib/sendEmail-v156/sendEmail.exe'.format(config.Root)
    arguments = [u'-t aav/qualitätssicherung', '-s outlook.wkd.wolterskluwer.de',\
     '-xu [email protected]',\
     '-xp Qualität2015!',
     '-a {}'.format(message)]
    subprocess.call([sendemail,arguments])
def runTests(args):
    fname = 'runTests'
    global SQUISHINSTALLATION, SCRIPTNAME
    print('starting '+fname)
    print('args.format: ' + args.format )

    Major = args.Major # 21 # os.environ['Major']  # args.major
    Release = args.Release # os.environ['Release'] #
    revision = args.revision # os.environ['Revision'] # 

    if args.environment:
        if os.path.exists(os.getenv('SQUISH_PACKAGE')):
            SQUISHINSTALLATION = os.getenv('SQUISH_PACKAGE')
        else:
            print(SCRIPTNAME + ': -e given as option, but SQUISH_PACKAGE is not set in the environment!')

    # first we bring the 'local' up to date if so desired
    if args.update:
        print('first we start an update of the "local"!')
        # synchronous call
        subprocess.call(['python', '/local/Stp/{}/Scripts/localupdate.py'.format(Major)])
        #g.callBAT(['C:/local/Stp/21/Scripts/localUpdate.bat'])
        #exit

        # testSet = tinyTest

    #print('testbatch args.testset: ' + str(args.testset))
    # if args.testset == 'allTests':
    #    testSet=allTests
    #testSet = testsets.allTests
    #if args.testset == 'tinyTest':
    #    testSet = testsets.tinyTest
    #if args.testset == 'dataTest':
    #    testSet = testsets.dataTest
    #if args.testset == 'iconBarTest':
    #    testSet = testsets.iconBarTest

    # testSet = args.testset
    testSet = testsets.allTests

    print(SCRIPTNAME+': '+fname+' testsSet: '+ str(testSet))
    # testSet = testsets.iconBarTest

    testSuite = args.testsuite
    # ---- argument handling >  

    # here we set the home directory of the test suite
    if sys.platform.startswith('win'): # Windows
        HOME = config.Root+'/SquishTests/' #'M:/Test/squish' # Python understands Unix paths even on Windows
    elif sys.platform.startswith('darwin'): # Mac OS X
        HOME = '/Users/squish'
    else: # Other Unix-like, e.g. Linux
        HOME = '/home/squish'

    if args.debug:
        print(SCRIPTNAME+': '+fname+': HOME: ', HOME)
        #print(SCRIPTNAME+': '+fname+': SQUISHINSTALLATION: ', SQUISHINSTALLATION)
        print(SCRIPTNAME+': '+fname+': testSet: ', str(testSet)) 
        print(SCRIPTNAME+': '+fname+': '+'argsformat: '+args.format)

    if SQUISHINSTALLATION not in sys.path:
        sys.path.append(SQUISHINSTALLATION)

    # start the squishserver (and don't wait)
    if sys.platform.startswith('win'):
        squishserver = SQUISHINSTALLATION+ '/squishserver.exe'
        squishrunner = SQUISHINSTALLATION+ '/squishrunner.exe'
        # if args.verbose or args.debug: 
        print( SCRIPTNAME+': '+fname+': '+'squish server path: ' + squishserver)
        print( SCRIPTNAME+': '+fname+': '+'squish runner path: ' + squishrunner)
        os.environ['SQUISH_SCRIPT_DIR']='{}/SquishTests/Global/shared; '.format(config.Root)\
                                      + '{}/SquishTests/Global/shared/SSE-Scripts; '.format(config.Root)\
                                      + '{}/SquishTests/Global/shared/HL-Scripts; '.format(config.Root)\
                                      + '{}/SquishTests/Global/shared/QS-Scripts; '.format(config.Root)\
                                      + '{}/SquishTests/Global/shared/TM-Scripts; '.format(config.Root)

        pid = subprocess.Popen([squishserver]).pid
    else:
        pid = subprocess.Popen([squishserver]).pid

    print(SCRIPTNAME+': '+fname+': starting squishrunner with test suite ' + testSuite)
    # execute the test (and wait for it to finish)
    argsdebugargs = ''
    if args.debug:
        argsdebugargs = 'apw'

    # available test sets: allTests, tinyTest, dataTest
    # if args.debug:
    print(SCRIPTNAME+': '+fname+': testSet: ', str(testSet) )

    testlog = '----------\n'
    # now we iterate over the list of tests and call each one individually
    print(os.getcwd())
    for testname in testSet:
        print(SCRIPTNAME+': '+fname+': '+'testname: '+testname)
        testlog = testlog + str(runTest(squishrunner, args.Machinename, testSuite, testname, argsdebugargs, args.format, args.sendemail, 
                                        HOME, Major, Release, revision, args.log, args.version))
    print(SCRIPTNAME+' ----------------testlog: \n'+testlog)
    print(SCRIPTNAME+' ----------------testlog')
    #input()

    logfile = filesystemutils.createLogFile(str(args.Product).strip(), str(args.Machinename).strip(),'Squish')
    filesystemutils.logprint(logfile, 'main', testlog, SCRIPTNAME)

    print(SCRIPTNAME+': '+fname+': '+' stopping squish server')
    # stop the squishserver
    try:
        subprocess.call([squishserver, ' --stop'])
    except:
        print(SCRIPTNAME+': '+fname+': '+' failed to stop squish server')

    # first we kill spawned processes that might block access to the generated files
    if args.cleanup:
        subprocess.call(['python', 'killSpawnedProcesses.py'])

    # then we archive the generated files to a time-stamped directory
    indir = os.path.join(os.path.expanduser('~'),'Documents/Steuerfälle')
    outdir = '/temp/squishresults'+str(datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))

    '''
    try: 
        os.mkdir(outdir)
    except:
        pass
    '''
    shutil.copytree(indir,outdir)

    # and finally we remove the generated files, so that we have a clean slate
    # for the next run and we won't get any confirmation dialogs for overwriting files
    if args.cleanup:
        subprocess.call(['python', 'deleteGeneratedFiles.py'])

    if testlog == None:
        testlog = 'No testlog generated'
    return testlog