Exemplo n.º 1
0
def testPythonSvn():
    log = logging.getLogger("testPythonSvn")
    log.notice(
        'If this script immediately exists with "Segmentation fault" or "Illegal instruction", see http://wiki/wiki/python-svn'
    )
    c = Client()
    try:
        c.mkdir('svn+ssh://svn/wm/sandbox/bug25523', 'testing mkdir')
    except ClientError:
        # already exists
        pass
Exemplo n.º 2
0
def release(project, version, build, options):
    """Release a project/version"""

    log = logging.getLogger("release")
    log.info('Beginning release')

    client = Client()

    # Check to make sure version will be legal as a tag
    reg = re.compile('[-a-zA-Z0-9_.]+')
    for x in range(len(version)):
        if reg.match(version[x]) == None:
            raise Exception(
                "The version specified has characters that are not legal for setting a tag."
            )

    basePath = '/ext/build/' + project + '/' + version

    # resolve path to snapshot

    if (build == 'best'):
        log.info("Resolving best link:")
    else:
        log.info("Resolving link to snapshot '%s':" % (build))

    if build:
        # try snapshot first
        snapPath = basePath + '/snap/' + build
        snapSource = 'SNAP'
        if not os.path.exists(snapPath):
            # try tinderbuilds
            snapPath = basePath + '/tinderbuilds/' + build
            snapSource = 'TINDERBUILD'
        if not os.path.exists(snapPath):
            # try base
            snapPath = basePath + '/' + build
            snapSource = 'BASE'

        if not os.path.exists(snapPath):
            raise Exception("Could not find specified build %s for %s %s" %
                            (build, project, version))
    else:
        snapPath = basePath + '/best'
        snapSource = 'BEST'
        if not os.path.exists(snapPath):
            raise Exception(
                'Could not find best link at %s - either create a best link or retry with "--build".'
                % (snapPath))

    if options.paranoid and snapSource == 'TINDERBUILD':
        raise Exception(
            'Specified build found at %s. Direct release of tinderbuild is not recommended. Rerun with "-sv" to snapshot your build first, or use "--relaxed" to disable this check.'
            % snapPath)

    # get canonical path
    path = os.path.realpath(snapPath)
    # parse timestamp
    timestamp = getTimestamp(path)

    # determine tag
    project_xml = path + '/src/project.xml'
    if not os.path.exists(project_xml):
        project_xml = path + '/src/' + project + '_project/project.xml'
    if not os.path.exists(project_xml):
        raise Exception('Could not find project.xml at: ' + project_xml)

    proj = Project(project_xml)

    tag = version
    patch = None
    if proj.patch:
        patch = proj.patch

    if options.override_patch:
        patch = options.override_patch

    if patch:
        # It would be reasonable / intuitive for a user to include a leading p in override_patch.
        # Remove any leading ps or spaces to normalize expectations.
        patch = patch.strip('p \t')

        tag += 'p' + patch

    if options.override_patch:
        log.warn(
            'using tag %s, including override patch number instead of value from project.xml (%s)'
            % (tag, proj.patch))

    # Determine if this is SVN or git
    scmgit = False
    scmsvn = False
    if os.path.exists(path + '/git-checkout.log'):
        scmgit = True
    else:
        if os.path.exists(path + '/svn-checkout.log'):
            scmsvn = True
        else:
            raise Exception('Could not determine SVN or GIT')

    # determine checkout revision and path
    if scmsvn:
        info = client.info(path + "/src")
        rev = info.revision
        svnpath = info.url.replace("svn://", "svn+ssh://")

        if options.paranoid:
            if svnpath.find(project) == -1:
                raise Exception(
                    'The project you'
                    're trying to release doesn'
                    't contain its project name %s in its SVN path %s. Something is horribly wrong. (Use "--relaxed" to disable this check.)'
                    % (project, svnPath))

    # Determine tag path
    tagDir = 'svn+ssh://svn/wm/project/' + project + '/tags'
    tagPath = tagDir + '/' + tag
    # For git, make sure the repo is writable by the current user
    if scmgit:
        cmd = 'ssh git@git'
        results = shell(cmd, options)
        repo_match = False
        repo_writable = False
        for x in range(len(results)):
            if results[x].lstrip('@_RW \t\r\n').rstrip('\r\n') == project:
                repo_match = True
                if results[x][9] == 'W':
                    repo_writable = True
                else:
                    raise Exception(
                        'You dont have right to make changes to the repo for this project, therefore you cannot set the tag.'
                    )

    # check that tag doesn't already exist
    if not options.notag:
        if scmsvn:
            try:
                client.ls(tagPath)

                # tag exists already! Oops!
                raise Exception(
                    'Tag path %s already exists! Halting. (You can use --notag to disable tag creation and this check.)'
                    % (tagPath))
            except ClientError:
                # this is expected, as we haven't created it yet.
                pass

    log.info("Releasing:")
    log.info(" build: %s", path)
    if scmsvn:
        log.info(" svn:   -r %d %s", rev.number, svnpath)
    if scmgit:
        log.info(" git")
    log.info(" tag:   %s", tag)

    # Make release dirs
    log.info("Ensuring that release directories exist")
    releasesDir = basePath + '/releases'
    allReleasesDir = '/ext/build/' + project + '/releases'

    ssh('mkdir -p ' + releasesDir, options)
    ssh('mkdir -p ' + allReleasesDir, options)

    # Copy to releases
    log.info("Moving snap to releases")

    cmd = 'test -d ' + path + ' && mv ' + path + ' ' + releasesDir
    ssh(cmd, options)

    # Create soft links
    log.info("Create soft links")

    cmd = 'cd ' + releasesDir + '; test -e ' + tag + ' || ln -s ' + timestamp + ' ' + tag
    ssh(cmd, options)
    cmd = 'cd ' + allReleasesDir + '; test -e ' + tag + ' || ln -s ../' + version + '/releases/' + tag + ' ' + tag
    ssh(cmd, options)

    # recursively find dependencies and record
    # this will overwrite any previous instances (e.g. from a snapshot)
    findDepends(log, releasesDir + "/" + timestamp, options)

    # Edit save file
    log.info("Appending to SAVE file")

    msg = '%s %s RELEASE' % (project, version)
    writeSave(log, releasesDir + '/' + tag, msg, options)

    # Create project tags directory
    if scmsvn:
        try:
            client.ls(tagDir)
            log.info("Project tags directory already exists")
        except ClientError:
            # does not exist, so create it
            log.info("Creating project tags directory")
            if not options.dryrun:
                client.mkdir(
                    tagDir,
                    'release-project: make tag directory for ' + project)

        if options.notag:
            log.notice('skippping tag creation, as --notag is set')

            # may want to write tag file, if svn path has a tag in it already.
            if svnpath.find('/tags/') != -1:
                log.notice(
                    'src svnpath is a tag already, writing that to TAG path')
                cmd = 'cd ' + releasesDir + '/' + tag + '; echo ' + svnpath + ' >> TAG'
                ssh(cmd, options)
        else:
            # Make tag
            log.info("Tagging project")
            log.info(" > svn copy -r%d %s %s", rev.number, svnpath, tagPath)
            message = 'release-project: saving release tag'

            def get_log_message():
                return True, message

            client.callback_get_log_message = get_log_message
            if not options.dryrun:
                client.copy(svnpath, tagPath, rev)
            client.callback_get_log_message = None

            # Log to TAG file
            log.info("Creating TAG file")

            cmd = 'cd ' + releasesDir + '/' + tag + '; echo ' + tagPath + ' >> TAG'
            ssh(cmd, options)

        #Create tag for git
    if scmgit:
        cmd = 'cd ' + releasesDir + '/' + tag + '/src && git show --format=oneline --summary | cut -d \' \' -f 1'
        githash = shell(cmd, options)
        cmd = 'ssh git@git addtag ' + project + ' ' + version + ' ' + githash[0]
        try:
            shell(cmd, options)
        except ShellException, e:
            raise Exception(
                'Something went wrong with the addtag command. Check the log to see what the error was'
            )
        cmd = 'cd ' + releasesDir + '/' + tag + '/src && git fetch'
        ssh(cmd, options)