| 1 | ################################################################################
|
|---|
| 2 | # Initialisation file for the ZMS Product for Zope
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | #
|
|---|
| 18 | ################################################################################
|
|---|
| 19 |
|
|---|
| 20 | """ZMS Product"""
|
|---|
| 21 |
|
|---|
| 22 | # Documentation string.
|
|---|
| 23 | __doc__ = """initialization module."""
|
|---|
| 24 | # Version string.
|
|---|
| 25 | __version__ = '0.1'
|
|---|
| 26 |
|
|---|
| 27 | # Imports.
|
|---|
| 28 | from App.Common import package_home
|
|---|
| 29 | from App.ImageFile import ImageFile
|
|---|
| 30 | from DateTime.DateTime import DateTime
|
|---|
| 31 | import ConfigParser
|
|---|
| 32 | import OFS.misc_
|
|---|
| 33 | import os
|
|---|
| 34 | import re
|
|---|
| 35 | import stat
|
|---|
| 36 | # Product Imports.
|
|---|
| 37 | import _globals
|
|---|
| 38 | import zms
|
|---|
| 39 | import zmscustom
|
|---|
| 40 | import zmssqldb
|
|---|
| 41 | import zmslinkcontainer
|
|---|
| 42 | import zmslinkelement
|
|---|
| 43 | import _multilangmanager
|
|---|
| 44 | import _mediadb
|
|---|
| 45 | import _sequence
|
|---|
| 46 | import _zmsattributecontainer
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | ################################################################################
|
|---|
| 50 | # Define the initialize() function.
|
|---|
| 51 | ################################################################################
|
|---|
| 52 |
|
|---|
| 53 | def initialize(context):
|
|---|
| 54 | """Initialize the product."""
|
|---|
| 55 |
|
|---|
| 56 | try:
|
|---|
| 57 | """Try to register the product."""
|
|---|
| 58 |
|
|---|
| 59 | context.registerClass(
|
|---|
| 60 | zms.ZMS,
|
|---|
| 61 | permission = 'Add ZMSs',
|
|---|
| 62 | constructors = ( zms.manage_addZMSForm, zms.manage_addZMS),
|
|---|
| 63 | container_filter = zms.containerFilter,
|
|---|
| 64 | )
|
|---|
| 65 | context.registerClass(
|
|---|
| 66 | zmscustom.ZMSCustom,
|
|---|
| 67 | permission = 'Add ZMSs',
|
|---|
| 68 | constructors = (zmscustom.manage_addZMSCustomForm, zmscustom.manage_addZMSCustom),
|
|---|
| 69 | container_filter = zmscustom.containerFilter,
|
|---|
| 70 | )
|
|---|
| 71 | context.registerClass(
|
|---|
| 72 | zmssqldb.ZMSSqlDb,
|
|---|
| 73 | permission = 'Add ZMSs',
|
|---|
| 74 | constructors = (zmssqldb.manage_addZMSSqlDbForm, zmssqldb.manage_addZMSSqlDb),
|
|---|
| 75 | container_filter = zmscustom.containerFilter,
|
|---|
| 76 | )
|
|---|
| 77 | context.registerClass(
|
|---|
| 78 | zmslinkcontainer.ZMSLinkContainer,
|
|---|
| 79 | permission = 'Add ZMSs',
|
|---|
| 80 | constructors = (zmslinkcontainer.manage_addZMSLinkContainer, zmslinkcontainer.manage_addZMSLinkContainer),
|
|---|
| 81 | container_filter = zmscustom.containerFilter,
|
|---|
| 82 | )
|
|---|
| 83 | context.registerClass(
|
|---|
| 84 | zmslinkelement.ZMSLinkElement,
|
|---|
| 85 | permission = 'Add ZMSs',
|
|---|
| 86 | constructors = (zmslinkelement.manage_addZMSLinkElementForm, zmslinkelement.manage_addZMSLinkElement),
|
|---|
| 87 | container_filter = zmscustom.containerFilter,
|
|---|
| 88 | )
|
|---|
| 89 | context.registerClass(
|
|---|
| 90 | _mediadb.MediaDb,
|
|---|
| 91 | permission = 'Add ZMSs',
|
|---|
| 92 | constructors = (_mediadb.manage_addMediaDb, _mediadb.manage_addMediaDb),
|
|---|
| 93 | icon = 'www/acl_mediadb.gif',
|
|---|
| 94 | container_filter = _mediadb.containerFilter,
|
|---|
| 95 | )
|
|---|
| 96 | context.registerClass(
|
|---|
| 97 | _zmsattributecontainer.ZMSAttributeContainer,
|
|---|
| 98 | permission = 'Add ZMSs',
|
|---|
| 99 | constructors = (_zmsattributecontainer.manage_addZMSAttributeContainer, _zmsattributecontainer.manage_addZMSAttributeContainer),
|
|---|
| 100 | container_filter = _zmsattributecontainer.containerFilter,
|
|---|
| 101 | )
|
|---|
| 102 |
|
|---|
| 103 | # register deprecated classes
|
|---|
| 104 | dummy_constructors = (zmscustom.manage_addZMSCustomForm, zmscustom.manage_addZMSCustom,)
|
|---|
| 105 | dummy_permission = 'Add ZMSs'
|
|---|
| 106 |
|
|---|
| 107 | # automated registration for util
|
|---|
| 108 | OFS.misc_.misc_.zms['initutil']=_globals.initutil()
|
|---|
| 109 |
|
|---|
| 110 | # automated registration of language-dictionary
|
|---|
| 111 | OFS.misc_.misc_.zms['langdict']=_multilangmanager.langdict()
|
|---|
| 112 |
|
|---|
| 113 | # automated registration of configuration
|
|---|
| 114 | confdict = {'last_modified':long(DateTime().timeTime())}
|
|---|
| 115 | PRODUCT_HOME = os.path.dirname(os.path.abspath(__file__))
|
|---|
| 116 | cfp = ConfigParser.ConfigParser()
|
|---|
| 117 | cfp.readfp(open(os.path.join(PRODUCT_HOME,'etc','zms.conf')))
|
|---|
| 118 | for section in cfp.sections():
|
|---|
| 119 | for option in cfp.options(section):
|
|---|
| 120 | confdict[section+'.'+option] = cfp.get( section, option)
|
|---|
| 121 | OFS.misc_.misc_.zms['confdict']=confdict
|
|---|
| 122 |
|
|---|
| 123 | # automated registration for other resources
|
|---|
| 124 | for img_path in ['www/']:
|
|---|
| 125 | path = package_home(globals()) + os.sep + img_path
|
|---|
| 126 | for file in os.listdir(path):
|
|---|
| 127 | filepath = path + os.sep + file
|
|---|
| 128 | mode = os.stat(filepath)[stat.ST_MODE]
|
|---|
| 129 | if not stat.S_ISDIR(mode):
|
|---|
| 130 | registerImage(filepath,file)
|
|---|
| 131 |
|
|---|
| 132 | # automated combination of external CSS
|
|---|
| 133 | gen = confdict.get('zmi.css.gen','').split(',')
|
|---|
| 134 | if gen[0] != '':
|
|---|
| 135 | print "automated combination of external CSS:",gen
|
|---|
| 136 | fileobj = open(translate_path(confdict.get('zmi.all')),'w')
|
|---|
| 137 | for key in gen:
|
|---|
| 138 | fn = translate_path(confdict.get('zmi.%s'%key))
|
|---|
| 139 | fh = open(fn,'r')
|
|---|
| 140 | fc = fh.read()
|
|---|
| 141 | fh.close()
|
|---|
| 142 | s0 = len(fc)
|
|---|
| 143 | # Pack
|
|---|
| 144 | fc = fc.strip()
|
|---|
| 145 | fc = re.sub( '/\*((.|\n|\r|\t)*?)\*/', '', fc)
|
|---|
| 146 | while True:
|
|---|
| 147 | done = False
|
|---|
| 148 | for k in ['=','+','{','}','(',';',',',':']:
|
|---|
| 149 | for sk in [' ','\n']:
|
|---|
| 150 | while fc.find(sk+k)>=0:
|
|---|
| 151 | fc=fc.replace(sk+k,k)
|
|---|
| 152 | done = True
|
|---|
| 153 | while k+sk not in [') ','}\n'] and fc.find(k+sk)>=0:
|
|---|
| 154 | fc=fc.replace(k+sk,k)
|
|---|
| 155 | done = True
|
|---|
| 156 | d = ['\t','',' ',' ','\n\n','\n',';}','}']
|
|---|
| 157 | for i in range(len(d)/2):
|
|---|
| 158 | k = d[i*2]
|
|---|
| 159 | v = d[i*2+1]
|
|---|
| 160 | while fc.find(k) >= 0:
|
|---|
| 161 | fc = fc.replace(k,v)
|
|---|
| 162 | done = True
|
|---|
| 163 | if not done:
|
|---|
| 164 | break
|
|---|
| 165 | s1 = len(fc)
|
|---|
| 166 | print "add",fn,"(Packed:",s0,"->",s1,"Bytes)"
|
|---|
| 167 | fileobj.write(fc)
|
|---|
| 168 | fileobj.close()
|
|---|
| 169 |
|
|---|
| 170 | # automated combination of external JavaScript
|
|---|
| 171 | gen = confdict.get('jquery.libs.gen','').split(',')
|
|---|
| 172 | if gen[0] != '':
|
|---|
| 173 | print "automated combination of external JavaScript:",gen
|
|---|
| 174 | fileobj = open(translate_path(confdict.get('jquery.all')),'w')
|
|---|
| 175 | for key in gen:
|
|---|
| 176 | fn = translate_path(confdict.get('jquery.%s'%key))
|
|---|
| 177 | fh = open(fn,'r')
|
|---|
| 178 | fc = fh.read()
|
|---|
| 179 | fh.close()
|
|---|
| 180 | s0 = len(fc)
|
|---|
| 181 | # Pack
|
|---|
| 182 | fc = fc.strip()
|
|---|
| 183 | fc = re.sub( '/\*(\!|\*|\s)((.|\n|\r|\t)*?)\*/', '', fc)
|
|---|
| 184 | fc = re.sub( '//( |-|\$)((.|\r|\t)*?)\n', '', fc)
|
|---|
| 185 | while True:
|
|---|
| 186 | done = False
|
|---|
| 187 | for k in ['=','+','-','(',')',';',',',':','&','|']:
|
|---|
| 188 | for sk in [' ','\n']:
|
|---|
| 189 | while fc.find(sk+k)>=0:
|
|---|
| 190 | fc=fc.replace(sk+k,k)
|
|---|
| 191 | done = True
|
|---|
| 192 | while fc.find(k+sk)>=0:
|
|---|
| 193 | fc=fc.replace(k+sk,k)
|
|---|
| 194 | done = True
|
|---|
| 195 | d = ['\t',' ','{ ','{','{\n','{',' }','}',';}','}',',\n',',','\n ','\n',' ',' ','\n\n','\n','}\n}\n','}}\n']
|
|---|
| 196 | for i in range(len(d)/2):
|
|---|
| 197 | k = d[i*2]
|
|---|
| 198 | v = d[i*2+1]
|
|---|
| 199 | while fc.find(k) >= 0:
|
|---|
| 200 | fc = fc.replace(k,v)
|
|---|
| 201 | done = True
|
|---|
| 202 | if not done:
|
|---|
| 203 | break
|
|---|
| 204 | s1 = len(fc)
|
|---|
| 205 | print "add",fn,"(Packed:",s0,"->",s1,"Bytes)"
|
|---|
| 206 | fileobj.write(fc)
|
|---|
| 207 | fileobj.close()
|
|---|
| 208 |
|
|---|
| 209 | except:
|
|---|
| 210 | """If you can't register the product, dump error.
|
|---|
| 211 |
|
|---|
| 212 | Zope will sometimes provide you with access to "broken product" and
|
|---|
| 213 | a backtrace of what went wrong, but not always; I think that only
|
|---|
| 214 | works for errors caught in your main product module.
|
|---|
| 215 |
|
|---|
| 216 | This code provides traceback for anything that happened in
|
|---|
| 217 | registerClass(), assuming you're running Zope in debug mode."""
|
|---|
| 218 |
|
|---|
| 219 | import sys, traceback, string
|
|---|
| 220 | type, val, tb = sys.exc_info()
|
|---|
| 221 | sys.stderr.write(string.join(traceback.format_exception(type, val, tb), ''))
|
|---|
| 222 | del type, val, tb
|
|---|
| 223 |
|
|---|
| 224 | def translate_path(s):
|
|---|
| 225 | """
|
|---|
| 226 | translate path
|
|---|
| 227 | """
|
|---|
| 228 | ZMS_HOME = package_home(globals())
|
|---|
| 229 | if s.startswith('/++resource++zms_/'):
|
|---|
| 230 | l = ['plugins','www']+s.split('/')[2:]
|
|---|
| 231 | elif s.startswith('/misc_/zms/'):
|
|---|
| 232 | l = ['www']+s.split('/')[3:]
|
|---|
| 233 | return os.sep.join([ZMS_HOME]+l)
|
|---|
| 234 |
|
|---|
| 235 | def registerImage(filepath,s):
|
|---|
| 236 | """
|
|---|
| 237 | manual icon registration
|
|---|
| 238 | """
|
|---|
| 239 | icon=ImageFile(filepath,globals())
|
|---|
| 240 | icon.__roles__ = None
|
|---|
| 241 | OFS.misc_.misc_.zms[s]=icon
|
|---|
| 242 |
|
|---|
| 243 | ################################################################################
|
|---|