def initialize(context): # hook into the Control Panel global translation_service # allow for disabling PTS entirely by setting a environment variable. if bool(os.getenv('DISABLE_PTS')): log('Disabled by environment variable "DISABLE_PTS".', logging.WARNING) return cp = context._ProductContext__app.Control_Panel # argh if cp_id in cp.objectIds(): cp_ts = getattr(cp, cp_id) # use the ts in the acquisition context of the control panel # translation_service = translation_service.__of__(cp) translation_service = PTSWrapper(cp_ts) else: cp_ts = make_translation_service(cp) # don't touch - this is the last version that didn't have the # attribute (0.4) instance_version = getattr(cp_ts, '_instance_version', (0, 4, 0, 0)) if instance_version[3] > 99: log('development mode: translation service recreated', detail = '(found %s.%s.%s.%s)\n' % instance_version) cp._delObject(cp_id) cp_ts = make_translation_service(cp) if instance_version < PlacelessTranslationService._class_version: log('outdated translation service found, recreating', detail = '(found %s.%s.%s.%s)\n' % instance_version) cp._delObject(cp_id) purgeMoFileCache() cp_ts = make_translation_service(cp) # sweep products log('products: %r' % get_products(), logging.DEBUG) for prod in get_products(): # prod is a tuple in the form: # (priority, dir_name, index, base_dir) for each Product directory cp_ts._load_i18n_dir(os.path.join(prod[3], prod[1], 'i18n')) cp_ts._load_locales_dir(os.path.join(prod[3], prod[1], 'locales')) # sweep the i18n directory for local catalogs instance_i18n = os.path.join(INSTANCE_HOME, 'i18n') if os.path.isdir(instance_i18n): cp_ts._load_i18n_dir(instance_i18n) instance_locales = os.path.join(INSTANCE_HOME, 'locales') if os.path.isdir(instance_locales): cp_ts._load_locales_dir(instance_locales) # didn't found any catalogs if not cp_ts.objectIds(): log('no translations found!', logging.DEBUG) # set ZPT's translation service # NOTE: since this registry is a global var we can't register the # persistent service itself (zodb connection) therefore a # wrapper is created around it setGlobalTranslationService(PTSWrapper(cp_ts))
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) # We want to fail immediately if a product throws an exception # during install, so we set the raise_exc flag. install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def installProduct(app, productName, quiet=False): """Install the Zope 2 product with the given name, so that it will show up in the Zope 2 control panel and have its ``initialize()`` hook called. The ``STARTUP`` layer or an equivalent layer must have been loaded first. If ``quiet`` is False, an error will be logged if the product cannot be found. By default, the function is silent. Note that products' ZCML is *not* loaded automatically, even if the product is in the Products namespace. """ import sys from OFS.Folder import Folder from OFS.Application import get_folder_permissions, get_products from OFS.Application import install_product, install_package from App.class_init import InitializeClass import Products found = False if productName in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: install_product(app, productDir, name, [], get_folder_permissions(), raise_exc=1) InitializeClass(Folder) _INSTALLED_PRODUCTS[productName] = (priority, name, index, productDir,) found = True break else: if HAS_ZOPE213: packages = tuple(get_packages_to_initialize()) else: packages = getattr(Products, '_packages_to_initialize', []) for module, init_func in packages: if module.__name__ == productName: install_package(app, module, init_func, raise_exc=1) if not HAS_ZOPE213: Products._packages_to_initialize.remove((module, init_func)) _INSTALLED_PRODUCTS[productName] = (module, init_func,) found = True break if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()
def test_get_products(self): self.makeFakeProducts() self.configure(cfg) from OFS.Application import get_products names = [x[1] for x in get_products()] for name in FAKEPRODUCTS: self.assert_(name in names)
def test_multiple_product_paths(self): self.makeFakeProducts() self.makeProduct(os.path.join(TEMPPRODUCTS2, 'another')) self.configure(cfg) from OFS.Application import get_products names = [x[1] for x in get_products()] for name in FAKEPRODUCTS: self.assert_(name in names) self.assert_('another' in names)
def test_empty_dir_on_products_path_is_not_product(self): self.makeFakeProducts() os.makedirs(os.path.join(TEMPPRODUCTS, 'gleeb')) self.configure(cfg) from OFS.Application import get_products names = [x[1] for x in get_products()] for name in FAKEPRODUCTS: self.assert_(name in names) self.assert_('gleeb' not in names)
def test_file_on_products_path_is_not_product(self): self.makeFakeProducts() f = open(os.path.join(TEMPPRODUCTS, 'README.txt'), 'w') f.write('#foo') f.close() self.configure(cfg) from OFS.Application import get_products names = [x[1] for x in get_products()] for name in FAKEPRODUCTS: self.assert_(name in names) self.assert_('README.txt' not in names)
def _install_product(self, name, app): """Zope 2 install a given product. """ meta_types = [] if name not in self.installed_products: for priority, product_name, index, product_dir in get_products(): if product_name == name: install_product(app, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) self.installed_products.append(name) Products.meta_types = Products.meta_types + \ tuple(meta_types) InitializeClass(Folder) # WTF ? break
def uninstallProduct(app, productName, quiet=False): """Uninstall the given Zope 2 product. This is the inverse of ``installProduct()`` above. """ import sys # from OFS.Folder import Folder # from OFS.Application import get_folder_permissions # from AccessControl.class_init import InitializeClass from OFS.Application import Application, get_products global _INSTALLED_PRODUCTS found = False if productName not in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: if name in Application.misc_.__dict__: delattr(Application.misc_, name) # TODO: Also remove permissions from get_folder_permissions? # Difficult to know if this would stomp on any other # permissions # InitializeClass(Folder) found = True break elif productName in _INSTALLED_PRODUCTS: # must be a package module, init_func = _INSTALLED_PRODUCTS[productName] name = module.__name__ packages = get_packages_to_initialize() packages.append((module, init_func)) found = True if found: del _INSTALLED_PRODUCTS[productName] if not found and not quiet: sys.stderr.write( 'Could not install product {0}\n'.format(productName)) sys.stderr.flush()
def uninstallProduct(app, productName, quiet=False): """Uninstall the given Zope 2 product. This is the inverse of ``installProduct()`` above. """ import sys # from OFS.Folder import Folder # from OFS.Application import get_folder_permissions # from AccessControl.class_init import InitializeClass from OFS.Application import Application, get_products global _INSTALLED_PRODUCTS found = False if productName not in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: if name in Application.misc_.__dict__: delattr(Application.misc_, name) # TODO: Also remove permissions from get_folder_permissions? # Difficult to know if this would stomp on any other # permissions # InitializeClass(Folder) found = True break elif productName in _INSTALLED_PRODUCTS: # must be a package module, init_func = _INSTALLED_PRODUCTS[productName] name = module.__name__ packages = get_packages_to_initialize() packages.append((module, init_func)) found = True if found: del _INSTALLED_PRODUCTS[productName] if not found and not quiet: sys.stderr.write('Could not install product {0}\n'.format(productName)) sys.stderr.flush()
def install_products(app, *prod): """auxiliary function to install products *prod* (by names).""" from OFS.Application import get_folder_permissions, get_products, install_product folder_permissions = get_folder_permissions() meta_types=[] done={} # work around a Zope bug: "Products.__path__" may contain # non existing elements import Products, os.path Products.__path__ = [p for p in Products.__path__ if os.path.exists(p)] products = get_products() for priority, product_name, index, product_dir in products: if product_name not in prod or product_name in done: continue done[product_name]=1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=True)
def install_products(app): # Install a list of products into the basic folder class, so # that all folders know about top-level objects, aka products # from OFS.Application import get_folder_permissions from OFS.Application import install_product from OFS.Application import install_package from OFS.Application import get_packages_to_initialize from OFS.Application import get_products from App.config import getConfiguration import transaction folder_permissions = get_folder_permissions() meta_types = [] done = {} debug_mode = getConfiguration().debug_mode transaction.get().note('Prior to product installs') transaction.commit() products = get_products() for priority, product_name, index, product_dir in products: # For each product, we will import it and try to call the # intialize() method in the product __init__ module. If # the method doesnt exist, we put the old-style information # together and do a default initialization. if product_name in done: continue if is_sauna_product(product_dir): # Will be later loaded by installDeferred() continue done[product_name] = 1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=debug_mode) # Delayed install of packages-as-products for module, init_func in tuple(get_packages_to_initialize()): install_package(app, module, init_func, raise_exc=debug_mode)
def installProduct(name, quiet=0): '''Installs a Zope product.''' start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) # We want to fail immediately if a product throws an exception # during install, so we set the raise_exc flag. install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions(), raise_exc=1) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) Globals.default__class_init__(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and not _installedProducts.has_key(name): for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions()) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def initialize2(context): # allow for disabling PTS entirely by setting an environment variable. if bool(os.getenv('DISABLE_PTS')): log('Disabled by environment variable "DISABLE_PTS".', logging.WARNING) return cp = getattr(getattr(context, '_ProductContext__app', None), 'Control_Panel', None) # argh if cp is not None and cp_id in cp.objectIds(): cp_ts = getattr(cp, cp_id, None) # Clean up ourselves if cp_ts is not None: cp._delObject(cp_id) _remove_mo_cache(CACHE_PATH) # load translation files from all packages and products loaded = {} import Products packages = get_registered_packages() for package in packages: name = package.__name__ path = package.__path__[0] loaded[name] = True i18n_dir = os.path.join(path, 'i18n') if isdir(i18n_dir): _load_i18n_dir(i18n_dir) for product in get_products(): name = product[1] if name in IGNORED: continue basepath = product[3] fullname = 'Products.' + name # Avoid loading products registered as packages twice if loaded.get(fullname): continue loaded[fullname] = True i18n_dir = os.path.join(basepath, name, 'i18n') if isdir(i18n_dir): _load_i18n_dir(i18n_dir)
def install_products(app, *prod): """auxiliary function to install products *prod* (by names).""" from OFS.Application import get_folder_permissions, get_products, install_product folder_permissions = get_folder_permissions() meta_types = [] done = {} # work around a Zope bug: "Products.__path__" may contain # non existing elements import Products, os.path Products.__path__ = [p for p in Products.__path__ if os.path.exists(p)] products = get_products() for priority, product_name, index, product_dir in products: if product_name not in prod or product_name in done: continue done[product_name] = 1 install_product(app, product_dir, product_name, meta_types, folder_permissions, raise_exc=True)
def get_packages(): """Returns a dict of package name to package path.""" result = {} packages = get_registered_packages() for package in packages: name = package.__name__ path = package.__path__[0] result[name] = path for product in get_products(): name = product[1] if name in IGNORED: continue basepath = product[3] fullname = "Products." + name # Avoid getting products registered as packages twice if result.get(fullname): continue result[fullname] = os.path.join(basepath, name) return result
def get_packages(): """Returns a dict of package name to package path.""" result = {} packages = get_registered_packages() for package in packages: name = package.__name__ path = package.__path__[0] result[name] = path for product in get_products(): name = product[1] if name in IGNORED: continue basepath = product[3] fullname = 'Products.' + name # Avoid getting products registered as packages twice if result.get(fullname): continue result[fullname] = os.path.join(basepath, name) return result
def _installProduct(name, quiet=0): '''Installs a Zope product.''' from AccessControl.class_init import InitializeClass start = time.time() meta_types = [] if _patched and name not in _installedProducts: for priority, product_name, index, product_dir in get_products(): if product_name == name: if not quiet: _print('Installing %s ... ' % product_name) install_product(_theApp, product_dir, product_name, meta_types, get_folder_permissions()) _installedProducts[product_name] = 1 Products.meta_types = Products.meta_types + tuple(meta_types) InitializeClass(Folder) if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) break else: if name != 'SomeProduct': # Ignore the skeleton tests :-P if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def installProduct(app, productName, quiet=False, multiinit=False): """Install the Zope 2 product with the given name, so that it will show up in the Zope 2 control panel and have its ``initialize()`` hook called. The ``STARTUP`` layer or an equivalent layer must have been loaded first. If ``quiet`` is False, an error will be logged if the product cannot be found. By default, the function is silent. Note that products' ZCML is *not* loaded automatically, even if the product is in the Products namespace. """ from App.class_init import InitializeClass from OFS.Application import get_folder_permissions from OFS.Application import get_products from OFS.Application import install_package from OFS.Application import install_product from OFS.Folder import Folder import Products import sys found = False if productName in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: install_product(app, productDir, name, [], get_folder_permissions(), raise_exc=1) InitializeClass(Folder) _INSTALLED_PRODUCTS[productName] = ( priority, name, index, productDir, ) found = True break else: if HAS_ZOPE213: packages = tuple(get_packages_to_initialize()) else: packages = getattr(Products, '_packages_to_initialize', []) for module, init_func in packages: if module.__name__ == productName: install_package(app, module, init_func, raise_exc=1) if not HAS_ZOPE213: Products._packages_to_initialize.remove( (module, init_func)) _INSTALLED_PRODUCTS[productName] = ( module, init_func, ) found = True if not multiinit: break if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()
def uninstallProduct(app, productName, quiet=False): """Uninstall the given Zope 2 product. This is the inverse of ``installProduct()`` above. """ import sys # from OFS.Folder import Folder # from OFS.Application import get_folder_permissions # from App.class_init import InitializeClass from OFS.Application import Application, get_products import Products global _INSTALLED_PRODUCTS found = False if productName not in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: if name in Application.misc_.__dict__: del Application.misc_.__dict__[name] try: cp = app['Control_Panel']['Products'] except KeyError: # Zope 4 pass else: if name in cp: product = cp[name] app._manage_remove_product_meta_type(product) app._manage_remove_product_permission(product) del cp[name] # TODO: Also remove permissions from get_folder_permissions? # Difficult to know if this would stomp on any other # permissions # InitializeClass(Folder) found = True break elif productName in _INSTALLED_PRODUCTS: # must be a package module, init_func = _INSTALLED_PRODUCTS[productName] name = module.__name__ try: cp = app['Control_Panel']['Products'] except KeyError: # Zope 4 pass else: if name in cp: product = cp[name] app._manage_remove_product_meta_type(product) app._manage_remove_product_permission(product) del cp[name] if HAS_ZOPE213: packages = get_packages_to_initialize() else: packages = Products._packages_to_initialize packages.append((module, init_func)) found = True if found: del _INSTALLED_PRODUCTS[productName] if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()
] return ret GLOBALS = globals() # define dependencies DEPENDENCIES = ['DataGridField'] # GS profile name EXTENSION_PROFILES = ('Products.TutorWeb:default', ) # The name of the Product PROJECTNAME = 'TutorWeb' DEBUG = True products = get_products() for priority, name, index, productDir in get_products(): if (name == PROJECTNAME): productdir = productDir + '/' + name bindir = productdir + '/bin' EXPLANATION_FIG = True ECMCR_WORKFLOW_ID = 'ecq_result_workflow' ECMCR_WORKFLOW_TITLE = 'Result Workflow [ECQ]' ECMCT_WORKFLOW_ID = 'ecq_quiz_workflow' ECMCT_WORKFLOW_TITLE = 'Test Workflow [ECQ]' ECMCE_WORKFLOW_ID = 'ecq_element_workflow' ECMCE_WORKFLOW_TITLE = 'Element Workflow [ECQ]' SKINS_DIR = 'skins'
def hasProduct(name): '''Checks if a product can be found along Products.__path__''' return name in [n[1] for n in get_products()]
def uninstallProduct(app, productName, quiet=False): """Uninstall the given Zope 2 product. This is the inverse of ``installProduct()`` above. """ import sys # from OFS.Folder import Folder # from OFS.Application import get_folder_permissions # from App.class_init import InitializeClass from OFS.Application import Application, get_products import Products global _INSTALLED_PRODUCTS found = False if productName not in _INSTALLED_PRODUCTS: return if productName.startswith('Products.'): for priority, name, index, productDir in get_products(): if ('Products.' + name) == productName: if name in Application.misc_.__dict__: del Application.misc_.__dict__[name] if name in app['Control_Panel']['Products']: product = app['Control_Panel']['Products'][name] app._manage_remove_product_meta_type(product) app._manage_remove_product_permission(product) del app['Control_Panel']['Products'][name] # TODO: Also remove permissions from get_folder_permissions? # Difficult to know if this would stomp on any other permissions # InitializeClass(Folder) found = True break elif productName in _INSTALLED_PRODUCTS: # must be a package module, init_func = _INSTALLED_PRODUCTS[productName] name = module.__name__ if name in app['Control_Panel']['Products']: product = app['Control_Panel']['Products'][name] app._manage_remove_product_meta_type(product) app._manage_remove_product_permission(product) del app['Control_Panel']['Products'][name] if HAS_ZOPE213: packages = get_packages_to_initialize() else: packages = Products._packages_to_initialize packages.append((module, init_func)) found = True if found: del _INSTALLED_PRODUCTS[productName] if not found and not quiet: sys.stderr.write("Could not install product %s\n" % productName) sys.stderr.flush()
# The name of the Product PROJECTNAME = 'TutorWeb' DEBUG = False try: # Plone 4 and higher import plone.app.upgrade PLONE_VERSION = 4 except ImportError: PLONE_VERSION = 3 try: import numpy NUMPY = True except: NUMPY = False products = get_products() for priority, name, index, productDir in get_products(): if (name == PROJECTNAME): productdir = productDir+'/'+name bindir = productdir+'/bin' EXPLANATION_FIG = True ECMCR_WORKFLOW_ID = 'tutorweb_result_workflow' ECMCR_WORKFLOW_TITLE = 'Result Workflow [TutorWeb]' ECMCT_WORKFLOW_ID = 'tutorweb_quiz_workflow' ECMCT_WORKFLOW_TITLE = 'Test Workflow [TutorWeb]' ECMCE_WORKFLOW_ID = 'tutorweb_element_workflow' ECMCE_WORKFLOW_TITLE = 'Element Workflow [TutorWeb]' SKINS_DIR = 'skins'