Bug fix: Check that tarfile can be imported

This commit is contained in:
Kiooeht 2011-09-07 19:33:26 -07:00
parent 6a05bab45b
commit 2b9278d717

View file

@ -1,7 +1,11 @@
import urllib import urllib
import re import re
import time import time
import tarfile, zipfile try:
import tarfile
except:
tarfile = None
import zipfile
import os, sys, shutil import os, sys, shutil
USER_TYPE = "edge" USER_TYPE = "edge"
@ -127,7 +131,7 @@ def updateExtract(url, extension):
urllib.urlretrieve(url, fn) urllib.urlretrieve(url, fn)
else: else:
fn = urllib.urlretrieve(url)[0] fn = urllib.urlretrieve(url)[0]
if tarfile.is_tarfile(fn): if tarfile and tarfile.is_tarfile(fn):
extension = ".tar.gz" extension = ".tar.gz"
elif zipfile.is_zipfile(fn): elif zipfile.is_zipfile(fn):
extension = ".zip" extension = ".zip"
@ -148,9 +152,11 @@ def updateExtract(url, extension):
if extension == ".zip": if extension == ".zip":
from zipfile import is_zipfile as is_updatefile, ZipFile as openupdate from zipfile import is_zipfile as is_updatefile, ZipFile as openupdate
print "Opening .zip" print "Opening .zip"
elif extension.startswith(".tar"): elif tarfile and extension.startswith(".tar"):
from tarfile import is_tarfile as is_updatefile, open as openupdate from tarfile import is_tarfile as is_updatefile, open as openupdate
print "Opening .tar" print "Opening .tar"
else:
return
if is_updatefile(fn): if is_updatefile(fn):
update = openupdate(fn, 'r') update = openupdate(fn, 'r')