thirdparty/vcs-load-dirs/vcs_support/vcs_wc.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 11 Jul 2009 23:29:31 +0200
changeset 2599 22e1ec7bd02a
parent 2311 e8262ca32109
permissions -rw-r--r--
Add queue.yaml to build scripts.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2311
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
# Copyright (C) 2003-2007 John Goerzen
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
# <jgoerzen@complete.org>
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
#
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#    This program is free software; you can redistribute it and/or modify
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
#    it under the terms of the GNU General Public License as published by
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
#    the Free Software Foundation; either version 2 of the License, or
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
#    (at your option) any later version.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#    This program is distributed in the hope that it will be useful,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
#    GNU General Public License for more details.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
#
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
#    You should have received a copy of the GNU General Public License
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
#    along with this program; if not, write to the Free Software
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
import util
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
import os.path
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
from commandver import cmd, isdarcs, issvk, isgit, ishg, vcscmd
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
class wc:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
    """Object for a working copy."""
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
    def __init__(self, wcpath, verbose = 0, fsonly = 0):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
        self.wcpath = os.path.abspath(wcpath)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
        self.verb = verbose
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
        self.fsonly = fsonly
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
        if not self.wcverify():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
            raise Exception, "%s is not a tla working copy" % self.wcpath
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    32
    def gettreeversion(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
        if isdarcs():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    34
            #util.chdircmd(self.wcpath, util.getstdoutsafeexec, "darcs",
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
            #              ['check'])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
            return "Darcs repository"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
        elif ishg():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
            return "Mercurial repository"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
        elif issvk():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
            return "Svk repository"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
        elif isgit():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
            return "Git repository"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
            return util.chdircmd(self.wcpath, util.getstdoutsafeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
                                 ['tree-version'])[0].strip() 
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
    def wcverify(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
        try:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
            self.gettreeversion()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
        except util.ExecProblem:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
            return 0
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
        return 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
    def gettaggingmethod(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
        if isdarcs() or isgit() or ishg():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
            return 'explicit'
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
            return util.chdircmd(self.wcpath, util.getstdoutsafeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
                                 [cmd().tagging_method])[0].strip()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    60
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
    def gettree(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
        return util.maketree(self.wcpath,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
                             ignore = [r'(^(\{arch\}$|,,|\.hg|\.hgtags|\.hgignore|\.git|_darcs|\.arch-ids$|\.arch-inventory$|\+\+)|/\.arch-ids/)'])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
    
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
    def addtag(self, file):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
            print "Adding %s" % file
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    68
        if (file[-1] == '/') and \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    69
           (not os.path.exists(os.path.join(self.wcpath,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
                                            file[:-1]))):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
            try:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
                print "addtag: making dir %s" % file[:-1]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
                os.makedirs(os.path.join(self.wcpath, file[:-1]))
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
            except:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
                raise
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
        file = self.slashstrip(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    77
        isdir = os.path.isdir(os.path.join(self.wcpath, file))
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
        if (not self.fsonly) and \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
               (not ishg()) and ((not isdarcs()) or isdir):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
            # Darcs will see adds later, but we need to add dirs
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
            # now so darcs mv will work.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
            #
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
            # Mercurial will see adds later, and doesn't track directories,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    84
            # so we don't do anything with it.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
            util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
                          cmd().add + [file])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
    def movetag(self, src, dest):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
            print "Moving %s to %s" % (src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
        if src[-1] == '/' \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
               and dest[-1] == '/' \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
               and ((not isdarcs()) and (not isgit()) and (not ishg())):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
            # Dir to dir -- darcs mv will catch it already.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
            # Git doesn't do rename recording, so don't worry about it?
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
            return
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
        src, dest = self.slashstrip(src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
        if not self.fsonly:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
            util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
                          [cmd().move, src, dest])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
    def movefile(self, src, dest):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   103
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   104
            print "Moving file %s to %s" % (src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
        src, dest = self.slashstrip(src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
        def doit():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   108
            destdir = os.path.dirname(dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
            if (not os.path.exists(destdir)) and destdir != '':
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
                self.makedirs(destdir)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   111
            if self.fsonly or \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
               (not isdarcs() and (not isgit()) and (not ishg())):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
                # Darcs, hg, and git actually do this when they move the tag
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
                os.rename(src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
        util.chdircmd(self.wcpath, doit)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   117
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   118
    def delfile(self, file):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   119
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   120
            print "Deleting file %s" % file
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   121
        fullfile = os.path.join(self.wcpath, file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   122
        if os.path.isfile(fullfile):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
            os.unlink(fullfile)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   124
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
            util.safeexec("rm", ['-rf', fullfile])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
    def deltag(self, file):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   128
        if (not self.fsonly) and \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
               ((not isdarcs()) and (not ishg())):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
            if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
                print "Deleting %s" % file
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
            if os.path.islink(os.path.join(self.wcpath,file)) or os.path.exists(os.path.join(self.wcpath, file)):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   133
                util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   134
                          cmd().delete + [file])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   135
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   136
    def makelog(self, summary, logtext):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   137
        self.summary = summary
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   138
        self.logtext = logtext
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   139
        if ishg() or isgit() or isdarcs():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   140
            logfn = self.wcpath + "/../,,vcslog"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   141
	else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   142
            logfn =  util.chdircmd(self.wcpath, util.getstdoutsafeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   143
                                   ['make-log'])[0].strip()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   144
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   145
        self.logfn = os.path.abspath(logfn)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   146
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   147
        fd = open(self.logfn, "w")
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   148
        if isgit():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   149
            fd.write("%s\n\n" % summary)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   150
        if ishg():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   151
            fd.write("%s\n" % summary)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   152
        elif not (isdarcs() or ishg()):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   153
            fd.write("Summary: %s\n" % summary)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   154
            fd.write("Keywords: \n\n")
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   155
        fd.write(logtext)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   156
        print "LOGTEXT", logtext
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   157
        fd.close()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   158
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   159
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   160
    def commit(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   161
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   162
            print "Committing changes"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   163
        if isdarcs():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   164
            util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   165
                          [cmd().commit, "-l", "-a", "-m", self.summary,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   166
                           "--logfile", self.logfn,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   167
                           "--delete-logfile"])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   168
        elif isgit():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   169
            util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   170
                          [cmd().commit, "-a", "-F", self.logfn])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   171
	    os.unlink(self.logfn)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   172
        elif ishg():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   173
            util.chdircmd(self.wcpath, util.safeexec, vcscmd,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   174
                          [cmd().commit, "-A", "-l", self.logfn])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   175
            os.unlink(self.logfn)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   176
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   177
            if len(util.chdircmd(self.wcpath, util.getstdoutsafeexec, vcscmd, ['logs']))==0:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   178
                util.chdircmd(self.wcpath, util.safeexec, vcscmd, [cmd().importcmd])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   179
            else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   180
                util.chdircmd(self.wcpath, util.safeexec, vcscmd, [cmd().commit])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   181
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   182
    def slashstrip(self, *args):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   183
        retval = []
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   184
        for item in args:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   185
            if not len(item):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   186
                retval.append(item)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   187
            if item[-1] == '/':
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   188
                item = item[:-1]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   189
            retval.append(item)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   190
        if len(args) == 1:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   191
            return retval[0]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   192
        return retval
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   193
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   194
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   195
    def makedirs(self, name, mode=0777):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   196
        """makedirs(path [, mode=0777])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   197
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   198
        Super-mkdir; create a leaf directory and all intermediate ones.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   199
        Works like mkdir, except that any intermediate path segment (not
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   200
        just the rightmost) will be created if it does not exist.  This is
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   201
        recursive.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   202
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   203
        (Modified from Python source)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   204
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   205
        """
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   206
        head, tail = os.path.split(name)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   207
        if not tail:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   208
            head, tail = os.path.split(head)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   209
        if head and tail and not os.path.exists(head):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   210
            self.makedirs(head, mode)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   211
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   212
            print "Created directory", name
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   213
        os.mkdir(name, mode)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   214
        self.addtag(name)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   215