diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 77 |
1 files changed, 44 insertions, 33 deletions
@@ -24,6 +24,11 @@ import sys | |||
24 | import time | 24 | import time |
25 | import urllib2 | 25 | import urllib2 |
26 | 26 | ||
27 | try: | ||
28 | import threading as _threading | ||
29 | except ImportError: | ||
30 | import dummy_threading as _threading | ||
31 | |||
27 | from color import Coloring | 32 | from color import Coloring |
28 | from git_command import GitCommand | 33 | from git_command import GitCommand |
29 | from git_config import GitConfig, IsId, GetSchemeFromUrl | 34 | from git_config import GitConfig, IsId, GetSchemeFromUrl |
@@ -34,6 +39,8 @@ from progress import Progress | |||
34 | 39 | ||
35 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 40 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M |
36 | 41 | ||
42 | _urllib_lock = _threading.Lock() | ||
43 | |||
37 | def _lwrite(path, content): | 44 | def _lwrite(path, content): |
38 | lock = '%s.lock' % path | 45 | lock = '%s.lock' % path |
39 | 46 | ||
@@ -1458,40 +1465,44 @@ class Project(object): | |||
1458 | dest.seek(0, os.SEEK_END) | 1465 | dest.seek(0, os.SEEK_END) |
1459 | pos = dest.tell() | 1466 | pos = dest.tell() |
1460 | 1467 | ||
1461 | req = urllib2.Request(srcUrl) | 1468 | _urllib_lock.acquire() |
1462 | if pos > 0: | ||
1463 | req.add_header('Range', 'bytes=%d-' % pos) | ||
1464 | |||
1465 | try: | 1469 | try: |
1466 | r = urllib2.urlopen(req) | 1470 | req = urllib2.Request(srcUrl) |
1467 | except urllib2.HTTPError, e: | 1471 | if pos > 0: |
1468 | def _content_type(): | 1472 | req.add_header('Range', 'bytes=%d-' % pos) |
1469 | try: | 1473 | |
1470 | return e.info()['content-type'] | 1474 | try: |
1471 | except: | 1475 | r = urllib2.urlopen(req) |
1472 | return None | 1476 | except urllib2.HTTPError, e: |
1473 | 1477 | def _content_type(): | |
1474 | if e.code == 404: | 1478 | try: |
1475 | keep = False | 1479 | return e.info()['content-type'] |
1476 | return False | 1480 | except: |
1477 | elif _content_type() == 'text/plain': | 1481 | return None |
1478 | try: | 1482 | |
1479 | msg = e.read() | 1483 | if e.code == 404: |
1480 | if len(msg) > 0 and msg[-1] == '\n': | 1484 | keep = False |
1481 | msg = msg[0:-1] | 1485 | return False |
1482 | msg = ' (%s)' % msg | 1486 | elif _content_type() == 'text/plain': |
1483 | except: | 1487 | try: |
1484 | msg = '' | 1488 | msg = e.read() |
1485 | else: | 1489 | if len(msg) > 0 and msg[-1] == '\n': |
1486 | try: | 1490 | msg = msg[0:-1] |
1487 | from BaseHTTPServer import BaseHTTPRequestHandler | 1491 | msg = ' (%s)' % msg |
1488 | res = BaseHTTPRequestHandler.responses[e.code] | 1492 | except: |
1489 | msg = ' (%s: %s)' % (res[0], res[1]) | 1493 | msg = '' |
1490 | except: | 1494 | else: |
1491 | msg = '' | 1495 | try: |
1492 | raise DownloadError('HTTP %s%s' % (e.code, msg)) | 1496 | from BaseHTTPServer import BaseHTTPRequestHandler |
1493 | except urllib2.URLError, e: | 1497 | res = BaseHTTPRequestHandler.responses[e.code] |
1494 | raise DownloadError('%s: %s ' % (req.get_host(), str(e))) | 1498 | msg = ' (%s: %s)' % (res[0], res[1]) |
1499 | except: | ||
1500 | msg = '' | ||
1501 | raise DownloadError('HTTP %s%s' % (e.code, msg)) | ||
1502 | except urllib2.URLError, e: | ||
1503 | raise DownloadError('%s: %s ' % (req.get_host(), str(e))) | ||
1504 | finally: | ||
1505 | _urllib_lock.release() | ||
1495 | 1506 | ||
1496 | p = None | 1507 | p = None |
1497 | try: | 1508 | try: |