Debian Codegraph @

cvssync

raw symbols SCIP
1 #!/usr/bin/python3
2 # Runs under both Python 2 and Python 3: preserve this property!
3 # SPDX-License-Identifier: GPL-2.0+
4 """
5 cvssync - fetch a CVS repository using rsync
6
7 This tool is a front end for rsync that attempts to deduce how to get
8 a copy of a CVS repository by analyzing the arguments you are told
9 to pass CVS to check out a copy.
10
11 The magic (when there is any) is in knowing how to construct the
12 actual path to the repository from the host, path and module arguments.
13 """
14
15 # Hosting-site rules live inside the following function.
16
17 def computesource(sourcehost, sourcepath, sourcemodule):
18 "Compute an rsync source given a CVS sourcehost, sourcepath, and sourcemodule"
19 if "sourceforge" in sourcehost:
20 # Supply the /cvsroot path head if not given.
21 if not sourcepath.startswith("/cvsroot"):
22 sourcepath = "/cvsroot" + sourcepath
23 # Deal with the Sourceforge convention for naming project
24 # pseudohosts. This does it in a backwards-compatible way.
25 project = sourcepath.split("/")[-1]
26 if not sourcehost.startswith(project + "."):
27 sourcehost = project + "." + sourcehost
28 # On SourceForge you need to double the colon and strip the
29 # leading / to invoke the rsync module facility.
30 return "%s::%s/%s/" % (sourcehost, sourcepath[1:], sourcemodule)
31 elif "berlios" in sourcehost:
32 # The pattern is rsync -av cvs.berlios.de::<projectname>_cvs cvs
33 return "cvs.berlios.de::%s_cvs" % sourcemodule
34 elif "sourceware" in sourcehost:
35 # The pattern is rsync -av sourceware.org::<projectname>-cvs/<module>/
36 return "%s::%s-cvs/%s/" % (sourcehost, sourcepath.split('/')[2], sourcemodule)
37 elif "savannah" in sourcehost:
38 # Supply the /sources path head if not given.
39 if not sourcepath.startswith("/sources"):
40 sourcepath = "/sources" + sourcepath
41 return "rsync://cvs.savannah.gnu.org%s/%s/" % (sourcepath, sourcemodule)
42 elif not sourcehost:
43 return "%s/%s/" % (sourcepath, sourcemodule)
44 else:
45 return "%s:%s/%s/" % (sourcehost, sourcepath, sourcemodule)
46
47 # You should not need to modify anything below this line
48
49 import os, sys, getopt, subprocess
50
51 verbose = False
52 execute = True
53
54 def do_or_die(dcmd):
55 "Either execute a command or raise a fatal exception."
56 if verbose:
57 sys.stdout.write("cvssync: executing '%s'\n" % (dcmd,))
58 if execute:
59 try:
60 retcode = subprocess.call(dcmd, shell=True)
61 if retcode < 0:
62 sys.stderr.write("cvssync: child was terminated by signal %d.\n" % -retcode)
63 sys.exit(1)
64 elif retcode != 0:
65 sys.stderr.write("cvssync: child returned %d.\n" % retcode)
66 sys.exit(1)
67 except (OSError, IOError) as e:
68 sys.stderr.write("cvssync: execution of %s failed: %s\n" % (dcmd, e))
69 sys.exit(1)
70
71 if __name__ == '__main__':
72
73 (opts, arguments) = getopt.getopt(sys.argv[1:], "cno:v")
74 oopt = None
75 checkoutable = False
76 for (opt, arg) in opts:
77 if opt == '-c':
78 checkoutable = True
79 if opt == '-n':
80 execute = False
81 if opt == '-o':
82 oopt = arg
83 if opt == '-v':
84 verbose += 1
85
86 if len(arguments) == 1 and arguments[0].startswith("cvs://"):
87 try:
88 (host, module) = arguments[0][6:].split("#")
89 i = host.find('/')
90 (host, path) = (host[:i], host[i:])
91 if "@" in host:
92 host = host.split("@")[1]
93 except ValueError:
94 sys.stderr.write("cvssync: ill-formed CVS URL\n")
95 sys.exit(1)
96 elif len(arguments) == 2:
97 host = arguments[0]
98 module = arguments[1]
99 if "@" in host:
100 host = host.split("@")[1]
101 if ":" not in host:
102 sys.stderr.write("cvssync: repository path is missing.\n")
103 sys.exit(1)
104 (host, path) = host.split(":")
105 else:
106 sys.stderr.write("cvssync: requires a host/path and module argument\n")
107 sys.exit(1)
108
109 if verbose:
110 print("host = %s, path = %s, module = %s" % (host, path, module))
111
112 directory = oopt or module
113 vopt = "v" if verbose else ""
114
115 source = computesource(host, path, module)
116
117 if checkoutable:
118 if not os.path.exists(directory):
119 os.mkdir(directory)
120 dummyroot = os.path.join(directory, "CVSROOT")
121 if not os.path.exists(dummyroot):
122 os.mkdir(dummyroot)
123 directory = os.path.join(directory, module)
124
125 do_or_die("rsync -sa%sz '%s' '%s'" % (vopt, source, directory))
126
127 # end