예제 #1
0
파일: zmslog.py 프로젝트: cmeier76/ZMS5
 def LOG(self, severity, info):
   log_severity = severity
   if log_severity == logging.DEBUG:
     log_severity = logging.INFO
   self.LOGGER.log( severity, info)
   if getattr( self, 'copy_to_stdout', True):
     standard.writeStdout(self, '%s %s(%i) %s'%(str(log_time()), severity_string(severity), int(severity), info))
예제 #2
0
def initialize(context):
    """Initialize the product."""

    try:
        """Try to register the product."""

        context.registerClass(
            zms.ZMS,
            permission='Add ZMSs',
            constructors=(zms.manage_addZMSForm, zms.manage_addZMS),
            container_filter=zms.containerFilter,
        )
        context.registerClass(
            zmscustom.ZMSCustom,
            permission='Add ZMSs',
            constructors=(zmscustom.manage_addZMSCustomForm,
                          zmscustom.manage_addZMSCustom),
            container_filter=zmscustom.containerFilter,
        )
        context.registerClass(
            zmssqldb.ZMSSqlDb,
            permission='Add ZMSs',
            constructors=(zmssqldb.manage_addZMSSqlDbForm,
                          zmssqldb.manage_addZMSSqlDb),
            container_filter=zmscustom.containerFilter,
        )
        context.registerClass(
            zmslinkcontainer.ZMSLinkContainer,
            permission='Add ZMSs',
            constructors=(zmscustom.manage_addZMSCustomForm,
                          zmscustom.manage_addZMSCustom),
            container_filter=zmscustom.containerFilter,
        )
        context.registerClass(
            zmslinkelement.ZMSLinkElement,
            permission='Add ZMSs',
            constructors=(zmscustom.manage_addZMSCustomForm,
                          zmscustom.manage_addZMSCustom),
            container_filter=zmscustom.containerFilter,
        )
        context.registerClass(
            _mediadb.MediaDb,
            permission='Add ZMSs',
            constructors=(_mediadb.manage_addMediaDb,
                          _mediadb.manage_addMediaDb),
            container_filter=_mediadb.containerFilter,
        )
        context.registerClass(
            _zmsattributecontainer.ZMSAttributeContainer,
            permission='Add ZMSs',
            constructors=(
                _zmsattributecontainer.manage_addZMSAttributeContainer,
                _zmsattributecontainer.manage_addZMSAttributeContainer),
            container_filter=_zmsattributecontainer.containerFilter,
        )

        # register deprecated classes
        dummy_constructors = (
            zmscustom.manage_addZMSCustomForm,
            zmscustom.manage_addZMSCustom,
        )
        dummy_permission = 'Add ZMSs'
        zms.NoETagAdapter.register()

        # automated registration of language-dictionary
        if not hasattr(OFS.misc_.misc_, 'zms'):
            OFS.misc_.misc_.zms = {}
        OFS.misc_.misc_.zms['langdict'] = _multilangmanager.langdict()

        # automated registration of configuration
        confdict = _confmanager.ConfDict.get()
        OFS.misc_.misc_.zms['confdict'] = confdict

        # automated minification
        confkeys = confdict.keys()
        for confkey in [
                x for x in confkeys
                if x.startswith('gen.') and x + '.include' in confkeys
        ]:
            gen = confdict.get(confkey + '.include').split(',')
            if gen[0] != '':
                standard.writeStdout(
                    context, "automated minification: %s=%s" %
                    (confkey, str(confdict.get(confkey))))
                fileobj = open(translate_path(confdict.get(confkey)), 'w')
                for key in gen:
                    fn = translate_path(confdict.get(key))
                    fh = open(fn, 'r')
                    fc = fh.read()
                    fh.close()
                    l0 = len(fc)
                    if fn.find('.min.') > 0 or fn.find('-min.') > 0:
                        standard.writeStdout(context,
                                             "add %s (%i Bytes)" % (fn, l0))
                    else:
                        # Pack
                        s0 = []
                        s1 = []
                        s2 = []
                        s3 = []
                        if fn.endswith('.js'):
                            s0 = [ \
                                '\$ZMI\.writeDebug\((.*?)\);', \
                                '/\*(\!|\*|\s)((.|\n|\r|\t)*?)\*/', \
                                '//( |-|\$)((.|\r|\t)*?)\n', \
                              ]
                            s1 = [
                                '=', '+', '-', '(', ')', ';', ',', ':', '&',
                                '|'
                            ]
                            s2 = []
                            s3 = [
                                '\t', ' ', '{ ', '{', '{\n', '{', ' }', '}',
                                ';}', '}', ',\n', ',', ';\n', ';', '\n ', '\n',
                                '  ', ' ', '\n\n', '\n', '}\n}\n', '}}\n'
                            ]
                        elif fn.endswith('.css'):
                            s0 = [ \
                                '/\*((.|\n|\r|\t)*?)\*/', \
                              ]
                            s1 = ['=', '+', '{', '}', '(', ';', ',', ':']
                            s2 = [') ', '}\n']
                            s3 = [
                                '\t', ' ', '  ', ' ', '\n\n', '\n', ';}', '}'
                            ]
                        fc = fc.strip()
                        for s in s0:
                            l1 = len(fc)
                            fc = re.sub(s, '', fc)
                        while True:
                            done = False
                            for k in s1:
                                for sk in [' ', '\n']:
                                    while fc.find(sk + k) >= 0:
                                        fc = fc.replace(sk + k, k)
                                        done = True
                                    while k + sk not in s2 and fc.find(
                                            k + sk) >= 0:
                                        fc = fc.replace(k + sk, k)
                                        done = True
                            d = s3
                            for i in range(len(d) // 2):
                                k = d[i * 2]
                                v = d[i * 2 + 1]
                                while fc.find(k) >= 0:
                                    l1 = len(fc)
                                    fc = fc.replace(k, v)
                                    done = True
                            if not done:
                                break
                        l1 = len(fc)
                        standard.writeStdout(
                            context,
                            "add %s (Packed: %i -> %i Bytes)" % (fn, l0, l1))
                    fileobj.write(fc)
                fileobj.close()

        # automated generation of language JavaScript
        from xml.dom import minidom
        filename = os.sep.join([package_home(globals())] +
                               ['import', '_language.xml'])
        standard.writeStdout(
            context,
            "automated generation of language JavaScript: %s" % filename)
        xmldoc = minidom.parse(filename)
        langs = None
        d = {}
        for row in xmldoc.getElementsByTagName('Row'):
            cells = row.getElementsByTagName('Cell')
            if langs is None:
                langs = []
                for cell in cells:
                    data = getData(cell)
                    if data is not None:
                        langs.append(data)
            else:
                l = []
                for cell in cells:
                    data = getData(cell)
                    if cell.attributes.get('ss:Index') is not None:
                        while len(l) < int(
                                cell.attributes['ss:Index'].value) - 1:
                            l.append(None)
                    l.append(data)
                if len(l) > 1:
                    k = l[0]
                    d[k] = {}
                    for i in range(len(l) - 1):
                        d[k][langs[i]] = l[i + 1]

        # populate language-strings to i18n-js
        path = os.sep.join([package_home(globals())] +
                           ['plugins', 'www', 'i18n'])
        if not os.path.exists(path):
            os.mkdir(path)
        for lang in langs:
            filename = os.sep.join([path, '%s.js' % lang])
            standard.writeStdout(context, "generate: %s" % filename)
            fileobj = codecs.open(filename, mode='w', encoding='utf-8')
            fileobj.write('var zmiLangStr={\'lang\':\'%s\'' % lang)
            for k in d.keys():
                v = d[k].get(lang)
                if v is not None:
                    v = v.replace('\'', '\\\'').replace('\n', '\\n')
                    fileobj.write(',\'%s\':\'' % k)
                    fileobj.write(v)
                    fileobj.write('\'')
            fileobj.write('};')
            fileobj.close()

    except:
        """If you can't register the product, dump error. 
        
        Zope will sometimes provide you with access to "broken product" and
        a backtrace of what went wrong, but not always; I think that only 
        works for errors caught in your main product module. 
        
        This code provides traceback for anything that happened in 
        registerClass(), assuming you're running Zope in debug mode."""

        import sys, traceback, string
        type, val, tb = sys.exc_info()
        sys.stderr.write(''.join(traceback.format_exception(type, val, tb)))
        del type, val, tb