Пример #1
0
def edit_and_check_stl_script(scriptPath):
    "Edit and validate the given script before including in the regression test."
    global issue_number, bug_title, ssuser
    
    bugFileName = os.path.basename(scriptPath)
    SSApi.SetSSUser(ssuser)
    result, output = SSApi.CheckOut(OPEN_BUGS_DIR, SS_OPEN_BUGS_PROJ + bugFileName)
    if result == SSApi.ERROR:
        error_exit("VSS CheckOut Error: " + output + "\nCould not update " + bugFileName)

    # Insert leading echo statements with title and issue number, before allowing user to edit.
    bugFile = open(scriptPath, "r")
    bugFileLines = bugFile.readlines()
    bugFile.close()

    if issue_number == -1:
        issueLine = "echo 'Issue number: <unknown>';\n"
    else:
        issueLine = "echo 'Issue number: " + `issue_number` + "';\n"

    echoTitle = bug_title.replace("'","''").replace("%", "%%")
    titleLine = "echo '" + echoTitle + "';\n"
    if not issueLine in bugFileLines:
        bugFileLines.insert(0, issueLine)
    if not titleLine in bugFileLines:        
        bugFileLines.insert(1, titleLine)

    bugFile = open(scriptPath, "w")
    bugFile.writelines(bugFileLines)
    bugFile.close()

    # Allow the user to edit the script.
    print "Please make any changes you wish to " + bugFileName
    print "Note: If all you get is an invalid certificate trust file error, please"
    print "change the .stl file association to the text editor of your choice."
    print "Save your changes and close your editor to continue..."
    os.system("\"" + scriptPath + "\"")

    # Call the script checker to validate before including in the regression test
    result = script_checker_api.check_test_script(scriptPath)
    while result == script_checker_api.FALSE:
        print "This script may not be ready for inclusion into the regression test."
        s = raw_input("Enter 'y' if you're sure you want it as is, 'n' to quit, or any other key to edit.")
        if s == "n" or s == "N":
            print "Exiting."
            ssResult, output = SSApi.UndoCheckOut(SS_OPEN_BUGS_PROJ + bugFileName)
            if ssResult == SSApi.ERROR:
                error_exit("SSApi error: could not undo checkout of " + SS_OPEN_BUGS_PROJ + bugFileName + ".\n" + output)
            sys.exit(0)
        if s == "y" or s == "Y":
            break
        print "Please make any changes you wish to " + bugFileName
        os.system("\"" + scriptPath + "\"")
        result = script_checker_api.check_test_script(scriptPath)
    else:
        print "Script checked okay."

    result, output = SSApi.CheckIn(SS_OPEN_BUGS_PROJ + bugFileName)
    if result == SSApi.ERROR:
        error_exit("SSApi CheckIn Error: "  + output + "\nCould not update " + bugFileName)

    return result
Пример #2
0
#=================================================================================
#  $Header: /Tools/ScriptChecker/script_checker.py 1     1/15/02 3:52p Tom $
#
#  DESCRIPTION:  This script uses check_test_script which scans an stl file,
#                ensuring that it drops anything that it creates (cleans up after
#                itself) and has --vl_process_upd comments after all statements
#                which might cause a trigger to fire.
#
#  ORIGINAL AUTHOR: Tom Higgins
#=================================================================================

import sys
from Tools.ScriptChecker import script_checker_api

# Get the filename from the user
try:
    bugFile = sys.argv[1]
except:
    bugFile = raw_input("Please enter the path of the stl file you wish to check: ")
    
result = script_checker_api.check_test_script(bugFile)
if result == script_checker_api.TRUE:
    print "Script " + bugFile + " checked okay."
else:
    print "Script check failed for " + bugFile

sys.exit(result)