Skip to content

Commit

Permalink
Determine extract bundle type properly, clean up after downloading sy…
Browse files Browse the repository at this point in the history
…mbols path
  • Loading branch information
ahal-test committed Oct 26, 2011
1 parent 64bb1a4 commit 9a04539
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 12 additions & 6 deletions peptest/peputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@
import zipfile
import tarfile

def download(url, savepath=None):
def download(url, savepath=''):
"""
Save the file located at 'url' into 'savepath'
If savepath is None, use the last part of the url path.
Returns the path of the saved file.
"""
data = urllib2.urlopen(url)
if savepath is None:
if savepath == '' or os.path.isdir(savepath):
parsed = urlparse.urlsplit(url)
savepath = parsed.path[parsed.path.rfind('/')+1:]
filename = parsed.path[parsed.path.rfind('/')+1:]
savepath = os.path.join(savepath, filename)
savedir = os.path.dirname(savepath)
if savedir and not os.path.exists(savedir):
if savedir != '' and not os.path.exists(savedir):
os.makedirs(savedir)
outfile = open(savepath, 'wb')
outfile.write(data.read())
Expand All @@ -69,11 +70,14 @@ def extract(path, savedir=None, delete=False):
Takes in a tar or zip file and extracts it to savedir
If savedir is not specified, extracts to path
If delete is set to True, deletes the bundle at path
Returns the list of top level files that were extracted
"""
if path.endswith('.zip'):
if zipfile.is_zipfile(path):
bundle = zipfile.ZipFile(path)
elif path.endswith('.tar.gz') or path.endswith('.tar.bz2'):
namelist = bundle.namelist()
elif tarfile.is_tarfile(path):
bundle = tarfile.open(path)
namelist = bundle.getnames()
else:
return
if savedir is None:
Expand All @@ -84,3 +88,5 @@ def extract(path, savedir=None, delete=False):
bundle.close()
if delete:
os.remove(path)
return [os.path.join(savedir, name) for name in namelist
if len(name.rstrip(os.sep).split(os.sep)) == 1]
8 changes: 5 additions & 3 deletions peptest/runpeptests.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ def stop(self):
if os.path.exists(os.path.join(here, f)):
os.remove(os.path.join(here, f))

if os.path.exists(os.path.join(here, 'symbols')):
shutil.rmtree(os.path.join('symbols'))

# delete any minidumps that may have been created
dumpDir = os.path.join(self.profile.profile, 'minidumps')
if self.options.profilePath and os.path.exists(dumpDir):
Expand Down Expand Up @@ -225,6 +222,11 @@ def checkForCrashes(self, testName=None):
else:
self.logger.warning('No symbols_path or stackwalk path specified, can\'t process dump')
break

# if the symbols path was downloaded, cleanup after ourselves
if utils.isURL(self.options.symbolsPath):
if os.path.exists(symbolsPath):
shutil.rmtree(symbolsPath)
return foundCrash

class FirefoxPeptest(Peptest):
Expand Down

0 comments on commit 9a04539

Please sign in to comment.