diff options
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index ceb81eaa..deff171a 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -17,9 +17,11 @@ from optparse import SUPPRESS_HELP | |||
17 | import os | 17 | import os |
18 | import re | 18 | import re |
19 | import shutil | 19 | import shutil |
20 | import socket | ||
20 | import subprocess | 21 | import subprocess |
21 | import sys | 22 | import sys |
22 | import time | 23 | import time |
24 | import xmlrpclib | ||
23 | 25 | ||
24 | from git_command import GIT | 26 | from git_command import GIT |
25 | from project import HEAD | 27 | from project import HEAD |
@@ -57,6 +59,10 @@ back to the manifest revision. This option is especially helpful | |||
57 | if the project is currently on a topic branch, but the manifest | 59 | if the project is currently on a topic branch, but the manifest |
58 | revision is temporarily needed. | 60 | revision is temporarily needed. |
59 | 61 | ||
62 | The -s/--smart-sync option can be used to sync to a known good | ||
63 | build as specified by the manifest-server element in the current | ||
64 | manifest. | ||
65 | |||
60 | SSH Connections | 66 | SSH Connections |
61 | --------------- | 67 | --------------- |
62 | 68 | ||
@@ -97,6 +103,9 @@ later is required to fix a server side protocol bug. | |||
97 | p.add_option('-d','--detach', | 103 | p.add_option('-d','--detach', |
98 | dest='detach_head', action='store_true', | 104 | dest='detach_head', action='store_true', |
99 | help='detach projects back to manifest revision') | 105 | help='detach projects back to manifest revision') |
106 | p.add_option('-s', '--smart-sync', | ||
107 | dest='smart_sync', action='store_true', | ||
108 | help='smart sync using manifest from a known good build') | ||
100 | 109 | ||
101 | g = p.add_option_group('repo Version options') | 110 | g = p.add_option_group('repo Version options') |
102 | g.add_option('--no-repo-verify', | 111 | g.add_option('--no-repo-verify', |
@@ -182,6 +191,49 @@ uncommitted changes are present' % project.relpath | |||
182 | print >>sys.stderr, 'error: cannot combine -n and -l' | 191 | print >>sys.stderr, 'error: cannot combine -n and -l' |
183 | sys.exit(1) | 192 | sys.exit(1) |
184 | 193 | ||
194 | if opt.smart_sync: | ||
195 | if not self.manifest.manifest_server: | ||
196 | print >>sys.stderr, \ | ||
197 | 'error: cannot smart sync: no manifest server defined in manifest' | ||
198 | sys.exit(1) | ||
199 | try: | ||
200 | server = xmlrpclib.Server(self.manifest.manifest_server) | ||
201 | p = self.manifest.manifestProject | ||
202 | b = p.GetBranch(p.CurrentBranch) | ||
203 | branch = b.merge | ||
204 | |||
205 | env = dict(os.environ) | ||
206 | if (env.has_key('TARGET_PRODUCT') and | ||
207 | env.has_key('TARGET_BUILD_VARIANT')): | ||
208 | target = '%s-%s' % (env['TARGET_PRODUCT'], | ||
209 | env['TARGET_BUILD_VARIANT']) | ||
210 | [success, manifest_str] = server.GetApprovedManifest(branch, target) | ||
211 | else: | ||
212 | [success, manifest_str] = server.GetApprovedManifest(branch) | ||
213 | |||
214 | if success: | ||
215 | manifest_name = "smart_sync_override.xml" | ||
216 | manifest_path = os.path.join(self.manifest.manifestProject.worktree, | ||
217 | manifest_name) | ||
218 | try: | ||
219 | f = open(manifest_path, 'w') | ||
220 | try: | ||
221 | f.write(manifest_str) | ||
222 | self.manifest.Override(manifest_name) | ||
223 | finally: | ||
224 | f.close() | ||
225 | except IOError: | ||
226 | print >>sys.stderr, 'error: cannot write manifest to %s' % \ | ||
227 | manifest_path | ||
228 | sys.exit(1) | ||
229 | else: | ||
230 | print >>sys.stderr, 'error: %s' % manifest_str | ||
231 | sys.exit(1) | ||
232 | except socket.error: | ||
233 | print >>sys.stderr, 'error: cannot connect to manifest server %s' % ( | ||
234 | self.manifest.manifest_server) | ||
235 | sys.exit(1) | ||
236 | |||
185 | rp = self.manifest.repoProject | 237 | rp = self.manifest.repoProject |
186 | rp.PreSync() | 238 | rp.PreSync() |
187 | 239 | ||