# ------------------------------------------------------------------------------ from appy.gen.plone25.wrappers import AbstractWrapper # ------------------------------------------------------------------------------ _PY = 'Please specify a file corresponding to a Python interpreter ' \ '(ie "/usr/bin/python").' FILE_NOT_FOUND = 'Path "%s" was not found.' VALUE_NOT_FILE = 'Path "%s" is not a file. ' + _PY NO_PYTHON = "Name '%s' does not starts with 'python'. " + _PY NOT_UNO_ENABLED_PYTHON = '"%s" is not a UNO-enabled Python interpreter. ' \ 'To check if a Python interpreter is UNO-enabled, ' \ 'launch it and type "import uno". If you have no ' \ 'ImportError exception it is ok.' # ------------------------------------------------------------------------------ class ToolWrapper(AbstractWrapper): def validPythonWithUno(self, value): '''This method represents the validator for field unoEnabledPython.''' if value: if not os.path.exists(value): return FILE_NOT_FOUND % value if not os.path.isfile(value): return VALUE_NOT_FILE % value if not os.path.basename(value).startswith('python'): return NO_PYTHON % value if os.system('%s -c "import uno"' % value): return NOT_UNO_ENABLED_PYTHON % value return None def getInitiator(self): '''Retrieves the object that triggered the creation of the object being currently created (if any).''' res = None rq = self.o.REQUEST if rq.get('nav', ''): initiatorUid = rq['nav'].split('.')[1] res = self.o.uid_catalog(UID=initiatorUid)[0].getObject().appy() return res def getObject(self, uid): '''Allow to retrieve an object from its unique identifier p_uid.''' return self.o.getObject(uid, appy=True) def getDiskFolder(self): '''Returns the disk folder where the Appy application is stored.''' return self.o.getProductConfig().diskFolder # ------------------------------------------------------------------------------