summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index cbf0decc..f573b980 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16import netrc
16from optparse import SUPPRESS_HELP 17from optparse import SUPPRESS_HELP
17import os 18import os
18import re 19import re
@@ -21,6 +22,7 @@ import socket
21import subprocess 22import subprocess
22import sys 23import sys
23import time 24import time
25import urlparse
24import xmlrpclib 26import xmlrpclib
25 27
26try: 28try:
@@ -81,6 +83,18 @@ build as specified by the manifest-server element in the current
81manifest. The -t/--smart-tag option is similar and allows you to 83manifest. The -t/--smart-tag option is similar and allows you to
82specify a custom tag/label. 84specify a custom tag/label.
83 85
86The -u/--manifest-server-username and -p/--manifest-server-password
87options can be used to specify a username and password to authenticate
88with the manifest server when using the -s or -t option.
89
90If -u and -p are not specified when using the -s or -t option, '%prog'
91will attempt to read authentication credentials for the manifest server
92from the user's .netrc file.
93
94'%prog' will not use authentication credentials from -u/-p or .netrc
95if the manifest server specified in the manifest file already includes
96credentials.
97
84The -f/--force-broken option can be used to proceed with syncing 98The -f/--force-broken option can be used to proceed with syncing
85other projects if a project sync fails. 99other projects if a project sync fails.
86 100
@@ -157,6 +171,12 @@ later is required to fix a server side protocol bug.
157 p.add_option('-t', '--smart-tag', 171 p.add_option('-t', '--smart-tag',
158 dest='smart_tag', action='store', 172 dest='smart_tag', action='store',
159 help='smart sync using manifest from a known tag') 173 help='smart sync using manifest from a known tag')
174 p.add_option('-u', '--manifest-server-username', action='store',
175 dest='manifest_server_username',
176 help='username to authenticate with the manifest server')
177 p.add_option('-p', '--manifest-server-password', action='store',
178 dest='manifest_server_password',
179 help='password to authenticate with the manifest server')
160 180
161 g = p.add_option_group('repo Version options') 181 g = p.add_option_group('repo Version options')
162 g.add_option('--no-repo-verify', 182 g.add_option('--no-repo-verify',
@@ -356,6 +376,14 @@ uncommitted changes are present' % project.relpath
356 if opt.manifest_name and opt.smart_tag: 376 if opt.manifest_name and opt.smart_tag:
357 print >>sys.stderr, 'error: cannot combine -m and -t' 377 print >>sys.stderr, 'error: cannot combine -m and -t'
358 sys.exit(1) 378 sys.exit(1)
379 if opt.manifest_server_username or opt.manifest_server_password:
380 if not (opt.smart_sync or opt.smart_tag):
381 print >>sys.stderr, 'error: -u and -p may only be combined with ' \
382 '-s or -t'
383 sys.exit(1)
384 if None in [opt.manifest_server_username, opt.manifest_server_password]:
385 print >>sys.stderr, 'error: both -u and -p must be given'
386 sys.exit(1)
359 387
360 if opt.manifest_name: 388 if opt.manifest_name:
361 self.manifest.Override(opt.manifest_name) 389 self.manifest.Override(opt.manifest_name)
@@ -365,8 +393,41 @@ uncommitted changes are present' % project.relpath
365 print >>sys.stderr, \ 393 print >>sys.stderr, \
366 'error: cannot smart sync: no manifest server defined in manifest' 394 'error: cannot smart sync: no manifest server defined in manifest'
367 sys.exit(1) 395 sys.exit(1)
396
397 manifest_server = self.manifest.manifest_server
398
399 if not '@' in manifest_server:
400 username = None
401 password = None
402 if opt.manifest_server_username and opt.manifest_server_password:
403 username = opt.manifest_server_username
404 password = opt.manifest_server_password
405 else:
406 try:
407 info = netrc.netrc()
408 except IOError:
409 print >>sys.stderr, '.netrc file does not exist or could not be opened'
410 else:
411 try:
412 parse_result = urlparse.urlparse(manifest_server)
413 if parse_result.hostname:
414 username, _account, password = \
415 info.authenticators(parse_result.hostname)
416 except TypeError:
417 # TypeError is raised when the given hostname is not present
418 # in the .netrc file.
419 print >>sys.stderr, 'No credentials found for %s in .netrc' % \
420 parse_result.hostname
421 except netrc.NetrcParseError, e:
422 print >>sys.stderr, 'Error parsing .netrc file: %s' % e
423
424 if (username and password):
425 manifest_server = manifest_server.replace('://', '://%s:%s@' %
426 (username, password),
427 1)
428
368 try: 429 try:
369 server = xmlrpclib.Server(self.manifest.manifest_server) 430 server = xmlrpclib.Server(manifest_server)
370 if opt.smart_sync: 431 if opt.smart_sync:
371 p = self.manifest.manifestProject 432 p = self.manifest.manifestProject
372 b = p.GetBranch(p.CurrentBranch) 433 b = p.GetBranch(p.CurrentBranch)