Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
GroupUserFolder.Installation.Installation Class Reference

List of all members.

Public Member Functions

def __init__
def report
def setupTools
def installSubSkin
def setupCustomModelsSkin
def setupTypesandSkins
def isPlone2
def hasFormController
def addFormValidators
def addNavigationTransitions
def setPermissions
def installMessageCatalog

Public Attributes

 root
 out
 typesTool
 skinsTool
 portal_properties
 navigation_properties
 form_properties

Detailed Description

Definition at line 34 of file Installation.py.


Constructor & Destructor Documentation

Definition at line 35 of file Installation.py.

00035 
00036     def __init__(self, root):
00037         self.root=root
00038         self.out=StringIO()
00039         self.typesTool = getToolByName(self.root, 'portal_types')
00040         self.skinsTool = getToolByName(self.root, 'portal_skins')
00041         self.portal_properties = getToolByName(self.root, 'portal_properties')
00042         self.navigation_properties = self.portal_properties.navigation_properties
00043         self.form_properties = self.portal_properties.form_properties


Member Function Documentation

Adds the form validators.
DON'T ADD ANYTHING IF CMFFORMCONTROLLER IS INSTALLED

Definition at line 142 of file Installation.py.

00142 
00143     def addFormValidators(self, mapping):
00144         """
00145         Adds the form validators.
00146         DON'T ADD ANYTHING IF CMFFORMCONTROLLER IS INSTALLED
00147         """
00148         # Plone2 management
00149         if self.hasFormController():
00150             return
00151         for (key, value) in mapping:
00152             safeEditProperty(self.form_properties, key, value)

Here is the call graph for this function:

Adds Navigation Transitions in portal properties

Definition at line 153 of file Installation.py.

00153 
00154     def addNavigationTransitions(self, transitions):
00155         """
00156         Adds Navigation Transitions in portal properties
00157         """
00158         # Plone2 management
00159         if self.hasFormController():
00160             return
00161         for (key, value) in transitions:
00162             safeEditProperty(self.navigation_properties, key, value)

Here is the call graph for this function:

hasFormController(self,) => Return 1 if CMFFC is available

Definition at line 133 of file Installation.py.

00133 
00134     def hasFormController(self,):
00135         """
00136         hasFormController(self,) => Return 1 if CMFFC is available
00137         """
00138         if 'portal_form_controller' in self.root.objectIds():
00139             return 1
00140         else:
00141             return None

Here is the caller graph for this function:

def GroupUserFolder.Installation.Installation.installMessageCatalog (   self,
  plone,
  prodglobals,
  domain,
  poPrefix 
)
Sets up the a message catalog for this product
according to the available languages in both:
- .pot files in the "i18n" folder of this product
- MessageCatalog available for this domain
Typical use, create below this function:
def installCatalog(self):
    installMessageCatalog(self, Products.MyProduct, 'mydomain', 'potfile_')
    return
This assumes that you set the domain 'mydomain' in 'translation_service'
and the .../Products/YourProduct/i18n/potfile_en.po (...) contain your messages.

@param plone: the plone site
@type plone: a 'Plone site' object
@param prodglobals: see PloneSkinRegistrar.__init__
@param domain: the domain nick in Plone 'translation_service'
@type domain: string or None for the default domain
    (you shouldn't use the default domain)
@param poPrefix: .po files to use start with that prefix.
    i.e. use 'foo_' to install words from 'foo_fr.po', 'foo_en.po' (...)
@type poPrefix: string

Definition at line 178 of file Installation.py.

00178 
00179     def installMessageCatalog(self, plone, prodglobals, domain, poPrefix):
00180         """Sets up the a message catalog for this product
00181         according to the available languages in both:
00182         - .pot files in the "i18n" folder of this product
00183         - MessageCatalog available for this domain
00184         Typical use, create below this function:
00185         def installCatalog(self):
00186             installMessageCatalog(self, Products.MyProduct, 'mydomain', 'potfile_')
00187             return
00188         This assumes that you set the domain 'mydomain' in 'translation_service'
00189         and the .../Products/YourProduct/i18n/potfile_en.po (...) contain your messages.
00190 
00191         @param plone: the plone site
00192         @type plone: a 'Plone site' object
00193         @param prodglobals: see PloneSkinRegistrar.__init__
00194         @param domain: the domain nick in Plone 'translation_service'
00195         @type domain: string or None for the default domain
00196             (you shouldn't use the default domain)
00197         @param poPrefix: .po files to use start with that prefix.
00198             i.e. use 'foo_' to install words from 'foo_fr.po', 'foo_en.po' (...)
00199         @type poPrefix: string
00200         """
00201 
00202         installInfo = (
00203             "!! I18N INSTALLATION CANCELED !!\n"
00204             "It seems that your Plone instance does not have the i18n features installed correctly.\n"
00205             "You should have a 'translation_service' object in your Plone root.\n"
00206             "This object should have the '%(domain)s' domain registered and associated\n"
00207             "with an **existing** MessageCatalog object.\n"
00208             "Fix all this first and come back here." % locals())
00209         #
00210         # Find Plone i18n resources
00211         #
00212         try:
00213             ts = getattr(plone, 'translation_service')
00214         except AttributeError, e:
00215             return installInfo
00216         found = 0
00217         for nick, path in ts.getDomainInfo():
00218             if nick == domain:
00219                 found = 1
00220                 break
00221         if not found:
00222             return installInfo
00223         try:
00224             mc = ts.restrictedTraverse(path)
00225         except (AttributeError, KeyError), e:
00226             return installInfo
00227         self.out.write("Installing I18N messages into '%s'\n" % '/'.join(mc.getPhysicalPath()))
00228         enabledLangs = [nick for nick, lang in mc.get_languages_tuple()]
00229         self.out.write("This MessageCatalog has %s languages enabled.\n" %  ", ".join(enabledLangs))
00230         #
00231         # Find .po files
00232         #
00233         i18nPath = os.path.join(prodglobals['__path__'][0], 'i18n')
00234         poPtn = os.path.join(i18nPath, poPrefix + '*.po')
00235         poFiles = glob.glob(poPtn)
00236         rxFindLanguage = re.compile(poPrefix +r'(.*)\.po')
00237         poRsrc = {}
00238         for file in poFiles:
00239             k = rxFindLanguage.findall(file)[0]
00240             poRsrc[k] = file
00241         self.out.write("This Product provides messages for %s languages.\n" % ", ".join(poRsrc.keys()))
00242         for lang in enabledLangs:
00243             if poRsrc.has_key(lang):
00244                 self.out.write("Adding support for language %s.\n" % lang)
00245                 fh = open(poRsrc[lang])
00246                 mc.manage_import(lang, fh.read())
00247                 fh.close()
00248         self.out.write("Done !")
Install a subskin, i.e. a folder/directoryview.

Definition at line 68 of file Installation.py.

00068 
00069     def installSubSkin(self, skinFolder):
00070         """ Install a subskin, i.e. a folder/directoryview.
00071         """
00072         for skin in self.skinsTool.getSkinSelections():
00073             path = self.skinsTool.getSkinPath(skin)
00074             path = map( string.strip, string.split( path,',' ) )
00075             if not skinFolder in path:
00076                 try:
00077                     path.insert( path.index( 'custom')+1, skinFolder )
00078                 except ValueError:
00079                     path.append(skinFolder)
00080                 path = string.join( path, ', ' )
00081                 self.skinsTool.addSkinSelection( skin, path )
00082                 self.out.write('Subskin successfully installed into %s.\n' % skin)
00083             else:
00084                 self.out.write('*** Subskin was already installed into %s.\n' % skin)

Here is the caller graph for this function:

isPlone2(self,) => return true if we're using Plone2 ! :-)

Definition at line 127 of file Installation.py.

00127 
00128     def isPlone2(self,):
00129         """
00130         isPlone2(self,) => return true if we're using Plone2 ! :-)
00131         """
00132         return self.hasFormController()

Here is the call graph for this function:

Definition at line 44 of file Installation.py.

00044 
00045     def report(self):
00046         self.out.write('Installation completed.\n')
00047         return self.out.getvalue()

setPermissions(self) => Set standard permissions / roles

Definition at line 163 of file Installation.py.

00163 
00164     def setPermissions(self, perms_list):
00165         """
00166         setPermissions(self) => Set standard permissions / roles
00167         """
00168         # As a default behavior, newly-created permissions are granted to owner and manager.
00169         # To change this, just comment this code and grab back the code commented below to
00170         # make it suit your needs.
00171         for perm in perms_list:
00172             self.root.manage_permission(
00173                 perm,
00174                 ('Manager', 'Owner'),
00175                 acquire = 1
00176                 )
00177         self.out.write("Reseted default permissions\n")

Here is the caller graph for this function:

Install custom skin folder

Definition at line 85 of file Installation.py.

00085 
00086     def setupCustomModelsSkin(self, skin_name):
00087         """ Install custom skin folder
00088         """
00089         try:
00090             self.skinsTool.manage_addProduct['OFSP'].manage_addFolder(skin_name + 'CustomModels')
00091         except:
00092             self.out.write('*** Skin %sCustomModels already existed in portal_skins.\n' % skin_name)
00093         self.installSubSkin('%sCustomModels' % skin_name)

Here is the call graph for this function:

def GroupUserFolder.Installation.Installation.setupTools (   self,
  product_name,
  tools 
)

Definition at line 48 of file Installation.py.

00048 
00049     def setupTools(self, product_name, tools):
00050         addTool = self.root.manage_addProduct[product_name].manage_addTool
00051         for tool, title in tools:
00052             found = 0
00053             for obj in self.root.objectValues():
00054                 if obj.meta_type == tool:
00055                     found = 1
00056             if not found:
00057                 addTool(tool, None)
00058 
00059             found = 0
00060             root=self.root
00061             for obj in root.objectValues():
00062                 if obj.meta_type == tool:
00063                     obj.title=title
00064                     self.out.write("Added '%s' tool.\n" % (tool,))
00065                     found = 1
00066             if not found:
00067                 self.out.write("Couldn't add '%s' tool.\n" % (tool,))

def GroupUserFolder.Installation.Installation.setupTypesandSkins (   self,
  fti_list,
  skin_name,
  install_globals 
)
setup of types and skins

Definition at line 94 of file Installation.py.

00094 
00095     def setupTypesandSkins(self, fti_list, skin_name, install_globals):
00096         """
00097         setup of types and skins
00098         """
00099 
00100         # Former types deletion (added by PJG)
00101         for f in fti_list:
00102             if f['id'] in self.typesTool.objectIds():
00103                 self.out.write('*** Object "%s" already existed in the types tool => deleting\n' % (f['id']))
00104                 self.typesTool._delObject(f['id'])
00105 
00106         # Type re-creation
00107         for f in fti_list:
00108             # Plone1 : if cmfformcontroller is not available and plone1_action key is defined,
00109             # use this key instead of the regular 'action' key.
00110             if (not self.hasFormController()) and f.has_key('plone1_action'):
00111                 f['action'] = f['plone1_action']
00112 
00113             # Regular FTI processing
00114             cfm = apply(ContentFactoryMetadata, (), f)
00115             self.typesTool._setObject(f['id'], cfm)
00116             self.out.write('Type "%s" registered with the types tool\n' % (f['id']))
00117 
00118         # Install de chaque nouvelle subskin/layer
00119         try:
00120             addDirectoryViews(self.skinsTool, 'skins', install_globals)
00121             self.out.write( "Added directory views to portal_skins.\n" )
00122         except:
00123             self.out.write( '*** Unable to add directory views to portal_skins.\n')
00124 
00125         # Param de chaque nouvelle subskin/layer
00126         self.installSubSkin(skin_name)

Here is the call graph for this function:


Member Data Documentation

Definition at line 42 of file Installation.py.

Definition at line 41 of file Installation.py.

Definition at line 37 of file Installation.py.

Definition at line 40 of file Installation.py.

Definition at line 36 of file Installation.py.

Definition at line 39 of file Installation.py.

Definition at line 38 of file Installation.py.


The documentation for this class was generated from the following file: