1 |
commit: 28bb54f8d527979ad56375b73f70a43a28429755 |
2 |
Author: Chris Reffett <creffett <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Feb 8 04:02:18 2014 +0000 |
4 |
Commit: Chris Reffett <creffett <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Feb 8 04:02:18 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=28bb54f8 |
7 |
|
8 |
Add exists() and new() functions, make sync() private and add new sync |
9 |
pointing either to new() or _sync(). |
10 |
|
11 |
--- |
12 |
pym/portage/sync/modules/git/git.py | 109 +++++++++++++++++++++++++----------- |
13 |
1 file changed, 75 insertions(+), 34 deletions(-) |
14 |
|
15 |
diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py |
16 |
index 0c75dc7..833d7d9 100644 |
17 |
--- a/pym/portage/sync/modules/git/git.py |
18 |
+++ b/pym/portage/sync/modules/git/git.py |
19 |
@@ -51,7 +51,71 @@ class GitSync(object): |
20 |
self.repo = self.options.get('repo', None) |
21 |
self.xterm_titles = self.options.get('xterm_titles', False) |
22 |
|
23 |
+ |
24 |
+ def exists(self, **kwargs): |
25 |
+ '''Tests whether the repo actually exists''' |
26 |
+ if kwargs: |
27 |
+ self._kwargs(kwargs) |
28 |
+ elif not self.repo: |
29 |
+ return False |
30 |
+ spawn_kwargs = self.options.get('spawn_kwargs', None) |
31 |
+ |
32 |
+ if not os.path.exists(self.repo.location): |
33 |
+ return False |
34 |
+ exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\ |
35 |
+ (portage._shell_quote(self.repo.location),), |
36 |
+ **portage._native_kwargs(spawn_kwargs)) |
37 |
+ if exitcode == 128: |
38 |
+ return False |
39 |
+ return True |
40 |
+ |
41 |
+ |
42 |
def sync(self, **kwargs): |
43 |
+ '''Sync/Clone the repository''' |
44 |
+ if kwargs: |
45 |
+ self._kwargs(kwargs) |
46 |
+ |
47 |
+ if not self.has_git: |
48 |
+ return (1, False) |
49 |
+ |
50 |
+ if not self.exists(): |
51 |
+ return self.new() |
52 |
+ return self._sync() |
53 |
+ |
54 |
+ |
55 |
+ def new(self, **kwargs): |
56 |
+ '''Do the initial clone of the repository''' |
57 |
+ if kwargs: |
58 |
+ self._kwargs(kwargs) |
59 |
+ emerge_config = self.options.get('emerge_config', None) |
60 |
+ spawn_kwargs = self.options.get('spawn_kwargs', None) |
61 |
+ portdb = self.options.get('portdb', None) |
62 |
+ try: |
63 |
+ if not os.path.exists(self.repo.location): |
64 |
+ os.makedirs(self.repo.location) |
65 |
+ self.logger(self.xterm_titles, |
66 |
+ 'Created new directory %s' % self.repo.location) |
67 |
+ except IOError: |
68 |
+ return (1, False) |
69 |
+ msg = ">>> Cloning git repository from upstream into %s..." % self.repo.location |
70 |
+ self.logger(self.xterm_titles, msg) |
71 |
+ writemsg_level(msg + "\n") |
72 |
+ exitcode = portage.process.spawn_bash("cd %s ; git clone %s ." % \ |
73 |
+ (portage._shell_quote(self.repo.location), |
74 |
+ portage._shell_quote(self.repo.sync_uri)), |
75 |
+ **portage._native_kwargs(spawn_kwargs)) |
76 |
+ if exitcode != os.EX_OK: |
77 |
+ msg = "!!! git clone error in %s" % self.repo.location |
78 |
+ self.logger(self.xterm_titles, msg) |
79 |
+ writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
80 |
+ return (exitcode, False) |
81 |
+ msg = ">>> Git clone successful" |
82 |
+ self.logger(self.xterm_titles, msg) |
83 |
+ writemsg_level(msg + "\n") |
84 |
+ return self.post_sync(portdb, self.repo.location, emerge_config) |
85 |
+ |
86 |
+ |
87 |
+ def _sync(self, **kwargs): |
88 |
''' Update existing git repository, and ignore the syncuri. We are |
89 |
going to trust the user and assume that the user is in the branch |
90 |
that he/she wants updated. We'll let the user manage branches with |
91 |
@@ -59,44 +123,22 @@ class GitSync(object): |
92 |
''' |
93 |
if kwargs: |
94 |
self._kwargs(kwargs) |
95 |
- emerge_config = self.options.get('emerge_config', None) |
96 |
- spawn_kwargs = self.options.get('spawn_kwargs', None) |
97 |
- portdb = self.options.get('portdb', None) |
98 |
- |
99 |
- if not self.has_git: |
100 |
- return self.repo.location, 1, False |
101 |
+ emerge_config = self.options.get('emerge_config', None) |
102 |
+ spawn_kwargs = self.options.get('spawn_kwargs', None) |
103 |
+ portdb = self.options.get('portdb', None) |
104 |
|
105 |
- # Test if the directory is a valid git repo, and run |
106 |
- # git clone if not |
107 |
- exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\ |
108 |
+ msg = ">>> Starting git pull in %s..." % self.repo.location |
109 |
+ self.logger(self.xterm_titles, msg) |
110 |
+ writemsg_level(msg + "\n") |
111 |
+ exitcode = portage.process.spawn_bash("cd %s ; git pull" % \ |
112 |
(portage._shell_quote(self.repo.location),), |
113 |
**portage._native_kwargs(spawn_kwargs)) |
114 |
- if exitcode == 128: |
115 |
- msg = "!!! Git repo does not already exist, cloning from upstream..." |
116 |
+ if exitcode != os.EX_OK: |
117 |
+ msg = "!!! git pull error in %s" % self.repo.location |
118 |
self.logger(self.xterm_titles, msg) |
119 |
- writemsg_level(msg + "\n") |
120 |
- exitcode = portage.process.spawn_bash("cd %s ; git clone %s ." % \ |
121 |
- (portage._shell_quote(self.repo.location), |
122 |
- portage._shell_quote(self.repo.sync_uri)), |
123 |
- **portage._native_kwargs(spawn_kwargs)) |
124 |
- if exitcode != os.EX_OK: |
125 |
- msg = "!!! git clone error in %s." % self.repo.location |
126 |
- self.logger(self.xterm_titles, msg) |
127 |
- writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
128 |
+ writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
129 |
return (exitcode, False) |
130 |
- else: |
131 |
- msg = ">>> Starting git pull in %s..." % self.repo.location |
132 |
- self.logger(self.xterm_titles, msg ) |
133 |
- writemsg_level(msg + "\n") |
134 |
- exitcode = portage.process.spawn_bash("cd %s ; git pull" % \ |
135 |
- (portage._shell_quote(self.repo.location),), |
136 |
- **portage._native_kwargs(spawn_kwargs)) |
137 |
- if exitcode != os.EX_OK: |
138 |
- msg = "!!! git pull error in %s." % self.repo.location |
139 |
- self.logger(self.xterm_titles, msg) |
140 |
- writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
141 |
- return (exitcode, False) |
142 |
- msg = ">>> Git pull in %s successful" % self.repo.location |
143 |
+ msg = ">>> Git pull successful" % self.repo.location |
144 |
self.logger(self.xterm_titles, msg) |
145 |
writemsg_level(msg + "\n") |
146 |
return self.post_sync(portdb, self.repo.location, emerge_config) |
147 |
@@ -119,4 +161,3 @@ class GitSync(object): |
148 |
if exitcode == os.EX_OK: |
149 |
updatecache_flg = True |
150 |
return (exitcode, updatecache_flg) |
151 |
- |