Changeset c49e500 in rtems-source-builder
- Timestamp:
- 07/29/14 00:04:55 (8 years ago)
- Branches:
- 4.10, 4.11, 4.9, 5, master
- Children:
- a083b52
- Parents:
- 4837350
- Location:
- source-builder/sb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source-builder/sb/download.py
r4837350 rc49e500 34 34 import log 35 35 import path 36 37 def _humanize_bytes(bytes, precision = 1): 38 abbrevs = ( 39 (1 << 50L, 'PB'), 40 (1 << 40L, 'TB'), 41 (1 << 30L, 'GB'), 42 (1 << 20L, 'MB'), 43 (1 << 10L, 'kB'), 44 (1, ' bytes') 45 ) 46 if bytes == 1: 47 return '1 byte' 48 for factor, suffix in abbrevs: 49 if bytes >= factor: 50 break 51 return '%.*f%s' % (precision, float(bytes) / factor, suffix) 36 52 37 53 def _http_parser(source, config, opts): … … 175 191 if url.startswith('https://api.github.com'): 176 192 url = urlparse.urljoin(url, config.expand('tarball/%{version}')) 177 log.notice('download: %s -> %s' % (url, os.path.relpath(path.host(local)))) 193 dst = os.path.relpath(path.host(local)) 194 log.notice('download: %s -> %s' % (url, dst)) 178 195 failed = False 179 196 if not opts.dry_run(): 180 197 _in = None 181 198 _out = None 199 _length = None 200 _have = 0 201 _chunk_size = 256 * 1024 202 _chunk = None 203 _last_percent = 200.0 204 _last_msg = '' 205 _wipe_output = False 182 206 try: 183 _in = urllib2.urlopen(url) 184 _out = open(path.host(local), 'wb') 185 _out.write(_in.read()) 207 try: 208 _in = urllib2.urlopen(url) 209 _out = open(path.host(local), 'wb') 210 try: 211 _length = int(_in.info().getheader('Content-Length').strip()) 212 except: 213 pass 214 while True: 215 _msg = '\rdownloading: %s - %s ' % (dst, _humanize_bytes(_have)) 216 if _length: 217 _percent = round((float(_have) / _length) * 100, 2) 218 if _percent != _last_percent: 219 _msg += 'of %s (%0.0f%%) ' % (_humanize_bytes(_length), _percent) 220 if _msg != _last_msg: 221 extras = (len(_last_msg) - len(_msg)) 222 log.stdout_raw('%s%s' % (_msg, ' ' * extras + '\b' * extras)) 223 _last_msg = _msg 224 _chunk = _in.read(_chunk_size) 225 if not _chunk: 226 break 227 _out.write(_chunk) 228 _have += len(_chunk) 229 if _wipe_output: 230 log.stdout_raw('\r%s\r' % (' ' * len(_last_msg))) 231 else: 232 log.stdout_raw('\n') 233 except: 234 log.stdout_raw('\n') 235 raise 186 236 except IOError, err: 187 237 log.notice('download: %s: error: %s' % (url, str(err))) -
source-builder/sb/log.py
r4837350 rc49e500 58 58 for l in text.replace(chr(13), '').splitlines(): 59 59 print l 60 61 def stdout_raw(text = os.linesep): 62 print text, 63 sys.stdout.flush() 60 64 61 65 def stderr(text = os.linesep, log = None):
Note: See TracChangeset
for help on using the changeset viewer.