Exemplo n.º 1
0
 def installTranslations(self):
     '''Creates or updates the translation objects within the tool.'''
     translations = [t.o.id for t in self.appyTool.translations]
     # We browse the languages supported by this application and check
     # whether we need to create the corresponding Translation objects.
     for language in self.languages:
         if language in translations: continue
         # We will create, in the tool, the translation object for this
         # language. Determine first its title.
         langId, langEn, langNat = languages.get(language)
         if langEn != langNat:
             title = '%s (%s)' % (langEn, langNat)
         else:
             title = langEn
         self.appyTool.create('translations', id=language, title=title)
         self.appyTool.log('Translation object created for "%s".' % language)
     # Now, we synchronise every Translation object with the corresponding
     # "po" file on disk.
     appFolder = self.config.diskFolder
     appName = self.config.PROJECTNAME
     dn = os.path.dirname
     jn = os.path.join
     i18nFolder = jn(jn(jn(dn(dn(dn(appFolder))),'Products'),appName),'i18n')
     for translation in self.appyTool.translations:
         # Get the "po" file
         poName = '%s-%s.po' % (appName, translation.id)
         poFile = PoParser(jn(i18nFolder, poName)).parse()
         for message in poFile.messages:
             setattr(translation, message.id, message.getMessage())
         self.appyTool.log('Translation "%s" updated from "%s".' % \
                           (translation.id, poName))
Exemplo n.º 2
0
    def installTool(self):
        '''Updates the tool (now that the catalog is created) and updates its
           inner objects (users, groups, translations, documents).'''
        tool = self.app.config
        tool.createOrUpdate(True, None)
        appyTool = tool.appy()
        appyTool.log('Appy version is "%s".' % appy.version.short)

        # Execute custom pre-installation code if any
        if hasattr(appyTool, 'beforeInstall'): appyTool.beforeInstall()

        # Create the default users if they do not exist
        for login, roles in self.defaultUsers.iteritems():
            if not appyTool.count('User', noSecurity=True, login=login):
                appyTool.create('users', noSecurity=True, id=login, login=login,
                                password3=login, password4=login, roles=roles)
                appyTool.log('User "%s" created.' % login)
        # Ensure users "anon" and "system" have no email
        for login in ('anon', 'system'):
            user = appyTool.search1('User', noSecurity=True, login=login)
            user.email = None
        # Create group "admins" if it does not exist
        if not appyTool.count('Group', noSecurity=True, login='******'):
            appyTool.create('groups', noSecurity=True, login='******',
                            title='Administrators', roles=['Manager'])
            appyTool.log('Group "admins" created.')

        # Create a group for every global role defined in the application
        # (if required).
        if self.config.appConfig.groupsForGlobalRoles:
            for role in self.config.applicationGlobalRoles:
                groupId = role.lower()
                if appyTool.count('Group', noSecurity=True, login=groupId):
                    continue
                appyTool.create('groups', noSecurity=True, login=groupId,
                                title=role, roles=[role])
                appyTool.log('Group "%s", related to global role "%s", was ' \
                             'created.' % (groupId, role))

        # Create or update Translation objects
        translations = [t.o.id for t in appyTool.translations]
        # We browse the languages supported by this application and check
        # whether we need to create the corresponding Translation objects.
        done = []
        for language in self.languages:
            if language in translations: continue
            # We will create, in the tool, the translation object for this
            # language. Determine first its title.
            langId, langEn, langNat = languages.get(language)
            if langEn != langNat:
                title = '%s (%s)' % (langEn, langNat)
            else:
                title = langEn
            appyTool.create('translations', noSecurity=True,
                            id=language, title=title)
            done.append(language)
        if done: appyTool.log('Translations created for %s.' % ', '.join(done))

        # Synchronizes, if required, every Translation object with the
        # corresponding "po" file on disk.
        if appyTool.loadTranslationsAtStartup:
            appFolder = self.config.diskFolder
            appName = self.config.PROJECTNAME
            i18nFolder = os.path.join(appFolder, 'tr')
            done = []
            for translation in appyTool.translations:
                # Get the "po" file
                poName = '%s-%s.po' % (appName, translation.id)
                poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
                for message in poFile.messages:
                    setattr(translation, message.id, message.getMessage())
                done.append(translation.id)
            appyTool.log('translation(s) %s updated (%s messages).' % \
                         (', '.join(done), len(poFile.messages)))

        # Execute custom installation code if any.
        if hasattr(appyTool, 'onInstall'): appyTool.onInstall()
Exemplo n.º 3
0
 def getLanguageName(self, code):
     '''Gets the language name (in this language) from a 2-chars language
        p_code.'''
     return languages.get(code)[2]
Exemplo n.º 4
0
    def installTool(self):
        '''Updates the tool (now that the catalog is created) and updates its
           inner objects (users, groups, translations, documents).'''
        tool = self.app.config
        tool.createOrUpdate(True, None)
        tool.refreshSecurity()
        appyTool = tool.appy()
        appyTool.log('Appy version is "%s".' % appy.version.short)

        # Create the admin user if it does not exist.
        if not appyTool.count('User', noSecurity=True, login='******'):
            appyTool.create('users', noSecurity=True, login='******',
                            password1='admin', password2='admin',
                            email='*****@*****.**', roles=['Manager'])
            appyTool.log('Admin user "admin" created.')

        # Create group "admins" if it does not exist
        if not appyTool.count('Group', noSecurity=True, login='******'):
            appyTool.create('groups', noSecurity=True, login='******',
                            title='Administrators', roles=['Manager'])
            appyTool.log('Group "admins" created.')

        # Create a group for every global role defined in the application
        for role in self.config.applicationGlobalRoles:
            relatedGroup = '%s_group' % role
            if appyTool.count('Group', noSecurity=True, login=relatedGroup):
                continue
            appyTool.create('groups', noSecurity=True, login=relatedGroup,
                            title=relatedGroup, roles=[role])
            appyTool.log('Group "%s", related to global role "%s", was ' \
                         'created.' % (relatedGroup, role))

        # Create POD templates within the tool if required
        for contentType in self.config.attributes.iterkeys():
            appyClass = tool.getAppyClass(contentType)
            if not appyClass: continue # May be an abstract class
            wrapperClass = tool.getAppyClass(contentType, wrapper=True)
            for appyType in wrapperClass.__fields__:
                if appyType.type != 'Pod': continue
                # Find the attribute that stores the template, and store on
                # it the default one specified in the appyType if no
                # template is stored yet.
                attrName = appyTool.getAttributeName('podTemplate', appyClass,
                                                     appyType.name)
                fileObject = getattr(appyTool, attrName)
                if not fileObject or (fileObject.size == 0):
                    # There is no file. Put the one specified in the appyType.
                    fileName = os.path.join(appyTool.getDiskFolder(),
                                            appyType.template)
                    if os.path.exists(fileName):
                        setattr(appyTool, attrName, fileName)
                        # If the template is ods, set the default format to ods
                        # (because default is odt)
                        if fileName.endswith('.ods'):
                            formats = appyTool.getAttributeName('formats',
                                                       appyClass, appyType.name)
                            setattr(appyTool, formats, ['ods'])
                        appyTool.log('Imported "%s" in the tool in ' \
                                     'attribute "%s"'% (fileName, attrName))
                    else:
                        appyTool.log('Template "%s" was not found!' % \
                                     fileName, type='error')

        # Create or update Translation objects
        translations = [t.o.id for t in appyTool.translations]
        # We browse the languages supported by this application and check
        # whether we need to create the corresponding Translation objects.
        for language in self.languages:
            if language in translations: continue
            # We will create, in the tool, the translation object for this
            # language. Determine first its title.
            langId, langEn, langNat = languages.get(language)
            if langEn != langNat:
                title = '%s (%s)' % (langEn, langNat)
            else:
                title = langEn
            appyTool.create('translations', noSecurity=True,
                            id=language, title=title)
            appyTool.log('Translation object created for "%s".' % language)

        # Execute custom installation code if any
        if hasattr(appyTool, 'onInstall'): appyTool.onInstall()

        # Now, if required, we synchronise every Translation object with the
        # corresponding "po" file on disk.
        if appyTool.loadTranslationsAtStartup:
            appFolder = self.config.diskFolder
            appName = self.config.PROJECTNAME
            i18nFolder = os.path.join(appFolder, 'tr')
            for translation in appyTool.translations:
                # Get the "po" file
                poName = '%s-%s.po' % (appName, translation.id)
                poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
                for message in poFile.messages:
                    setattr(translation, message.id, message.getMessage())
                appyTool.log('Translation "%s" updated from "%s".' % \
                             (translation.id, poName))
Exemplo n.º 5
0
    def installTool(self):
        '''Updates the tool (now that the catalog is created) and updates its
           inner objects (users, groups, translations, documents).'''
        tool = self.app.config
        tool.createOrUpdate(True, None)
        tool.refreshSecurity()
        appyTool = tool.appy()
        appyTool.log('Appy version is "%s".' % appy.version.short)

        # Create the admin user if no user exists.
        try:
            users = self.app.acl_users.getUsers()
        except:
            # When Plone has installed PAS in acl_users this may fail. Plone
            # may still be in the way for migration purposes.
            users = ('admin',) # We suppose there is at least a user.
        if not users:
            appyTool.create('users', noSecurity=True, login='******',
                            password1='admin', password2='admin',
                            email='*****@*****.**', roles=['Manager'])
            appyTool.log('Admin user "admin" created.')

        # Create group "admins" if it does not exist
        if not appyTool.count('Group', noSecurity=True, login='******'):
            appyTool.create('groups', noSecurity=True, login='******',
                            title='Administrators', roles=['Manager'])
            appyTool.log('Group "admins" created.')

        # Create a group for every global role defined in the application
        for role in self.config.applicationGlobalRoles:
            relatedGroup = '%s_group' % role
            if appyTool.count('Group', noSecurity=True, login=relatedGroup):
                continue
            appyTool.create('groups', noSecurity=True, login=relatedGroup,
                            title=relatedGroup, roles=[role])
            appyTool.log('Group "%s", related to global role "%s", was ' \
                         'created.' % (relatedGroup, role))

        # Create POD templates within the tool if required
        for contentType in self.config.attributes.iterkeys():
            appyClass = tool.getAppyClass(contentType)
            if not appyClass: continue # May be an abstract class
            wrapperClass = tool.getAppyClass(contentType, wrapper=True)
            for appyType in wrapperClass.__fields__:
                if appyType.type != 'Pod': continue
                # Find the attribute that stores the template, and store on
                # it the default one specified in the appyType if no
                # template is stored yet.
                attrName = appyTool.getAttributeName('podTemplate', appyClass,
                                                     appyType.name)
                fileObject = getattr(appyTool, attrName)
                if not fileObject or (fileObject.size == 0):
                    # There is no file. Put the one specified in the appyType.
                    fileName = os.path.join(appyTool.getDiskFolder(),
                                            appyType.template)
                    if os.path.exists(fileName):
                        setattr(appyTool, attrName, fileName)
                        appyTool.log('Imported "%s" in the tool in ' \
                                     'attribute "%s"'% (fileName, attrName))
                    else:
                        appyTool.log('Template "%s" was not found!' % \
                                     fileName, type='error')

        # Create or update Translation objects
        translations = [t.o.id for t in appyTool.translations]
        # We browse the languages supported by this application and check
        # whether we need to create the corresponding Translation objects.
        for language in self.languages:
            if language in translations: continue
            # We will create, in the tool, the translation object for this
            # language. Determine first its title.
            langId, langEn, langNat = languages.get(language)
            if langEn != langNat:
                title = '%s (%s)' % (langEn, langNat)
            else:
                title = langEn
            appyTool.create('translations', noSecurity=True,
                            id=language, title=title)
            appyTool.log('Translation object created for "%s".' % language)

        # Execute custom installation code if any
        if hasattr(appyTool, 'onInstall'): appyTool.onInstall()

        # Now, if required, we synchronise every Translation object with the
        # corresponding "po" file on disk.
        if appyTool.loadTranslationsAtStartup:
            appFolder = self.config.diskFolder
            appName = self.config.PROJECTNAME
            i18nFolder = os.path.join(appFolder, 'tr')
            for translation in appyTool.translations:
                # Get the "po" file
                poName = '%s-%s.po' % (appName, translation.id)
                poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
                for message in poFile.messages:
                    setattr(translation, message.id, message.getMessage())
                appyTool.log('Translation "%s" updated from "%s".' % \
                             (translation.id, poName))
Exemplo n.º 6
0
 def getLanguageName(self, code):
     '''Gets the language name (in this language) from a 2-chars language
        p_code.'''
     return languages.get(code)[2]
Exemplo n.º 7
0
    def installTool(self):
        '''Updates the tool (now that the catalog is created) and updates its
           inner objects (users, groups, translations, documents).'''
        tool = self.app.config
        tool.createOrUpdate(True, None)
        appyTool = tool.appy()
        appyTool.log('Appy version is "%s".' % appy.version.short)

        # Execute custom pre-installation code if any.
        if hasattr(appyTool, 'beforeInstall'): appyTool.beforeInstall()

        # Create the default users if they do not exist.
        for login, roles in self.defaultUsers.iteritems():
            if not appyTool.count('User', noSecurity=True, login=login):
                appyTool.create('users',
                                noSecurity=True,
                                id=login,
                                login=login,
                                password1=login,
                                password2=login,
                                email='*****@*****.**' % login,
                                roles=roles)
                appyTool.log('User "%s" created.' % login)

        # Create group "admins" if it does not exist
        if not appyTool.count('Group', noSecurity=True, login='******'):
            appyTool.create('groups',
                            noSecurity=True,
                            login='******',
                            title='Administrators',
                            roles=['Manager'])
            appyTool.log('Group "admins" created.')

        # Create a group for every global role defined in the application
        # (if required).
        if self.config.appConfig.groupsForGlobalRoles:
            for role in self.config.applicationGlobalRoles:
                groupId = role.lower()
                if appyTool.count('Group', noSecurity=True, login=groupId):
                    continue
                appyTool.create('groups',
                                noSecurity=True,
                                login=groupId,
                                title=role,
                                roles=[role])
                appyTool.log('Group "%s", related to global role "%s", was ' \
                             'created.' % (groupId, role))

        # Create or update Translation objects
        translations = [t.o.id for t in appyTool.translations]
        # We browse the languages supported by this application and check
        # whether we need to create the corresponding Translation objects.
        done = []
        for language in self.languages:
            if language in translations: continue
            # We will create, in the tool, the translation object for this
            # language. Determine first its title.
            langId, langEn, langNat = languages.get(language)
            if langEn != langNat:
                title = '%s (%s)' % (langEn, langNat)
            else:
                title = langEn
            appyTool.create('translations',
                            noSecurity=True,
                            id=language,
                            title=title)
            done.append(language)
        if done: appyTool.log('Translations created for %s.' % ', '.join(done))

        # Synchronizes, if required, every Translation object with the
        # corresponding "po" file on disk.
        if appyTool.loadTranslationsAtStartup:
            appFolder = self.config.diskFolder
            appName = self.config.PROJECTNAME
            i18nFolder = os.path.join(appFolder, 'tr')
            done = []
            for translation in appyTool.translations:
                # Get the "po" file
                poName = '%s-%s.po' % (appName, translation.id)
                poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
                for message in poFile.messages:
                    setattr(translation, message.id, message.getMessage())
                done.append(translation.id)
            appyTool.log('translation(s) %s updated (%s messages).' % \
                         (', '.join(done), len(poFile.messages)))

        # Execute custom installation code if any.
        if hasattr(appyTool, 'onInstall'): appyTool.onInstall()