Statistics
| Revision:

root / branches / v2_0_0_prep / dist-utils / scripts / svn-copy-tag @ 30602

History | View | Annotate | Download (2.79 KB)

1
#!/usr/bin/python
2

    
3
from svn_utils import *
4
import sys
5
import os
6

    
7
from os import path
8

    
9
def usage():
10
  print """
11
Copy the contents of a tag/branch to a new one
12

    
13
If enviroment var '%(env_name)s' isn't set
14
it use like gvSIG svn root this URL:
15
%(defalut_root)s
16
the current is:
17
%(cur_root)s
18

    
19
usage:
20
  %(command)s source traget message
21
  
22
  - source: Source path of copy relative
23
            to root
24

    
25
  - target: Source path of copy relative
26
            to root
27
   
28
  - message: Message to use in the operations
29

    
30
examples:
31
  
32
  %(command)s branches/v10 tags/tmp_build pre_v1_1_1_Build_1017
33

    
34
  %(command)s trunk tags/tmp_build pre_v1_2_Build_1203
35

    
36
""" % {
37
    "env_name":gvSIG_svn_root_env_name,
38
    "defalut_root":gvSIG_svn_default_root,
39
    "cur_root":get_gvSIG_SVN_root(),
40
    "command":sys.argv[0]
41
}
42

    
43
def checks():
44
  if len(sys.argv) != 4:
45
    return False
46
  return True
47

    
48
def run():
49
  if not checks():
50
    usage()
51
    exit(1)
52
  svnRoot = get_gvSIG_SVN_root()
53
  print "gvSIG svn root: %s" % svnRoot
54

    
55
  client = getSVNClient()
56
     
57
  logMsg = str(sys.argv[3])
58
  src = sys.argv[1]
59
  srcURL = "/".join((svnRoot,src))
60
  def logMsgCallback():
61
    return True,str(logMsg)
62
  client.callback_get_log_message = logMsgCallback
63

    
64
  trg = sys.argv[2]
65
  #trgName = "tmp_build"
66
  #trgNameStr = trgName
67
  trgURL = "/".join((svnRoot,trg))
68
  trgType,trgName = branchTypeAndName(svnRoot,trgURL)
69
  tagsForlderURL = "/".join((svnRoot,trgType))
70

    
71
  print "Checks for an existing %s..." % trg
72
  entries = client.ls(tagsForlderURL)
73
  for entry in entries:
74
    if entry["name"] == trgURL:
75
      existsTrg = True
76
      break
77
  else:
78
    existsTrg = False
79

    
80

    
81
  if existsTrg:
82
    msgs = client.log(trgURL,strict_node_history=True,limit=5) 
83
    print trg + " found!!! this is the last five logs:"
84
    print formatSvnLogForPrint(msgs)
85
    print "\n\n"
86
    yesNo = raw_input("Continue and remove this tag (y/n)?")
87
    if not yesNo.strip().lower().startswith("y"):
88
      print "** Aborted by user **"
89
      exit(1)
90

    
91
    print "Removing %s ..." % trgURL
92
    client.remove(trgURL)
93
  else:
94
    print "Source: %s" % srcURL
95
    print "Target: %s" % trgURL
96
    print "Message: %s" % logMsg
97
    yesNo = raw_input("It's correct? ,Continue (y/n)?")
98
    if not yesNo.strip().lower().startswith("y"):
99
      print "** Aborted by user **"
100
      exit(1)
101

    
102
    
103
  print "Creating %s...." % trg
104
  client.mkdir(trgURL,logMsg)
105

    
106

    
107
  print "Indentify proyects to copy...."
108
  entries = client.ls(srcURL)
109
  dirsToCopy = [entry["name"].split("/")[-1] for entry in entries]
110
  for adir in dirsToCopy:
111
    print "  - %s" % adir
112

    
113

    
114
  print "\nStart make copy..."
115
  for adir in dirsToCopy:
116
    tmpSrcDir = "/".join((srcURL,adir))
117
    tmpTrgDir = "/".join((trgURL,adir))
118
    print "%s --> %s" % (tmpSrcDir,tmpTrgDir)
119
    client.copy(tmpSrcDir,tmpTrgDir)
120

    
121
  print "\nFinish... OK"
122
  exit(0)
123

    
124

    
125
if __name__=="__main__":
126
  run()