Beispiel #1
0
 def untar(fnp, d):
     """ un pack compressed file, guessing format based on extention """
     if fnp.endswith(".tar.gz"):
         tar = tarfile.open(fnp, "r:gz")
     elif fnp.endswith(".tgz"):
         tar = tarfile.open(fnp, "r:gz")
     elif fnp.endswith(".tar.bz2"):
         tar = tarfile.open(fnp, "r:bz2")
     elif fnp.endswith(".tar"):
         tar = tarfile.open(fnp, "r")
     else:
         raise Exception("invalid file? " + fnp)
     print "untarring", CT.boldGreen(fnp), "to", CT.boldBlue(d)
     tar.extractall(d)
     tar.close()
Beispiel #2
0
 def untar(fnp, d):
     ''' un pack compressed file, guessing format based on extention '''
     if fnp.endswith(".tar.gz"):
         tar = tarfile.open(fnp, "r:gz")
     elif fnp.endswith(".tgz"):
         tar = tarfile.open(fnp, "r:gz")
     elif fnp.endswith(".tar.bz2"):
         tar = tarfile.open(fnp, "r:bz2")
     elif fnp.endswith(".tar"):
         tar = tarfile.open(fnp, "r")
     else:
         raise Exception("invalid file? " + fnp)
     print "untarring", CT.boldGreen(fnp), "to", CT.boldBlue(d)
     tar.extractall(d)
     tar.close()
Beispiel #3
0
 def get_file_if_size_diff(url, d):
     """only download the file if it's needed, not completely fail proof since it is 
     just a size check but fairly likely not to be the same for a difference """
     fn = url.split("/")[-1]
     out_fnp = os.path.join(d, fn)
     net_file_size = int(urllib.urlopen(url).info()["Content-Length"])
     if os.path.exists(out_fnp):
         fn_size = os.path.getsize(out_fnp)
         if fn_size == net_file_size:
             print "skipping download of", CT.boldGreen(fn)
             return out_fnp
         else:
             print "files sizes differed:", "on disk:", fn_size, "from net:", net_file_size
     print "retrieving", CT.boldGreen(fn), "from", CT.boldBlue(url)
     urllib.urlretrieve(url, out_fnp)
     return out_fnp
Beispiel #4
0
 def get_file_if_size_diff(url, d):
     '''only download the file if it's needed, not completely fail proof since it is 
     just a size check but fairly likely not to be the same for a difference '''
     fn = url.split('/')[-1]
     out_fnp = os.path.join(d, fn)
     net_file_size = int(urllib.urlopen(url).info()['Content-Length'])
     if os.path.exists(out_fnp):
         fn_size = os.path.getsize(out_fnp)
         if fn_size == net_file_size:
             print "skipping download of", CT.boldGreen(fn)
             return out_fnp
         else:
             print "files sizes differed:", "on disk:", fn_size, "from net:", net_file_size
     print "retrieving", CT.boldGreen(fn), "from", CT.boldBlue(url)
     urllib.urlretrieve(url, out_fnp)
     return out_fnp