Trac #7733: fix severe performance regression when creating ActivityBundle.
This commit is contained in:
parent
5ba227ff85
commit
1bd1b6c81e
@ -205,13 +205,13 @@ class ActivityBundle(Bundle):
|
|||||||
|
|
||||||
def get_locale_path(self):
|
def get_locale_path(self):
|
||||||
"""Get the locale path inside the (installed) activity bundle."""
|
"""Get the locale path inside the (installed) activity bundle."""
|
||||||
if not self._unpacked:
|
if self._zip_file is not None:
|
||||||
raise NotInstalledException
|
raise NotInstalledException
|
||||||
return os.path.join(self._path, 'locale')
|
return os.path.join(self._path, 'locale')
|
||||||
|
|
||||||
def get_icons_path(self):
|
def get_icons_path(self):
|
||||||
"""Get the icons path inside the (installed) activity bundle."""
|
"""Get the icons path inside the (installed) activity bundle."""
|
||||||
if not self._unpacked:
|
if self._zip_file is not None:
|
||||||
raise NotInstalledException
|
raise NotInstalledException
|
||||||
return os.path.join(self._path, 'icons')
|
return os.path.join(self._path, 'icons')
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ class ActivityBundle(Bundle):
|
|||||||
def get_icon(self):
|
def get_icon(self):
|
||||||
"""Get the activity icon name"""
|
"""Get the activity icon name"""
|
||||||
icon_path = os.path.join('activity', self._icon + '.svg')
|
icon_path = os.path.join('activity', self._icon + '.svg')
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
return os.path.join(self._path, icon_path)
|
return os.path.join(self._path, icon_path)
|
||||||
else:
|
else:
|
||||||
icon_data = self.get_file(icon_path).read()
|
icon_data = self.get_file(icon_path).read()
|
||||||
@ -365,7 +365,7 @@ class ActivityBundle(Bundle):
|
|||||||
raise RegistrationException
|
raise RegistrationException
|
||||||
|
|
||||||
def uninstall(self, force=False):
|
def uninstall(self, force=False):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
install_path = self._path
|
install_path = self._path
|
||||||
else:
|
else:
|
||||||
if not self.is_installed():
|
if not self.is_installed():
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
import StringIO
|
import StringIO
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
@ -59,9 +60,9 @@ class Bundle:
|
|||||||
self._zip_root_dir = None
|
self._zip_root_dir = None
|
||||||
|
|
||||||
if os.path.isdir(self._path):
|
if os.path.isdir(self._path):
|
||||||
self._unpacked = True
|
self._zip_file = None
|
||||||
else:
|
else:
|
||||||
self._unpacked = False
|
self._zip_file = zipfile.ZipFile(self._path)
|
||||||
self._check_zip_bundle()
|
self._check_zip_bundle()
|
||||||
|
|
||||||
# manifest = self._get_file(self._infodir + '/contents')
|
# manifest = self._get_file(self._infodir + '/contents')
|
||||||
@ -72,9 +73,12 @@ class Bundle:
|
|||||||
# if signature is None:
|
# if signature is None:
|
||||||
# raise MalformedBundleException('No signature file')
|
# raise MalformedBundleException('No signature file')
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if self._zip_file is not None:
|
||||||
|
self._zip_file.close()
|
||||||
|
|
||||||
def _check_zip_bundle(self):
|
def _check_zip_bundle(self):
|
||||||
zip_file = zipfile.ZipFile(self._path)
|
file_names = self._zip_file.namelist()
|
||||||
file_names = zip_file.namelist()
|
|
||||||
if len(file_names) == 0:
|
if len(file_names) == 0:
|
||||||
raise MalformedBundleException('Empty zip file')
|
raise MalformedBundleException('Empty zip file')
|
||||||
|
|
||||||
@ -99,48 +103,42 @@ class Bundle:
|
|||||||
def get_file(self, filename):
|
def get_file(self, filename):
|
||||||
f = None
|
f = None
|
||||||
|
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
path = os.path.join(self._path, filename)
|
path = os.path.join(self._path, filename)
|
||||||
try:
|
try:
|
||||||
f = open(path,"rb")
|
f = open(path,"rb")
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
zip_file = zipfile.ZipFile(self._path)
|
|
||||||
path = os.path.join(self._zip_root_dir, filename)
|
path = os.path.join(self._zip_root_dir, filename)
|
||||||
try:
|
try:
|
||||||
data = zip_file.read(path)
|
data = self._zip_file.read(path)
|
||||||
f = StringIO.StringIO(data)
|
f = StringIO.StringIO(data)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.debug('%s not found.' % filename)
|
logging.debug('%s not found.' % filename)
|
||||||
zip_file.close()
|
|
||||||
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def is_file(self, filename):
|
def is_file(self, filename):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
path = os.path.join(self._path, filename)
|
path = os.path.join(self._path, filename)
|
||||||
return os.path.isfile(path)
|
return os.path.isfile(path)
|
||||||
else:
|
else:
|
||||||
zip_file = zipfile.ZipFile(self._path)
|
|
||||||
path = os.path.join(self._zip_root_dir, filename)
|
path = os.path.join(self._zip_root_dir, filename)
|
||||||
try:
|
try:
|
||||||
zip_file.getinfo(path)
|
self._zip_file.getinfo(path)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
finally:
|
|
||||||
zip_file.close()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def is_dir(self, filename):
|
def is_dir(self, filename):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
path = os.path.join(self._path, filename)
|
path = os.path.join(self._path, filename)
|
||||||
return os.path.isdir(path)
|
return os.path.isdir(path)
|
||||||
else:
|
else:
|
||||||
zip_file = zipfile.ZipFile(self._path)
|
|
||||||
path = os.path.join(self._zip_root_dir, filename, "")
|
path = os.path.join(self._zip_root_dir, filename, "")
|
||||||
for f in zip_file.namelist():
|
for f in self._zip_file.namelist():
|
||||||
if f.startswith(path):
|
if f.startswith(path):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -150,7 +148,7 @@ class Bundle:
|
|||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
def _unzip(self, install_dir):
|
def _unzip(self, install_dir):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
raise AlreadyInstalledException
|
raise AlreadyInstalledException
|
||||||
|
|
||||||
if not os.path.isdir(install_dir):
|
if not os.path.isdir(install_dir):
|
||||||
@ -163,10 +161,13 @@ class Bundle:
|
|||||||
# FIXME: use manifest
|
# FIXME: use manifest
|
||||||
if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', '-o', self._path,
|
if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', '-o', self._path,
|
||||||
'-x', 'mimetype', '-d', install_dir):
|
'-x', 'mimetype', '-d', install_dir):
|
||||||
|
# clean up install dir after failure
|
||||||
|
shutil.rmtree(install_dir, ignore_errors=True)
|
||||||
|
# indicate failure.
|
||||||
raise ZipExtractException
|
raise ZipExtractException
|
||||||
|
|
||||||
def _zip(self, bundle_path):
|
def _zip(self, bundle_path):
|
||||||
if not self._unpacked:
|
if self._zip_file is not None:
|
||||||
raise NotInstalledException
|
raise NotInstalledException
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -195,7 +195,7 @@ class ContentBundle(Bundle):
|
|||||||
return "file://" + urllib.pathname2url(self.get_start_path())
|
return "file://" + urllib.pathname2url(self.get_start_path())
|
||||||
|
|
||||||
def is_installed(self):
|
def is_installed(self):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
return True
|
return True
|
||||||
elif os.path.isdir(self.get_root_dir()):
|
elif os.path.isdir(self.get_root_dir()):
|
||||||
return True
|
return True
|
||||||
@ -207,7 +207,7 @@ class ContentBundle(Bundle):
|
|||||||
self._run_indexer()
|
self._run_indexer()
|
||||||
|
|
||||||
def uninstall(self):
|
def uninstall(self):
|
||||||
if self._unpacked:
|
if self._zip_file is None:
|
||||||
if not self.is_installed():
|
if not self.is_installed():
|
||||||
raise NotInstalledException
|
raise NotInstalledException
|
||||||
install_dir = self._path
|
install_dir = self._path
|
||||||
|
Loading…
Reference in New Issue
Block a user