Univention Bugzilla – Attachment 7520 Details for
Bug 40827
Additional App data for App Appliances
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for pickle files
bug40827 (text/plain), 3.13 KB, created by
Dirk Wiesenthal
on 2016-03-07 18:16 CET
(
hide
)
Description:
Patch for pickle files
Filename:
MIME Type:
Creator:
Dirk Wiesenthal
Created:
2016-03-07 18:16 CET
Size:
3.13 KB
patch
obsolete
>Index: python/appcenter/app.py >=================================================================== >--- python/appcenter/app.py (Revision 67953) >+++ python/appcenter/app.py (Arbeitskopie) >@@ -961,6 +961,7 @@ > > > class AppManager(object): >+ _locale = None > _cache = [] > _package_manager = None > _pickle_file = os.path.join(CACHE_DIR, '.apps.%(locale)s.pkl') >@@ -968,14 +969,50 @@ > > @classmethod > def _invalidate_pickle_cache(cls): >- pickle_pattern = re.sub(r'%\(.*?\).', '*', cls._pickle_file) >- for pickle_file in glob(os.path.join(CACHE_DIR, pickle_pattern)): >+ if cls._pickle_file: >+ pickle_pattern = re.sub(r'%\(.*?\).', '*', cls._pickle_file) >+ for pickle_file in glob(pickle_pattern): >+ try: >+ os.unlink(pickle_file) >+ except OSError: >+ pass >+ >+ @classmethod >+ def _get_pickle_cache_file(cls): >+ if cls._pickle_file: >+ return cls._pickle_file % {'locale': cls._locale} >+ >+ @classmethod >+ def _save_pickle_cache(cls, cache): >+ pickle_file = cls._get_pickle_cache_file() >+ if pickle_file: > try: >- os.unlink(pickle_file) >- except OSError: >- pass >+ with open(pickle_file, 'wb') as fd: >+ dump(cache, fd, 2) >+ except (IOError, PickleError): >+ return False >+ else: >+ return True > > @classmethod >+ def _load_pickle_cache(cls): >+ pickle_file = cls._get_pickle_cache_file() >+ if pickle_file: >+ try: >+ with open(pickle_file, 'rb') as fd: >+ return load(fd) >+ except (IOError, PickleError): >+ return None >+ >+ @classmethod >+ def _relevant_ini_files(cls): >+ return glob(os.path.join(CACHE_DIR, '*.ini')) >+ >+ @classmethod >+ def _build_app_from_ini(cls, ini): >+ return cls._AppClass.from_ini(ini, locale=cls._locale) >+ >+ @classmethod > def clear_cache(cls): > ucr_load() > cls._cache[:] = [] >@@ -987,26 +1024,24 @@ > @classmethod > def _get_every_single_app(cls): > if not cls._cache: >- locale = get_locale() or 'en' >- pickle_file = cls._pickle_file % {'locale': locale} >+ cls._locale = get_locale() or 'en' > try: >- with open(pickle_file, 'rb') as fd: >- cls._cache = load(fd) >- except (IOError, PickleError): >- for ini in glob(os.path.join(CACHE_DIR, '*.ini')): >- app = cls._AppClass.from_ini(ini, locale=locale) >- if app is not None: >- cls._cache.append(app) >- cls._cache.sort() >- try: >- with open(pickle_file, 'wb') as fd: >- dump(cls._cache, fd, 2) >- except (IOError, PickleError): >- app_logger.warn('Unable to cache apps') >+ cached_apps = cls._load_pickle_cache() >+ if cached_apps is not None: >+ cls._cache = cached_apps >+ app_logger.debug('Loaded %d apps from cache' % len(cls._cache)) > else: >- app_logger.debug('Saved %d apps into cache' % len(cls._cache)) >- else: >- app_logger.debug('Loaded %d apps from cache' % len(cls._cache)) >+ for ini in cls._relevant_ini_files(): >+ app = cls._build_app_from_ini(ini) >+ if app is not None: >+ cls._cache.append(app) >+ cls._cache.sort() >+ if cls._save_pickle_cache(cls._cache): >+ app_logger.debug('Saved %d apps into cache' % len(cls._cache)) >+ else: >+ app_logger.warn('Unable to cache apps') >+ finally: >+ cls._locale = None > return cls._cache > > @classmethod
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 40827
: 7520