Advertisement
Azelphur

Untitled

May 29th, 2011
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1.     def untar(self, tar_file, destination):
  2.         total_size = os.path.getsize(tar_file)
  3.  
  4.         class MyFileObj(file):
  5.             def read(self, size):
  6.                 status = "Extracting: %s (%s bytes) [%3.2f%%]" % (os.path.basename(tar_file), total_size, self.tell() * 100. / total_size)
  7.                 status = status + chr(8)*(len(status)+1)
  8.                 print(status, end="")
  9.                 sys.stdout.flush()
  10.                 return file.read(self, size)
  11.  
  12.         tar = tarfile.open(fileobj=MyFileObj(tar_file))
  13.         tar.extractall(destination)
  14.         num_files = len(tar.getmembers())
  15.         tar.close()
  16.         return num_files
  17.  
  18.  
  19.  
  20. Traceback (most recent call last):
  21.   File "./manage.py", line 32, in <module>
  22.     main()
  23.   File "./manage.py", line 22, in main
  24.     addon.get(args[2], args[3])
  25.   File "/home/srcds/newservers/libmanage.py", line 83, in get
  26.     num_files = self.untar(file_path, ADDONS+name+'/')
  27.   File "/home/srcds/newservers/libmanage.py", line 128, in untar
  28.     class MyFileObj(file):
  29. NameError: global name 'file' is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement