diff options
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index cbf0decc..b75bedc1 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 | ||
16 | import netrc | ||
16 | from optparse import SUPPRESS_HELP | 17 | from optparse import SUPPRESS_HELP |
17 | import os | 18 | import os |
18 | import re | 19 | import re |
@@ -21,6 +22,7 @@ import socket | |||
21 | import subprocess | 22 | import subprocess |
22 | import sys | 23 | import sys |
23 | import time | 24 | import time |
25 | import urlparse | ||
24 | import xmlrpclib | 26 | import xmlrpclib |
25 | 27 | ||
26 | try: | 28 | try: |
@@ -365,8 +367,34 @@ uncommitted changes are present' % project.relpath | |||
365 | print >>sys.stderr, \ | 367 | print >>sys.stderr, \ |
366 | 'error: cannot smart sync: no manifest server defined in manifest' | 368 | 'error: cannot smart sync: no manifest server defined in manifest' |
367 | sys.exit(1) | 369 | sys.exit(1) |
370 | |||
371 | manifest_server = self.manifest.manifest_server | ||
372 | if not '@' in manifest_server: | ||
373 | try: | ||
374 | info = netrc.netrc() | ||
375 | except IOError: | ||
376 | print >>sys.stderr, '.netrc file does not exist or could not be opened' | ||
377 | else: | ||
378 | try: | ||
379 | parse_result = urlparse.urlparse(manifest_server) | ||
380 | if parse_result.hostname: | ||
381 | username, _account, password = \ | ||
382 | info.authenticators(parse_result.hostname) | ||
383 | except TypeError: | ||
384 | # TypeError is raised when the given hostname is not present | ||
385 | # in the .netrc file. | ||
386 | print >>sys.stderr, 'No credentials found for %s in .netrc' % \ | ||
387 | parse_result.hostname | ||
388 | except netrc.NetrcParseError as e: | ||
389 | print >>sys.stderr, 'Error parsing .netrc file: %s' % e | ||
390 | else: | ||
391 | if (username and password): | ||
392 | manifest_server = manifest_server.replace('://', '://%s:%s@' % | ||
393 | (username, password), | ||
394 | 1) | ||
395 | |||
368 | try: | 396 | try: |
369 | server = xmlrpclib.Server(self.manifest.manifest_server) | 397 | server = xmlrpclib.Server(manifest_server) |
370 | if opt.smart_sync: | 398 | if opt.smart_sync: |
371 | p = self.manifest.manifestProject | 399 | p = self.manifest.manifestProject |
372 | b = p.GetBranch(p.CurrentBranch) | 400 | b = p.GetBranch(p.CurrentBranch) |