瀏覽代碼

add the 'download_file' command when setting up linux schroot environment

Ashish Kulkarni 11 年之前
父節點
當前提交
6eba9089a2
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      scripts/build.py

+ 9 - 0
scripts/build.py

@@ -595,6 +595,15 @@ def build_setup_schroot(config, basedir):
                 open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
             elif name == 'append_file':
                 open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
+            elif name == 'download_file':
+                name = command[1].split('/')[-1]
+                loc  = os.path.join(root_dir, command[2], name)
+                if exists(loc): os.remove(loc)
+                def hook(cnt, bs, total):
+                    pct = int(cnt*bs*100/total)
+                    message("\rDownloading: %s [%d%%]" % (name, pct))
+                urllib.urlretrieve(command[1], loc, reporthook=hook)
+                message("\rDownloaded: %s%s\n" % (name, ' '*10))
             elif name == 'schroot_conf':
                 cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
                 cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))