thirdparty/vcs-load-dirs/vcs_support/commandver.py
changeset 2311 e8262ca32109
equal deleted inserted replaced
2310:d51331eaec15 2311:e8262ca32109
       
     1 # Copyright (C) 2003-2007 John Goerzen
       
     2 # <jgoerzen@complete.org>
       
     3 #
       
     4 #    This program is free software; you can redistribute it and/or modify
       
     5 #    it under the terms of the GNU General Public License as published by
       
     6 #    the Free Software Foundation; either version 2 of the License, or
       
     7 #    (at your option) any later version.
       
     8 #
       
     9 #    This program is distributed in the hope that it will be useful,
       
    10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 #    GNU General Public License for more details.
       
    13 #
       
    14 #    You should have received a copy of the GNU General Public License
       
    15 #    along with this program; if not, write to the Free Software
       
    16 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17 
       
    18 import util
       
    19 vcssyn = None
       
    20 vcsobj = None
       
    21 vcscmd = None
       
    22 darcs = False
       
    23 svk = False
       
    24 git = False
       
    25 hg = False
       
    26 
       
    27 def setscm(x):
       
    28     global darcs, svk, git, vcscmd, hg
       
    29     if (x == "darcs"):
       
    30         vcscmd = "darcs"
       
    31         darcs = True
       
    32     elif (x == "baz"):
       
    33         vcscmd = "baz"
       
    34     elif (x == "tla"):
       
    35         vcscmd = "tla"
       
    36     elif (x == "git"):
       
    37         vcscmd = "git"
       
    38         git = True
       
    39     elif (x == "hg"):
       
    40         vcscmd = "hg"
       
    41         hg = True
       
    42     elif (x == "svk"):
       
    43         vcscmd = "svk"
       
    44         svk = True
       
    45     else:
       
    46         print "Failed to determine VCS to use"
       
    47         sys.exit(2)
       
    48     print " VCSCMD: ", vcscmd
       
    49 
       
    50 def isdarcs():
       
    51     global darcs
       
    52     return darcs
       
    53 
       
    54 def issvk():
       
    55     global svk
       
    56     return svk
       
    57 
       
    58 def isgit():
       
    59     global git
       
    60     return git
       
    61 
       
    62 def ishg():
       
    63     global hg
       
    64     return hg
       
    65 
       
    66 def getvcssyntax():
       
    67     global vcssyn, vcsobj
       
    68     if vcssyn != None:
       
    69         return vcssyn
       
    70 
       
    71     if isdarcs():
       
    72         vcssyn = 'darcs'
       
    73         vcsobj = Darcs()
       
    74     elif ishg():
       
    75         vcssyn = 'hg'
       
    76         vcsobj = Hg()
       
    77     elif isgit():
       
    78         vcssyn = 'Git'
       
    79         vcsobj = Git()
       
    80     elif util.getstdoutsafeexec(vcscmd, ['-V'])[0].find('tla-1.0.') != -1:
       
    81         vcssyn = '1.0'
       
    82         vcsobj = Tla10()
       
    83     elif util.getstdoutsafeexec(vcscmd, ['-V'])[0].find('tla-1.1.') != -1:
       
    84         vcssyn = '1.1'
       
    85         vcsobj = Tla11()
       
    86     elif util.getstdoutsafeexec(vcscmd, ['-V'])[0].find('tla-1.3.') != -1:
       
    87         vcssyn = '1.3'
       
    88         vcsobj = Tla13()
       
    89     elif util.getstdoutsafeexec(vcscmd, ['-V'])[0].find('baz Bazaar version 1.4.') != -1:
       
    90         vcssyn = 'baz1.4'
       
    91         vcsobj = Baz14()        
       
    92     elif util.getstdoutsafeexec(vcscmd, ['-V'])[0].find('This is svk') != -1:
       
    93         vcssyn = 'svk'
       
    94         vcsobj = Svk()
       
    95     else:
       
    96         vcssyn = '1.3'
       
    97         vcsobj = Tla13()
       
    98     return vcssyn
       
    99 
       
   100 class Tla10:
       
   101     tagging_method = 'tagging-method'
       
   102     add = ['add-tag']
       
   103     move = 'move-tag'
       
   104     delete = ['delete-tag']
       
   105     update = 'update --in-place .'
       
   106     replay = 'replay --in-place .'
       
   107     commit = 'commit'
       
   108     importcmd = 'import'
       
   109 
       
   110 class Tla11:
       
   111     tagging_method = 'id-tagging-method'
       
   112     add = ['add']
       
   113     move = 'move'
       
   114     delete = ['delete']
       
   115     update = 'update'
       
   116     replay = 'replay'
       
   117     commit = 'commit'
       
   118     importcmd = 'import'
       
   119 
       
   120 class Tla13:
       
   121     tagging_method = 'id-tagging-method'
       
   122     add = ['add-id']
       
   123     move = 'move-id'
       
   124     delete = ['delete-id']
       
   125     update = 'update'
       
   126     replay = 'replay'
       
   127     commit = 'commit'
       
   128     importcmd = 'import'
       
   129 
       
   130 class Baz14:
       
   131     tagging_method = 'id-tagging-method'
       
   132     add = ['add-id']
       
   133     move = 'move-id'
       
   134     delete = ['delete-id']
       
   135     update = 'update'
       
   136     replay = 'replay'
       
   137     commit = 'commit'    
       
   138     importcmd = 'import'
       
   139 
       
   140 class Darcs:
       
   141     tagging_method = None
       
   142     add = ['add', '--case-ok']
       
   143     move = 'mv'
       
   144     delete = None
       
   145     update = 'pull'
       
   146     replay = 'pull'
       
   147     commit = 'record'
       
   148 
       
   149 class Hg:
       
   150     tagging_method = None
       
   151     add = ['add']
       
   152     move = 'mv'
       
   153     delete = None
       
   154     update = 'pull'
       
   155     replay = 'pull'
       
   156     commit = 'commit'
       
   157 
       
   158 class Git:
       
   159     tagging_method = None
       
   160     add = ['add']
       
   161     move = 'mv'
       
   162     delete = ['rm', '-r']
       
   163     update = 'checkout'
       
   164     replay = None 
       
   165     commit = 'commit'
       
   166 
       
   167 class Svk:
       
   168 	tagging_method = None
       
   169 	add = ['add']
       
   170 	move = 'mv'
       
   171 	delete = ['rm']
       
   172 	update = 'pull'
       
   173 	replay = 'pull'
       
   174 	commit = 'commit'
       
   175 
       
   176 def cmd():
       
   177     global vcsobj
       
   178     getvcssyntax()
       
   179     return vcsobj