thirdparty/vcs-load-dirs/vcs_support/vcs_interact.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 16 Sep 2009 20:09:13 +0200
changeset 2932 666d31bd43bd
parent 2311 e8262ca32109
permissions -rw-r--r--
Fixed the Student update to properly find its own URL. Also style fix in start_update module.
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 sys, os
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
import util
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
from commandver import isdarcs
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
from tempfile import mkdtemp
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
class interaction:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
    def __init__(self, wcobj, importdir, docommit, log = '', verbose = 0,
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
                 summary = None):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
        self.wcobj = wcobj
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
        self.log = log
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
        self.docommit = docommit
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
        self.verb = verbose
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
        self.summary = summary
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
        if os.path.isdir(importdir):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
            self.importdir = os.path.abspath(importdir)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    34
            self.importfile = None
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
            self.tmpdir = None
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
        else:                           # Not a dir, try to unpack an archive.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
            self.importfile = os.path.abspath(importdir)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
            # mkdtemp returns an absolute path
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
            self.importdir = mkdtemp("-vcs-load-dirs", ",,unpack-", "..")
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
            self.tmpdir = self.importdir
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
            try:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
                if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
                    print "Unpacking archive..."
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
                if self.importfile.endswith(".tar.gz"):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
                    util.chdircmd(self.importdir, util.safeexec, "tar",
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
                                  ["-zxf", self.importfile])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
                elif self.importfile.endswith(".tar.bz2"):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
                    util.chdircmd(self.importdir, util.safeexec, "tar",
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
                                  ["-jxf", self.importfile])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
                elif self.importfile.endswith(".zip"):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
                    util.chdircmd(self.importdir, util.safeexec, "unzip",
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
                                  [self.importfile])
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
                    raise IOError, "Unknown archive file type"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    60
                # Many tarballs expand into just one single directory.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
                # Check to see if that's the case.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
                dents = os.listdir(self.importdir)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
                if len(dents) == 1 and os.path.isdir(self.importdir + "/" +
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
                                                     dents[0]):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
                    self.importdir = self.importdir + "/" + dents[0]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
            except:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    68
                self.cleanup()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    69
                raise
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
    def cleanup(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
        if not (self.tmpdir is None):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
            util.safeexec("rm", ["-rf", self.tmpdir])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
            self.tmpdir = None
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
    def updateimportfiles(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    77
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
            print "Scanning upstream tree..."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
        self.importfiles = util.maketree(self.importdir)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
    def updatewcfiles(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
            print "Scanning working copy tree..."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    84
        self.wcfiles = self.wcobj.gettree()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
    def update(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
        self.updatewcfiles()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
        self.updatechangedfiles()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
    def updatechangedfiles(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
            print "Calculating changes..."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
        wcfilehash = {}
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
        for x in self.wcfiles:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
            wcfilehash[x] = 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
        importfilehash = {}
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
        for x in self.importfiles:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
            importfilehash[x] = 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
        self.addedfiles = [x for x in self.importfiles if not wcfilehash.has_key(x)]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
        self.deletedfiles = [x for x in self.wcfiles if not importfilehash.has_key(x)]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   103
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   104
    def main(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
        def readloop():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
            for command in sys.stdin.readline().strip().split(','):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
                command = command.strip()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   108
                if command == 'q':
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
                    return 0
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
                if command == 'r':
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   111
                    return 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
                src, dest = command.split(' ')
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
                src = int(src, 16)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
                dest = int(dest, 16)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
                self.mv(self.deletedfiles[src], self.addedfiles[dest])
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
            return 1
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
        self.updateimportfiles()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   119
        needsupdate = 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   120
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   121
        while 1:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   122
            self.update()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
            if self.wcobj.fsonly:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   124
                # Don't show this interface if we're not talking to the VCS
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
                break
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
            if not (len(self.addedfiles) and len(self.deletedfiles)):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
                # Just ran update; don't do it again.
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   128
                needsupdate = 0
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
                break
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
            counter = 0
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
            print "%3s %-35s %3s %-35s" % ('Num', 'Source Files', 'Num',
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   133
                                             'Destination Files',)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   134
            print "%s %s %s %s" % ("-" * 3, "-" * 35, "-" * 3, "-" * 35)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   135
            while counter < max(len(self.addedfiles), len(self.deletedfiles)):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   136
                addfile = ''
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   137
                delfile = ''
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   138
                if counter < len(self.addedfiles):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   139
                    addfile = self.addedfiles[counter]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   140
                if counter < len(self.deletedfiles):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   141
                    delfile = self.deletedfiles[counter]
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   142
                print "%3x %-35s %3x %-35s" % (counter, delfile, counter, addfile)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   143
                counter += 1
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   144
            print "Syntax: src dest [,src dest [,...]] to move, q to accept, r to redraw:"
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   145
            sys.stdout.write("Command: ")
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   146
            sys.stdout.flush()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   147
            try:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   148
                if not readloop():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   149
                    break
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   150
            except ValueError:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   151
                print "Error handling input; please try again."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   152
            except IndexError:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   153
                print "Error handling input; please try again."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   154
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   155
        self.catchup(needsupdate)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   156
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   157
    def catchup(self, needsupdate = 1):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   158
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   159
            print " *** Processing changes."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   160
        if needsupdate:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   161
            self.update()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   162
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   163
            print "Deleting %d files" % len(self.deletedfiles)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   164
        if isdarcs():
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   165
            for file in util.sorttree(self.deletedfiles, filesfirst = True):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   166
                self.delfile(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   167
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   168
            for file in self.deletedfiles:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   169
                self.delfile(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   170
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   171
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   172
            print "Copying upstream directory to working copy..."
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   173
        util.copyfrom(self.importdir, self.wcobj.wcpath)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   174
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   175
        if self.verb:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   176
            print "Adding %d files" % len(self.addedfiles)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   177
        self.addedfiles.sort() # Make sure top-level dirs added before files
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   178
        for file in self.addedfiles:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   179
            self.addfile(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   180
        self.writelog()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   181
        if self.docommit:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   182
            self.wcobj.commit()
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   183
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   184
    def writelog(self):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   185
        logtext = ""
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   186
        if not (self.importfile is None):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   187
            importname = self.importfile
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   188
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   189
            importname = self.importdir
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   190
            
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   191
        if self.summary:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   192
            summary = self.summary
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   193
        else:
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   194
            summary = "Imported %s" % os.path.basename(importname)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   195
        logtext += "Imported %s\ninto %s\n\n" % \
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   196
                   (os.path.basename(importname),
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   197
                   self.wcobj.gettreeversion())
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   198
        logtext += self.log
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   199
        self.wcobj.makelog(summary, logtext)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   200
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   201
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   202
    def addfile(self, file):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   203
        self.wcobj.addtag(file)
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
    def delfile(self, file):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   206
        self.wcobj.deltag(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   207
        self.wcobj.delfile(file)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   208
    
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   209
        
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   210
    def mv(self, src, dest):
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   211
        print "%s -> %s" % (src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   212
        self.wcobj.movefile(src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   213
        self.wcobj.movetag(src, dest)
e8262ca32109 Add vcs-load-dirs project to thirdparty directory.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   214