Ejemplo n.º 1
0
def RotateDirectories(dir):
    """Removes all but the 3 newest subdirectories from the given directory;
    assumes the directories are named with timestamps (numbers) because it 
    uses normal sorting to determine the order."""

    dirs = os.listdir(dir)
    for anyDir in dirs:
        if not os.path.isdir(os.path.join(dir, anyDir)):
            dirs.remove(anyDir)

    dirs.sort()
    for subdir in dirs[:-3]:
        subdir = os.path.join(dir, subdir)
        if os.path.isdir(subdir):
            hardhatutil.rmdirRecursive(subdir)
Ejemplo n.º 2
0
        sys.exit(1)

    # if tagID is present then we have to modify reposBase as a tag has
    # been requested instead of the trunk
    if tagID:
        reposBase = 'tags/%s' % tagID
    else:
        reposBase = 'trunk'

    # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)
    chanDir = os.path.join(workingDir, mainModule)
    # test if we've been thruough the loop at least once
    if clobber == 1:
        if os.path.exists(chanDir):
            hardhatutil.rmdirRecursive(chanDir)

    os.chdir(workingDir)

    # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")
    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)
    os.mkdir(outputDir)

    buildVersionEscaped = "\'" + buildVersion + "\'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")

    if not os.path.exists(chanDir):
        # Initialize sources
        print "Setup source tree..."
Ejemplo n.º 3
0
        print "Could not initialize hardhat environment.  Exiting."
        print "Exception:", e
        import traceback
        traceback.print_exc()
        sys.exit(1)
    
      # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)
    chanDir    = os.path.join(workingDir, 'chandler')
    
      # test if we've been through the loop at least once
    if clobber:
        for module in reposModules:
            modDir = os.path.join(workingDir, module)
            if os.path.exists(modDir):
                hardhatutil.rmdirRecursive(modDir)
            
    os.chdir(workingDir)

      # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")
    
    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)
    
    os.mkdir(outputDir)
    
    buildVersionEscaped = "\'" + buildVersion + "\'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")
    
    if not os.path.exists(chanDir):
Ejemplo n.º 4
0
def Start(hardhatScript, workingDir, buildVersion, clobber, log, skipTests=False, upload=False):

    # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)

    os.chdir(workingDir)

    # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")

    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)

    os.mkdir(outputDir)

    buildVersionEscaped = "'" + buildVersion + "'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")

    sourceChanged = False

    log.write("[tbox] Pulling source tree\n")

    for (module, moduleSource) in reposModules:
        moduleDir = os.path.join(workingDir, module)

        if os.path.exists(moduleDir):
            log.write("[tbox] Checking for source updates\n")
            print "updating %s" % module

            os.chdir(moduleDir)

            outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "up"])

            hardhatutil.dumpOutputList(outputList, log)

            if NeedsUpdate(outputList):
                sourceChanged = True
                log.write("[tbox] %s modified\n" % module)
            else:
                log.write("[tbox] %s unchanged\n" % module)

        else:
            svnSource = os.path.join(reposRoot, moduleSource)

            log.write("[tbox] Retrieving source tree [%s]\n" % svnSource)
            print "pulling %s" % module

            os.chdir(workingDir)

            outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "-q", "co", svnSource, module])

            hardhatutil.dumpOutputList(outputList, log)

            sourceChanged = True

    os.chdir(workingDir)

    doBuild(workingDir, log)

    if skipTests:
        ret = "success"
    else:
        ret = doTests(workingDir, log)

    if sourceChanged:
        doDistribution(workingDir, log, outputDir, buildVersion, buildVersionEscaped)

        changes = "-changes"
    else:
        changes = "-nochanges"

    print ret + changes

    return ret + changes
Ejemplo n.º 5
0
                     options.rsyncServer + ":staging/" + platform])
                    hardhatutil.dumpOutputList(outputList, log)

                    completedFile = timestamp + os.sep + "completed"
                    open(completedFile, "w").close()

                    log.write('rsync -e ssh -avzp ' + completedFile + ' ' +
                              options.rsyncServer + ':staging/' +
                              platform + "/" + timestamp)
                    outputList = hardhatutil.executeCommandReturnOutputRetry(
                     [rsyncProgram, "-e", "ssh", "-avzp",
                     completedFile, 
                     options.rsyncServer + ":staging/" + platform + "/" + timestamp])
                    hardhatutil.dumpOutputList(outputList, log)

                    hardhatutil.rmdirRecursive(timestamp)

        elif ret[:12] == "build_failed":
            print "The build failed"
            log.write("The build failed\n")
            status = "build_failed"
            log.close()
    
            log = open(logFile, "r")
            logContents = log.read()
            log.close()
            SendMail(fromAddr, alertAddr, startTime, buildName,
                     "The build failed", treeName, None)
            SendMail(fromAddr, mailtoAddr, startTime, buildName, status, 
             treeName, logContents)
            log = open(logFile, "w")
Ejemplo n.º 6
0
def main():
    global project

    nowString = time.strftime("%Y-%m-%d %H:%M:%S")
    nowShort = hardhatutil.RemovePunctuation(nowString)
    # nowString is the current time, in a SVN-compatible format
    print nowString
    # nowShort is nowString without punctuation or whitespace
    print nowShort

    try:
        opts, args = getopt.getopt(sys.argv[1:], "b:d:m:p:t:n:s")
    except getopt.GetoptError:
        usage()
        sys.exit(1)

    buildVersionArg = None
    svnDateArg = None
    toAddrArg = None
    projectArg = None
    svnTagArg = None
    buildName = 'buildname'
    noTests = 0

    for opt, arg in opts:

        if opt == "-b":
            buildVersionArg = arg

        if opt == "-d":
            svnDateArg = arg

        if opt == "-m":
            toAddrArg = arg

        if opt == "-p":
            projectArg = arg

        if opt == "-t":
            svnTagArg = arg

        if opt == "-n":
            buildName = arg

        if opt == "-s":
            noTests = 1

    if svnDateArg and svnTagArg:
        print "Please choose either a svn date or tag, not both"
        sys.exit(1)

    # defaults:
    if projectArg:
        project = projectArg

    if toAddrArg:
        toAddr = toAddrArg
    else:
        toAddr = None

    buildVersion = nowString

    if svnDateArg:
        buildVersion = svnDateArg
    if svnTagArg:
        buildVersion = svnTagArg
    if buildVersionArg:
        buildVersion = buildVersionArg

    print "nowString", nowString
    print "nowShort", nowShort
    print "buildVersion", buildVersion
    print "buildName", buildName
    print "skipTests=", noTests

    # buildVersion is encoded into the application's internal version

    whereAmI = os.path.dirname(os.path.abspath(hardhatutil.__file__))
    hardhatFile = os.path.join(whereAmI, "hardhat.py")

    homeDir = os.environ['HOME']
    buildDir = os.path.join(homeDir, "singlebuild")
    logFile = os.path.join(buildDir, "build.log")
    buildscriptFile = os.path.join("buildscripts", project + ".py")
    fromAddr = "builds"
    fromAddr += "@"
    fromAddr += "osafoundation.org"
    print "Mail to ", toAddr
    print "Build dir", buildDir
    print "Build file ", buildscriptFile

    curDir = os.path.abspath(os.getcwd())

    if os.path.exists(buildDir):
        hardhatutil.rmdirRecursive(buildDir)
    os.mkdir(buildDir)

    path = os.environ.get('PATH', os.environ.get('path'))
    svnProgram = hardhatutil.findInPath(path, "svn")

    log = open(logFile, "w+")
    try:
        # bring this hardhat directory up to date
        outputList = hardhatutil.executeCommandReturnOutputRetry(
            [svnProgram, "update"])

        # load the buildscript file for the project
        mod = hardhatutil.ModuleFromFile(buildscriptFile, "buildscript")

        # SendMail(fromAddr, toAddr, nowString, nowString, buildName,
        # "building", None)

        mod.Start(hardhatFile,
                  buildDir,
                  buildVersion,
                  1,
                  log,
                  skipTests=noTests,
                  tagID=svnTagArg)

    except Exception, e:
        import traceback
        traceback.print_exc()
        print "something failed"
        log.write("something failed")
        status = "build_failed"
Ejemplo n.º 7
0
        print "Could not initialize hardhat environment.  Exiting."
        print "Exception:", e
        import traceback
        traceback.print_exc()
        sys.exit(1)

    # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)
    chanDir = os.path.join(workingDir, 'chandler')

    # test if we've been through the loop at least once
    if clobber:
        for module in reposModules:
            modDir = os.path.join(workingDir, module)
            if os.path.exists(modDir):
                hardhatutil.rmdirRecursive(modDir)

    os.chdir(workingDir)

    # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")

    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)

    os.mkdir(outputDir)

    buildVersionEscaped = "\'" + buildVersion + "\'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")

    if not os.path.exists(chanDir):
Ejemplo n.º 8
0
def Start(hardhatScript,
          workingDir,
          buildVersion,
          clobber,
          log,
          skipTests=False,
          upload=False):

    # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)

    os.chdir(workingDir)

    # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")

    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)

    os.mkdir(outputDir)

    buildVersionEscaped = "\'" + buildVersion + "\'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")

    sourceChanged = False

    log.write("[tbox] Pulling source tree\n")

    for (module, moduleSource) in reposModules:
        moduleDir = os.path.join(workingDir, module)

        if os.path.exists(moduleDir):
            log.write("[tbox] Checking for source updates\n")
            print "updating %s" % module

            os.chdir(moduleDir)

            outputList = hardhatutil.executeCommandReturnOutputRetry(
                [svnProgram, "up"])

            hardhatutil.dumpOutputList(outputList, log)

            if NeedsUpdate(outputList):
                sourceChanged = True
                log.write("[tbox] %s modified\n" % module)
            else:
                log.write("[tbox] %s unchanged\n" % module)

        else:
            svnSource = os.path.join(reposRoot, moduleSource)

            log.write("[tbox] Retrieving source tree [%s]\n" % svnSource)
            print "pulling %s" % module

            os.chdir(workingDir)

            outputList = hardhatutil.executeCommandReturnOutputRetry(
                [svnProgram, "-q", "co", svnSource, module])

            hardhatutil.dumpOutputList(outputList, log)

            sourceChanged = True

    os.chdir(workingDir)

    doBuild(workingDir, log)

    if skipTests:
        ret = 'success'
    else:
        ret = doTests(workingDir, log)

    if sourceChanged:
        doDistribution(workingDir, log, outputDir, buildVersion,
                       buildVersionEscaped)

        changes = "-changes"
    else:
        changes = "-nochanges"

    print ret + changes

    return ret + changes
Ejemplo n.º 9
0
        sys.exit(1)
      
    # if tagID is present then we have to modify reposBase as a tag has
    # been requested instead of the trunk
    if tagID:
        reposBase='tags/%s' % tagID
    else:
        reposBase='trunk'
      
    # make sure workingDir is absolute
    workingDir = os.path.abspath(workingDir)
    chanDir = os.path.join(workingDir, mainModule)
    # test if we've been thruough the loop at least once
    if clobber == 1:
        if os.path.exists(chanDir):
            hardhatutil.rmdirRecursive(chanDir)
            
    os.chdir(workingDir)

    # remove outputDir and create it
    outputDir = os.path.join(workingDir, "output")
    if os.path.exists(outputDir):
        hardhatutil.rmdirRecursive(outputDir)
    os.mkdir(outputDir)
    
    buildVersionEscaped = "\'" + buildVersion + "\'"
    buildVersionEscaped = buildVersionEscaped.replace(" ", "|")
    
    if not os.path.exists(chanDir):
        # Initialize sources
        print "Setup source tree..."
Ejemplo n.º 10
0
def main():
    global project
    
    nowString = time.strftime("%Y-%m-%d %H:%M:%S")
    nowShort = hardhatutil.RemovePunctuation(nowString)
    # nowString is the current time, in a SVN-compatible format
    print nowString
    # nowShort is nowString without punctuation or whitespace
    print nowShort

    try:
        opts, args = getopt.getopt(sys.argv[1:], "b:d:m:p:t:n:s")
    except getopt.GetoptError:
        usage()
        sys.exit(1)

    buildVersionArg = None
    svnDateArg = None
    toAddrArg = None
    projectArg = None
    svnTagArg = None
    buildName = 'buildname'
    noTests = 0

    for opt, arg in opts:

        if opt == "-b":
            buildVersionArg = arg

        if opt == "-d":
            svnDateArg = arg

        if opt == "-m":
            toAddrArg = arg

        if opt == "-p":
            projectArg = arg

        if opt == "-t":
            svnTagArg = arg

        if opt == "-n":
            buildName = arg

        if opt == "-s":
            noTests = 1

    if svnDateArg and svnTagArg:
        print "Please choose either a svn date or tag, not both"
        sys.exit(1)

    # defaults:
    if projectArg:
        project = projectArg
        
    if toAddrArg:
        toAddr  = toAddrArg
    else:
        toAddr = None

    buildVersion = nowString

    if svnDateArg:
        buildVersion = svnDateArg
    if svnTagArg:
        buildVersion = svnTagArg
    if buildVersionArg:
        buildVersion = buildVersionArg

    print "nowString", nowString
    print "nowShort", nowShort
    print "buildVersion", buildVersion
    print "buildName", buildName
    print "skipTests=", noTests

    # buildVersion is encoded into the application's internal version

    whereAmI = os.path.dirname(os.path.abspath(hardhatutil.__file__))
    hardhatFile = os.path.join(whereAmI, "hardhat.py")

    homeDir = os.environ['HOME']
    buildDir = os.path.join(homeDir, "singlebuild")
    logFile = os.path.join(buildDir, "build.log")
    buildscriptFile = os.path.join("buildscripts", project + ".py")
    fromAddr = "builds"
    fromAddr += "@"
    fromAddr += "osafoundation.org"
    print "Mail to ", toAddr
    print "Build dir", buildDir
    print "Build file ", buildscriptFile

    curDir = os.path.abspath(os.getcwd())

    if os.path.exists(buildDir):
        hardhatutil.rmdirRecursive(buildDir)
    os.mkdir(buildDir)

    path = os.environ.get('PATH', os.environ.get('path'))
    svnProgram = hardhatutil.findInPath(path, "svn")

    log = open(logFile, "w+")
    try:
        # bring this hardhat directory up to date
        outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "update"])

        # load the buildscript file for the project
        mod = hardhatutil.ModuleFromFile(buildscriptFile, "buildscript")

        # SendMail(fromAddr, toAddr, nowString, nowString, buildName,
        # "building", None)

        mod.Start(hardhatFile, buildDir, buildVersion, 1, log, skipTests=noTests, tagID=svnTagArg)

    except Exception, e:
        import traceback
        traceback.print_exc()
        print "something failed"
        log.write("something failed")
        status = "build_failed"