/[gentoo-src]/portage/pym/sync/cvs.py
Gentoo

Contents of /portage/pym/sync/cvs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Sun Nov 7 14:38:39 2004 UTC (13 years, 7 months ago) by ferringb
Branch: MAIN
CVS Tags: portage_041204, HEAD
Branch point for: portage_2_1
Changes since 1.2: +1 -1 lines
File MIME type: text/x-python
header fixes.

1 # cvs.py; provides cvs sync capabilities, encapsulates the necessary cvs binary calls
2 # Copyright 2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 #$Header: /var/cvsroot/gentoo-src/portage/pym/sync/cvs.py,v 1.2 2004/11/07 14:06:53 ferringb Exp $
5
6 import os,portage_exec,stat
7 #import sync
8 import portage_const
9 import portage_exception
10
11 import sync.syncexceptions
12 class CVSIOError(sync.syncexceptions.SyncException):
13 def __init__(self,errmsg,command):
14 self.errmsg=errmsg
15 self.command=command
16 def __str__(self):
17 return "cvs error: command %s, %s" % (self.command, self.errmsg)
18
19 class CvsHost:
20 def __init__(self,host_uri,cvs_binary=portage_const.CVS_BIN):
21 if not os.access(cvs_binary, os.X_OK):
22 raise portage_exception.CommandNotFound(cvs_binary)
23 self.__binary=cvs_binary
24 #parse the bugger.
25 #new format.
26 #cvs://[CVS_RSH binary:]user@host:cvs_root:module
27 #example
28 #cvs://ssh:ferringb@dev.gentoo.org:/var/cvsroot:gentoo-x86
29 #old format
30 #cvs://user@host:cvsroot
31 #implicit gentoo-x86 module, and ext w/ ssh.
32 #here we go. :/
33
34 if host_uri.count(":") >= 2:
35 self.__init_new_host_uri(host_uri)
36 else:
37 self.__init_deprecated_uri(host_uri)
38
39 def __init_new_host_uri(self,host):
40 #cvs://ssh:ferringb@dev.gentoo.org:/var/cvsroot:gentoo-x86
41 s=host.split(":")
42 if len(s) == 4:
43 self.__ext=s.pop(0)
44 s[0] = ":ext:" + s[0]
45 else:
46 self.__ext=None
47 self.__cvsroot=s[0]+":"+s[1]
48 self.__cvsmodule=s[2]
49
50 def __init_deprecated_uri(self,host):
51 self.__ext="ssh"
52 self.__cvsmodule="gentoo-x86"
53 self.__cvsroot=host
54
55 def sync(self,local_path,verbosity=1,compress=False):
56 while local_path[-1] == "/":
57 local_path = local_path[:-1]
58 if compress:
59 c_arg='-z9'
60 else:
61 c_arg=''
62
63 env={}
64 if self.__ext:
65 env = {"CVS_RSH":self.__ext}
66
67 l=len(self.__cvsmodule)
68 if not os.path.exists(local_path):
69 newdir=os.path.basename(local_path)
70 basedir=local_path[:-len(newdir)]
71 if os.path.exists(basedir+"/"+self.__cvsmodule):
72 raise Exception("unable to checkout to %s, module directory %s exists already" % \
73 (basedir, self.__cvsmodule))
74 elif os.path.exists(basedir+"/CVS"):
75 raise Exception("unable to checkout to %s, a CVS directory exists w/in already" % basedir)
76 command="cd '%s' ; %s %s -d %s co -P %s" % \
77 (basedir, self.__binary, c_arg, self.__cvsroot, self.__cvsmodule)
78
79 ret=portage_exec.spawn_bash(command,env=env,opt_name="cvs co")
80 if ret:
81 raise CVSIOError("failed checkout",command)
82 if newdir != self.__cvsmodule:
83 ret = portage_exec.spawn(('mv','%s/%s' % (basedir,self.__cvsmodule),local_path))
84 if ret:
85 raise Exception("failed moving %s/%s to %s" % (basedir,self.__cvsmodule,local_path))
86 elif stat.S_ISDIR(os.stat(local_path).st_mode):
87
88 command="cd '%s'; %s %s -d %s up" % (local_path, self.__binary, c_arg,self.__cvsroot)
89 ret = portage_exec.spawn_bash(command, env=env,opt_name="cvs up")
90 if ret:
91 raise CVSIOError("failed updated", command)
92 else:
93 raise Exception("%s exists, and is not a directory. rectify please" % local_path)
94 return True
95

  ViewVC Help
Powered by ViewVC 1.1.20