Exemple #1
0
def svn_cleanup():
    try:
        svn("cleanup")
    except:
        print "svn cleanup failed" 
    else:
        print "svn cleanup succeeded"
Exemple #2
0
def update(version):
    """ Updates the current copy to the given version"""
    print 'Updating to version ' + version
    #return
    try:
        print 'Calling svn up'
        svn('up','-r',version)
    except Exception, e: 
        if re.search("svn cleanup" , e.stderr):
            print e.stderr
            print 'Calling svn cleanup'
            svn_cleanup()
            return 1
            #update(version)
        elif re.search("already exists",e.stderr):
            print e.stderr
            handle_unversionedFile(e.stderr)
            return 2
        elif re.search("Secure connection truncated", e.stderr) or re.search("503 Service Unavailable",e.stderr):
            print e.stderr
            return 3
            #update(version)
        else:
            print e.stderr
            return 4
Exemple #3
0
 def checkout(cls, cfg, dst_path):
     if os.path.exists(dst_path):
         is_under_ctl, meta = cls._get_vcs_info(dst_path)
         if not is_under_ctl:
             print 'Woring copy path allready exists, but not under VCS control.'
             return
         cls._switch(dst_path, cfg['SVN_URL'])
         cls._up_to_rev(dst_path, cfg['SVN_REV'])
     else:
         svn('co', cfg['SVN_URL'], '-r', cfg['SVN_REV'], dst_path)
Exemple #4
0
    def _switch(cls, path, repo_addr):
        """
        Update working copy to passed rev.
        Args:
            path: str, path to folder to update.
            rev: str, target revision, HEAD and etc supported as well.

        Throws:
            sh.ErrorReturnCode_1
        """
        svn('switch', repo_addr, path)
Exemple #5
0
    def _up_to_rev(cls, path, rev):
        """
        Update working copy to passed rev.
        Args:
            path: str, path to folder to update.
            rev: str, target revision, HEAD and etc supported as well.

        Throws:
            sh.ErrorReturnCode_1
        """
        svn('up', path, '-r{0}'.format(rev))
Exemple #6
0
def svn_commit(user, pwd, msg):
    val = svn("commit", "--username", user, "--password", pwd,
              "--no-auth-cache", "-m", msg)
    if val.exit_code != 0:
        raise ValueError("Commit failed with status ", val)
    else:
        return val
Exemple #7
0
def svn_checkout(remote, local):
    # Note that for Mac, this requires a more modern version of svn to be
    # installed than comes with Mac os 10.8. At least SVN 1.7.9 with Openssl
    # 1.0.1e works.
    val = svn("co", "--trust-server-cert", "--non-interactive", remote, local)
    if val.exit_code != 0:
        raise ValueError("Checkout failed with status ", val)
    else:
        return val
Exemple #8
0
def svn_checkout(remote, local):
    # Note that for Mac, this requires a more modern version of svn to be
    # installed than comes with Mac os 10.8. At least SVN 1.7.9 with Openssl
    # 1.0.1e works.
    val = svn("co", "--trust-server-cert", "--non-interactive", remote, local)
    if val.exit_code != 0:
        raise ValueError ("Checkout failed with status ", val)
    else:
        return val
Exemple #9
0
def _svn_info():
    lHEADId, lHash = None, None

    lSVNInfoRaw = sh.svn('info')

    lSVNInfo = {
        lEntry[0]: lEntry[1].strip()
        for lEntry in (lLine.split(':', 1) for lLine in lSVNInfoRaw.split('\n')
                       if lLine)
    }

    lHEADId = lSVNInfo['URL'].replace(lSVNInfo['Repository Root'] + '/', '')

    lSVNStatus = sh.svn('status', '-q')
    if len(lSVNStatus):
        lHEADId += '*'

    lHash = lSVNInfo['Revision']

    return lHEADId, lHash
Exemple #10
0
    def initSvn(self, file_content):
        from sh import svn, chmod, chown
        repourl = Config.SVN_ADDR + self.name
        hook_content = r'''#!/bin/bash
export LC_CTYPE=en_US.UTF-8
export LANG=en_US.UTF-8
svn up %s
''' % self.userhome
        #auto update with hook
        os.chdir(os.path.join(self.user_repo, 'hooks'))
        with open('post-commit', 'w') as f:
            f.write(hook_content)
        chmod('-R', 777, self.user_repo)
        #checkout add ci for init
        svn('co', '--non-interactive', '--trust-server-cert', repourl,
            self.userhome)
        chown('-R', Config.HTTPD_USER + ':' + Config.HTTPD_GROUP,
              self.userhome)
        os.chdir(self.userhome)
        with open('index.html', 'w') as f:
            f.write(file_content)
        svn('add', 'index.html')
        svn('ci', '--username', self.name, '--password', self.passwd,
            '--non-interactive', '--trust-server-cert', '-m', 'init commit',
            '--force-log')
Exemple #11
0
    def _get_vcs_info(cls, path):
        """
        Retrive working copy metadata.
        Args:
            path: str, path to folder to update.

        Returns:
            tuple of two elements
            bool - is path under VSC control or  not.
            str - VCS metadata.
        """
        rv = (False, None)
        try:
            meta = svn('info', path)
            return (True, meta)
        except sh.ErrorReturnCode_1:
            return rv
Exemple #12
0
    def _collect_derty(cls):
        """
        Collect changed and unwanted files in cwd.

        Returns:
            tuple of lists
            to_remove - files and folders names, which would be removed.
            to_rollback - files and folders names, which would be rolled back.
        """
        to_rollback = []
        to_remove = []
        clr_f_name = lambda row: row.rstrip().split(' ')[-1]

        for row in sh.svn('status', '--no-ignore'):
            if row.startswith('?'):
                to_remove.append(clr_f_name(row))
            elif row.startswith('M'):
                to_rollback.append(clr_f_name(row))

        return to_remove, to_rollback
Exemple #13
0
    def clean(cls, cfg, path):
        names2txt = lambda names: '\n'.join(['\t* ' + os.path.join(path, n) for n in names])
        with preserve_cwd():
            os.chdir(path)
            to_remove, to_rollback = cls._collect_derty()

            to_remove_txt = names2txt(to_remove)
            to_rollback_txt = names2txt(to_rollback)
            msg_rm = "The following untracked working tree files would be removed:"
            msg_rallback = "The following untracked working tree files would be rolled back:"

            def ask():
                msg = []
                if to_remove:
                    msg.extend([msg_rm, to_remove_txt])
                if to_rollback:
                    msg.extend([msg_rallback, to_rollback_txt])

                msg.append('\nContinue (y/n)')
                return raw_input('\n'.join(msg))


            while True:
                if to_remove or to_rollback:
                    is_agreed = ask()
                else:
                    print 'Nothing to clean'
                    return
                if is_agreed.lower() == 'n':
                    print 'Doing nothing'
                    return
                elif is_agreed.lower() == 'y':
                    break
                else:
                    is_agreed = ask()

            [cls._rm(f) for f in to_remove]
            [svn('revert', f) for f in to_rollback]
        cls.checkout(cfg, path)
        print 'Working copy cleared'
Exemple #14
0
    def initSvn(self, file_content):
        from sh import svn, chmod, chown
        repourl = Config.SVN_ADDR + self.name
        hook_content = r'''#!/bin/bash
export LC_CTYPE=en_US.UTF-8
export LANG=en_US.UTF-8
svn up %s
''' % self.userhome
        #auto update with hook
        os.chdir(os.path.join(self.user_repo, 'hooks'))
        with open('post-commit', 'w') as f: f.write(hook_content)
        chmod('-R', 777, self.user_repo)
        #checkout add ci for init
        svn('co', '--non-interactive', '--trust-server-cert', repourl, self.userhome)
        chown('-R', Config.HTTPD_USER + ':' + Config.HTTPD_GROUP, self.userhome)
        os.chdir(self.userhome)
        with open('index.html', 'w') as f:
            f.write(file_content)
        svn('add', 'index.html')
        svn('ci', '--username', self.name, '--password', self.passwd, '--non-interactive', '--trust-server-cert', '-m', 'init commit', '--force-log')
Exemple #15
0
def info(env):

    if not env.work.path:
        secho('ERROR: No ipbb work area detected', fg='red')
        return

    echo()
    secho("Packages", fg='blue')
    lSrcs = env.sources
    if not lSrcs:
        return

    lSrcTable = Texttable(max_width=0)
    lSrcTable.set_deco(Texttable.HEADER | Texttable.BORDER)
    lSrcTable.set_chars(['-', '|', '+', '-'])
    lSrcTable.header(['name', 'kind', 'version', 'hash'])
    for lSrc in lSrcs:
        lSrcDir = join(env.srcdir, lSrc)

        lKind, lHEADId, lHash = "unknown", None, None

        # Check if a git repository
        if exists(join(lSrcDir, '.git')):
            with DirSentry(lSrcDir) as _:

                lKind = 'git'
                try:
                    sh.git('rev-parse', '--git-dir')
                except sh.ErrorReturnCode_128:
                    lKind += ' (broken)'
                    lHEADId = '(unknown)'

                if lKind == 'git':
                    try:
                        lBranch = '/'.join(
                            sh.git('symbolic-ref',
                                   'HEAD').split('/')[2:]).strip()
                    except sh.ErrorReturnCode_128:
                        lBranch = None

                    try:
                        lTag = sh.git('describe', '--tags', '--exact-match',
                                      'HEAD').strip()
                    except sh.ErrorReturnCode_128:
                        lTag = None

                    lHash = sh.git('rev-parse', '--short=8',
                                   'HEAD').strip() + '...'

                    if lTag is not None:
                        lHEADId = lTag
                    elif lBranch is not None:
                        lHEADId = lBranch
                    else:
                        lHEADId = lHash

                    try:
                        sh.git('diff', '--no-ext-diff', '--quiet').strip()
                    except sh.ErrorReturnCode_1:
                        lHEADId += '*'

                    try:
                        sh.git('diff', '--no-ext-diff', '--cached',
                               '--quiet').strip()
                    except sh.ErrorReturnCode_1:
                        lHEADId += '+'
        elif exists(join(lSrcDir, '.svn')):
            with DirSentry(lSrcDir) as _:
                lKind = 'svn'

                lSVNInfoRaw = sh.svn('info')

                lSVNInfo = {
                    lEntry[0]: lEntry[1].strip()
                    for lEntry in (lLine.split(':', 1)
                                   for lLine in lSVNInfoRaw.split('\n')
                                   if lLine)
                }

                lHEADId = lSVNInfo['URL'].replace(
                    lSVNInfo['Repository Root'] + '/', '')

                lSVNStatus = sh.svn('status', '-q')
                if len(lSVNStatus):
                    lHEADId += '*'

                lHash = lSVNInfo['Revision']

        lSrcTable.add_row([lSrc, lKind, lHEADId, lHash])
    echo(lSrcTable.draw())
Exemple #16
0
def svn_add(fname):
    val = svn("add", fname)
    if val.exit_code != 0:
        raise ValueError("svn add failed with status ", val)
    else:
        return val
Exemple #17
0
def svn_add(fname):
    val = svn("add", fname)
    if val.exit_code != 0:
        raise ValueError("svn add failed with status ", val)
    else:
        return val
Exemple #18
0
def svn_commit(user, pwd, msg):
    val = svn("commit", "--username", user, "--password", pwd, "--no-auth-cache", "-m", msg)
    if val.exit_code != 0:
        raise ValueError ("Commit failed with status ", val)
    else:
        return val
Exemple #19
0
def srcstat(env):

    if not env.workPath:
        secho('ERROR: No ipbb work area detected', fg='red')
        return

    secho("Packages", fg='blue')
    lSrcs = env.getSources()
    if not lSrcs:
        return

    lSrcTable = Texttable(max_width=0)
    lSrcTable.set_deco(Texttable.HEADER | Texttable.BORDER)
    lSrcTable.set_chars(['-', '|', '+', '-'])
    lSrcTable.header(['name', 'kind', 'version'])
    for lSrc in lSrcs:
        lSrcDir = join(env.src, lSrc)

        lKind, lBranch = "unknown", None

        # Check if a git repository
        if exists(join(lSrcDir, '.git')):
            with DirSentry(lSrcDir) as _:

                lKind = 'git'
                try:
                    sh.git('rev-parse', '--git-dir')
                except sh.ErrorReturnCode_128:
                    lKind += ' (broken)'
                    lBranch = '(unknown)'

                if lKind == 'git':
                    try:
                        # lBranch = sh.git('symbolic-ref','--short', 'HEAD').strip()
                        lBranch = sh.git('symbolic-ref',
                                         'HEAD').split('/')[-1].strip()
                    except sh.ErrorReturnCode_128:
                        lBranch = sh.git('rev-parse', '--short',
                                         'HEAD').strip() + '...'

                    try:
                        sh.git('diff', '--no-ext-diff', '--quiet').strip()
                    except sh.ErrorReturnCode_1:
                        lBranch += '*'

                    try:
                        sh.git('diff', '--no-ext-diff', '--cached',
                               '--quiet').strip()
                    except sh.ErrorReturnCode_1:
                        lBranch += '+'
        elif exists(join(lSrcDir, '.svn')):
            with DirSentry(lSrcDir) as _:
                lKind = 'svn'

                lSVNInfoRaw = sh.svn('info')

                lSVNInfo = {
                    lEntry[0]: lEntry[1].strip()
                    for lEntry in (lLine.split(':', 1)
                                   for lLine in lSVNInfoRaw.split('\n')
                                   if lLine)
                }

                lBranch = lSVNInfo['URL'].replace(
                    lSVNInfo['Repository Root'] + '/', '')

                lSVNStatus = sh.svn('status', '-q')
                if len(lSVNStatus):
                    lBranch += '*'

        lSrcTable.add_row([lSrc, lKind, lBranch])
    echo(lSrcTable.draw())
Exemple #20
0
def svn(ictx, repo, dest, rev, dryrun, sparse):
    '''Add a svn repository REPO to the source area'''

    lUrl = urlparse(repo)
    lRepoName = splitext(basename(lUrl.path))[0] if dest is None else dest
    # -------------------------------------------------------------------------
    # Stop if the target directory already exists
    cprint('Adding svn repository [blue]{}[/blue'.format(repo))

    lRepoLocalPath = join(ictx.srcdir, lRepoName)

    if exists(lRepoLocalPath):
        raise click.ClickException('Repository already exists \'%s\'' %
                                   lRepoLocalPath)
    # -------------------------------------------------------------------------

    # -------------------------------------------------------------------------
    if not sparse:
        lArgs = ['checkout', '-q', repo]

        # Append destination directory if defined
        if dest is not None:
            lArgs.append(dest)

        if rev is not None:
            lArgs += ['-r', str(rev)]

        # Do the checkout
        lCmd = ['svn'] + lArgs
        cprint('Executing [blue]{}[/blue]'.format(' '.join(lCmd)))
        if not dryrun:
            sh.svn(*lArgs, _out=sys.stdout, _cwd=ictx.srcdir)
    else:
        cprint('Sparse checkout mode: [blue]{}[/blue]'.format(sparse))
        # ----------------------------------------------------------------------
        # Checkout an empty base folder
        lArgs = ['checkout', '--depth=empty', repo]

        # Append destination directory if defined
        if dest is not None:
            lArgs.append(dest)

        if rev is not None:
            lArgs += ['-r', str(rev)]

        lCmd = ['svn'] + lArgs
        cprint('Executing [blue]{}[/blue]'.format(' '.join(lCmd)))
        if not dryrun:
            sh.svn(*lArgs, _out=sys.stdout, _cwd=ictx.srcdir)
        # ----------------------------------------------------------------------
        lArgs = ['update']
        lCmd = ['svn'] + lArgs
        for lPath in sparse:
            lTokens = [lToken for lToken in lPath.split('/') if lToken]

            lPartials = [
                '/'.join(lTokens[:i + 1]) for i, _ in enumerate(lTokens)
            ]

            # Recursively check out intermediate, empty folders
            for lPartial in lPartials:
                lArgs = ['up', '--depth=empty', lPartial]
                cprint('Executing [blue]{}[/blue]'.format(' '.join(['svn'] +
                                                                   lArgs)))
                if not dryrun:
                    sh.svn(*lArgs, _out=sys.stdout, _cwd=lRepoLocalPath)

            # Finally check out the target
            lArgs = ['up', '--set-depth=infinity', lPath]
            cprint('Executing [blue]{}[/blue]'.format(' '.join(['svn'] +
                                                               lArgs)))
            if not dryrun:
                sh.svn(*lArgs, _out=sys.stdout, _cwd=lRepoLocalPath)

    _repo_init(ictx, lRepoName)