Exemplo n.º 1
0
def handle_commit(args,
                  msg,
                  branch,
                  treename,
                  kernelobjdir,
                  tmpdir,
                  wgitdir,
                  backport_rev,
                  kernel_rev,
                  prev_kernel_rev=None,
                  defconfig=None,
                  env={},
                  commit_failure=True,
                  append_shortlog=None):
    log = []

    def logwrite(l):
        log.append(l)

    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        bpid = gentree.Bp_Identity(integrate=False,
                                   kconfig_prefix='CPTCFG_',
                                   project_prefix='',
                                   project_dir=wdir,
                                   target_dir=wdir,
                                   target_dir_name='',
                                   kconfig_source_var='$BACKPORT_DIR')
        failure = gentree.process(kernelobjdir,
                                  open(args.copy_list, 'r'),
                                  bpid=bpid,
                                  git_revision=kernel_rev,
                                  base_name=tree,
                                  logwrite=logwrite,
                                  verbose=True,
                                  git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL,
                                                             failure)
            for l in log:
                print(l)
            newline = ''
            append_shortlog = None
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree,
                                                    prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'],
                   tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig,
                           os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        if not failure or commit_failure:
            if append_shortlog:
                files = []
                for d in git.status(tree=wdir):
                    files.extend(d[1:])
                if files:
                    msg += '\n' + append_shortlog[2] + '\n\n'
                    msg += git.shortlog(append_shortlog[0],
                                        append_shortlog[1],
                                        tree=kernelobjdir,
                                        files=files)
                else:
                    msg += "\nNo commits changed the generated code.\n\n"

            msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
                'newline': newline,
                'PREFIX': PREFIX,
                'bprev': backport_rev,
                'tree': treename,
                'krev': kernel_rev,
            }

            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure
def handle_commit(args, msg, branch, treename, kernelobjdir, tmpdir, wgitdir, backport_rev, kernel_rev,
                  prev_kernel_rev=None, defconfig=None, env={}, commit_failure=True):
    log = []
    def logwrite(l):
        log.append(l)
    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        failure = gentree.process(kernelobjdir, wdir, open(args.copy_list, 'r'),
                                  git_revision=kernel_rev,
                                  base_name=tree, logwrite=logwrite,
                                  git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL, failure)
            for l in log:
                print(l)
            newline=''
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree, prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'], tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig, os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
        'newline': newline,
        'PREFIX': PREFIX,
        'bprev': backport_rev,
        'tree': treename,
        'krev': kernel_rev,
      }

        if not failure or commit_failure:
            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure
Exemplo n.º 3
0
def handle_commit(args, msg, branch, treename, kernelobjdir, tmpdir, wgitdir, backport_rev, kernel_rev,
                  prev_kernel_rev=None, defconfig=None, env={}, commit_failure=True,
                  append_shortlog=None):
    log = []
    def logwrite(l):
        log.append(l)
    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        bpid = gentree.Bp_Identity(integrate = False,
                                   kconfig_prefix = 'CPTCFG_',
                                   project_prefix = '',
                                   project_dir = wdir,
                                   target_dir = wdir,
                                   target_dir_name = '',
                                   kconfig_source_var = '$BACKPORT_DIR')
        failure = gentree.process(kernelobjdir, open(args.copy_list, 'r'),
                                  bpid=bpid, git_revision=kernel_rev,
                                  base_name=tree, logwrite=logwrite,
                                  verbose=True, git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL, failure)
            for l in log:
                print(l)
            newline=''
            append_shortlog=None
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree, prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'], tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig, os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        if not failure or commit_failure:
            if append_shortlog:
                files = []
                for d in git.status(tree=wdir):
                    files.extend(d[1:])
                if files:
                    msg += '\n' + append_shortlog[2] + '\n\n'
                    msg += git.shortlog(append_shortlog[0], append_shortlog[1],
                                        tree=kernelobjdir, files=files)
                else:
                    msg += "\nNo commits changed the generated code.\n\n"

            msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
            'newline': newline,
            'PREFIX': PREFIX,
            'bprev': backport_rev,
            'tree': treename,
            'krev': kernel_rev,
          }

            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure
Exemplo n.º 4
0
def handle_commit(args,
                  msg,
                  branch,
                  treename,
                  kernelobjdir,
                  tmpdir,
                  wgitdir,
                  backport_rev,
                  kernel_rev,
                  prev_kernel_rev=None,
                  defconfig=None,
                  env={},
                  commit_failure=True):
    log = []

    def logwrite(l):
        log.append(l)

    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        failure = gentree.process(kernelobjdir,
                                  wdir,
                                  open(args.copy_list, 'r'),
                                  git_revision=kernel_rev,
                                  base_name=tree,
                                  logwrite=logwrite,
                                  git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL,
                                                             failure)
            for l in log:
                print(l)
            newline = ''
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree,
                                                    prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'],
                   tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig,
                           os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
            'newline': newline,
            'PREFIX': PREFIX,
            'bprev': backport_rev,
            'tree': treename,
            'krev': kernel_rev,
        }

        if not failure or commit_failure:
            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure