1 |
commit: d524b7285c973385c90e272829bda8b727cd5f54 |
2 |
Author: David Heidelberger <david.heidelberger <AT> ixit <DOT> cz> |
3 |
AuthorDate: Mon Jun 16 16:04:06 2014 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Tue Sep 30 00:42:26 2014 +0000 |
6 |
URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d524b728 |
7 |
|
8 |
portage/sync/modules: Add svn sync module |
9 |
|
10 |
Module submitted by: David Heidelberger |
11 |
edits by Brian Dolbec <dolsen>: |
12 |
Remove CheckSVNConfig class. |
13 |
Use the default CheckSyncConfig class instead. |
14 |
Copying the sync-cvs-repo option from the cvs module was incorrect and not needed. |
15 |
Fixed the new()'s spawn_bash(...) call. |
16 |
|
17 |
--- |
18 |
pym/portage/sync/modules/svn/__init__.py | 32 +++++++++++++ |
19 |
pym/portage/sync/modules/svn/svn.py | 81 ++++++++++++++++++++++++++++++++ |
20 |
2 files changed, 113 insertions(+) |
21 |
|
22 |
diff --git a/pym/portage/sync/modules/svn/__init__.py b/pym/portage/sync/modules/svn/__init__.py |
23 |
new file mode 100644 |
24 |
index 0000000..1fda55a |
25 |
--- /dev/null |
26 |
+++ b/pym/portage/sync/modules/svn/__init__.py |
27 |
@@ -0,0 +1,32 @@ |
28 |
+# Copyright 2014 Gentoo Foundation |
29 |
+# Distributed under the terms of the GNU General Public License v2 |
30 |
+ |
31 |
+"""SVN plug-in module for portage. |
32 |
+Performs a svn up on repositories |
33 |
+""" |
34 |
+ |
35 |
+ |
36 |
+from portage.localization import _ |
37 |
+from portage.sync.config_checks import CheckSyncConfig |
38 |
+from portage.util import writemsg_level |
39 |
+ |
40 |
+ |
41 |
+module_spec = { |
42 |
+ 'name': 'svn', |
43 |
+ 'description': __doc__, |
44 |
+ 'provides':{ |
45 |
+ 'svn-module': { |
46 |
+ 'name': "svn", |
47 |
+ 'class': "SVNSync", |
48 |
+ 'description': __doc__, |
49 |
+ 'functions': ['sync', 'new', 'exists'], |
50 |
+ 'func_desc': { |
51 |
+ 'sync': 'Performs a svn up on the repository', |
52 |
+ 'new': 'Creates the new repository at the specified location', |
53 |
+ 'exists': 'Returns a boolean of whether the specified dir ' + |
54 |
+ 'exists and is a valid SVN repository', |
55 |
+ }, |
56 |
+ 'validate_config': CheckSyncConfig, |
57 |
+ } |
58 |
+ } |
59 |
+} |
60 |
|
61 |
diff --git a/pym/portage/sync/modules/svn/svn.py b/pym/portage/sync/modules/svn/svn.py |
62 |
new file mode 100644 |
63 |
index 0000000..182a7ac |
64 |
--- /dev/null |
65 |
+++ b/pym/portage/sync/modules/svn/svn.py |
66 |
@@ -0,0 +1,81 @@ |
67 |
+# Copyright 1999-2014 Gentoo Foundation |
68 |
+# Distributed under the terms of the GNU General Public License v2 |
69 |
+ |
70 |
+import logging |
71 |
+import errno |
72 |
+ |
73 |
+import portage |
74 |
+from portage import os |
75 |
+from portage.util import writemsg_level |
76 |
+from portage.sync.syncbase import SyncBase |
77 |
+ |
78 |
+ |
79 |
+class SVNSync(SyncBase): |
80 |
+ '''SVN sync module''' |
81 |
+ |
82 |
+ short_desc = "Perform sync operations on SVN repositories" |
83 |
+ |
84 |
+ @staticmethod |
85 |
+ def name(): |
86 |
+ return "SVNSync" |
87 |
+ |
88 |
+ |
89 |
+ def __init__(self): |
90 |
+ SyncBase.__init__(self, "svn", "dev-vcs/subversion") |
91 |
+ |
92 |
+ |
93 |
+ def new(self, **kwargs): |
94 |
+ if kwargs: |
95 |
+ self._kwargs(kwargs) |
96 |
+ #initial checkout |
97 |
+ msg = ">>> Starting initial svn checkout with %s..." % self.repo.sync_uri |
98 |
+ self.logger(self.xterm_titles, msg) |
99 |
+ writemsg_level(msg + "\n") |
100 |
+ try: |
101 |
+ os.rmdir(self.repo.location) |
102 |
+ except OSError as e: |
103 |
+ if e.errno != errno.ENOENT: |
104 |
+ msg = "!!! existing '%s' directory; exiting." % self.repo.location |
105 |
+ self.logger(self.xterm_titles, msg) |
106 |
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR) |
107 |
+ return (1, False) |
108 |
+ del e |
109 |
+ svn_root = self.repo.sync_uri |
110 |
+ exitcode = portage.process.spawn_bash( |
111 |
+ "cd %s; exec svn %s" % |
112 |
+ (portage._shell_quote(os.path.dirname(self.repo.location)), |
113 |
+ portage._shell_quote(svn_root)), |
114 |
+ **portage._native_kwargs(self.spawn_kwargs)) |
115 |
+ if exitcode != os.EX_OK: |
116 |
+ msg = "!!! svn checkout error; exiting." |
117 |
+ self.logger(self.xterm_titles, msg) |
118 |
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR) |
119 |
+ return (exitcode, False) |
120 |
+ |
121 |
+ |
122 |
+ def _sync(self): |
123 |
+ """ |
124 |
+ Internal function to sync an existing SVN repository |
125 |
+ |
126 |
+ @return: tuple of return code (0=success), whether the cache |
127 |
+ needs to be updated |
128 |
+ @rtype: (int, bool) |
129 |
+ """ |
130 |
+ |
131 |
+ svn_root = self.repo.sync_uri |
132 |
+ |
133 |
+ if svn_root.startswith("svn://"): |
134 |
+ svn_root = svn_root[6:] |
135 |
+ #svn update |
136 |
+ msg = ">>> Starting svn update with %s..." % self.repo.sync_uri |
137 |
+ self.logger(self.xterm_titles, msg) |
138 |
+ writemsg_level(msg + "\n") |
139 |
+ exitcode = portage.process.spawn_bash( |
140 |
+ "cd %s; exec svn update" % \ |
141 |
+ (portage._shell_quote(self.repo.location),), |
142 |
+ **portage._native_kwargs(self.spawn_kwargs)) |
143 |
+ if exitcode != os.EX_OK: |
144 |
+ msg = "!!! svn update error; exiting." |
145 |
+ self.logger(self.xterm_titles, msg) |
146 |
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR) |
147 |
+ return (exitcode, False) |