Esempio n. 1
0
    def run(self):
        import cherrypy
        from gearshift import toolbox

        # TODO: remove this check once we convert the whole toolbox to genshi
        try:
            import turbokid
        except ImportError:
            # we could not import turbokid, the toolbox will crash with
            # horrible tracebacks...
            print "Please easy_install turbokid, toolbox cannot run without it"
            # sys exit with different than zero error code in case someone
            # is using the error code to know if it worked...
            sys.exit(2)

        # Make sure we have full configuration with every option
        # in it so other plugins or whatever find what they need
        # when starting even inside the toolblox
        conf = get_package_name()
        conf = conf and "%s.config" % conf or None
        conf = config.config_obj(configfile=self.config, modulename=conf)

        if 'global' in conf:
            config.update({'global': conf['global']})

        root = SecureObject(toolbox.Toolbox(),
                            from_any_host(self.hostlist),
                            exclude=['noaccess'])

        cherrypy.tree.mount(root, '/', config=gearshift.config.app)

        # amend some parameters since we are running from the command
        # line in order to change port, log methods...
        config.update({
            'global': {
                'server.socket_port': self.port,
                'server.webpath': '/',
                'server.environment': 'development',
                'server.log_to_screen': True,
                'autoreload.on': False,
                'server.package': 'gearshift.toolbox',
                'log_debug_info_filter.on': False,
                'tools.identity.failure_url': '/noaccess',
                'tools.identity.force_external_redirect': False,
                'tg.defaultview': 'kid',
                'tg.strict_parameters': False,
                'kid.outputformat': 'html default',
                'kid.encoding': 'utf-8'
            }
        })

        gearshift.view.load_engines()
        if self.noopen:
            cherrypy.engine.start()
        else:
            cherrypy.engine.start_with_callback(self.openbrowser)
        cherrypy.engine.block()
Esempio n. 2
0
    def run(self):
        import cherrypy
        from gearshift import toolbox

        # TODO: remove this check once we convert the whole toolbox to genshi
        try:
            import turbokid
        except ImportError:
            # we could not import turbokid, the toolbox will crash with
            # horrible tracebacks...
            print "Please easy_install turbokid, toolbox cannot run without it"
            # sys exit with different than zero error code in case someone
            # is using the error code to know if it worked...
            sys.exit(2)

        # Make sure we have full configuration with every option
        # in it so other plugins or whatever find what they need
        # when starting even inside the toolblox
        conf = get_package_name()
        conf = conf and "%s.config" % conf or None
        conf = config.config_obj(configfile=self.config, modulename=conf)

        if 'global' in conf:
            config.update({'global': conf['global']})

        root = SecureObject(toolbox.Toolbox(), from_any_host(self.hostlist),
                exclude=['noaccess'])

        cherrypy.tree.mount(root, '/', config=gearshift.config.app)

        # amend some parameters since we are running from the command
        # line in order to change port, log methods...
        config.update({'global': {
            'server.socket_port': self.port,
            'server.webpath': '/',
            'server.environment': 'development',
            'server.log_to_screen': True,
            'autoreload.on': False,
            'server.package': 'gearshift.toolbox',
            'log_debug_info_filter.on': False,
            'tools.identity.failure_url': '/noaccess',
            'tools.identity.force_external_redirect': False,
            'tg.defaultview': 'kid',
            'tg.strict_parameters': False,
            'kid.outputformat': 'html default',
            'kid.encoding': 'utf-8'
            }})

        gearshift.view.load_engines()
        if self.noopen:
            cherrypy.engine.start()
        else:
            cherrypy.engine.start_with_callback(self.openbrowser)
        cherrypy.engine.block()
Esempio n. 3
0
    def scan_source_files(self):
        source_files = []
        kid_files = []
        js_files = []
        srcdir = self.options.source_dir or get_package_name().split('.', 1)[0]
        print 'Scanning source directory', srcdir
        for root, dirs, files in os.walk(srcdir):
            if os.path.basename(root).lower() in ('cvs', '.svn'):
                continue
            for fname in files:
                name, ext = os.path.splitext(fname)
                srcfile = os.path.join(root, fname)
                if ext == '.py':
                    source_files.append(srcfile)
                elif ext == '.kid':
                    kid_files.append(srcfile)
                elif ext == '.js':
                    js_files.append(srcfile)
                else:
                    pass # do nothing
        tmp_handle, tmp_potfile = tempfile.mkstemp(
            '.pot', 'tmp', self.locale_dir)
        os.close(tmp_handle)
        potbasename = os.path.basename(tmp_potfile)[:-4]
        pygettext_options = ['-v', '-d', potbasename, \
                '-p', os.path.dirname(tmp_potfile)]
        if self.options.ascii_output:
            pygettext_options.insert(0, '-E')
        pygettext.sys.argv = [''] + pygettext_options + source_files
        pygettext.main()
        if not os.path.exists(tmp_potfile):
            raise ProgramError, 'pygettext failed'
        atexit.register(silent_os_remove, tmp_potfile)
        if kid_files and self.options.kid_support:
            self.scan_kid_files(tmp_potfile, kid_files)

        if js_files and self.options.js_support:
            self.scan_js_files(tmp_potfile, js_files)
        potfile = self.get_potfile_path()
        if os.path.isfile(potfile):
            bakfile = potfile.replace('.pot', '.bak')
            silent_os_remove(bakfile)
            os.rename(potfile, bakfile)
            print 'Backup existing file to', bakfile
        os.rename(tmp_potfile, potfile)
        print 'Message templates written to', potfile
Esempio n. 4
0
    def scan_source_files(self):
        source_files = []
        kid_files = []
        js_files = []
        srcdir = self.options.source_dir or get_package_name().split('.', 1)[0]
        print 'Scanning source directory', srcdir
        for root, dirs, files in os.walk(srcdir):
            if os.path.basename(root).lower() in ('cvs', '.svn'):
                continue
            for fname in files:
                name, ext = os.path.splitext(fname)
                srcfile = os.path.join(root, fname)
                if ext == '.py':
                    source_files.append(srcfile)
                elif ext == '.kid':
                    kid_files.append(srcfile)
                elif ext == '.js':
                    js_files.append(srcfile)
                else:
                    pass  # do nothing
        tmp_handle, tmp_potfile = tempfile.mkstemp('.pot', 'tmp',
                                                   self.locale_dir)
        os.close(tmp_handle)
        potbasename = os.path.basename(tmp_potfile)[:-4]
        pygettext_options = ['-v', '-d', potbasename, \
                '-p', os.path.dirname(tmp_potfile)]
        if self.options.ascii_output:
            pygettext_options.insert(0, '-E')
        pygettext.sys.argv = [''] + pygettext_options + source_files
        pygettext.main()
        if not os.path.exists(tmp_potfile):
            raise ProgramError, 'pygettext failed'
        atexit.register(silent_os_remove, tmp_potfile)
        if kid_files and self.options.kid_support:
            self.scan_kid_files(tmp_potfile, kid_files)

        if js_files and self.options.js_support:
            self.scan_js_files(tmp_potfile, js_files)
        potfile = self.get_potfile_path()
        if os.path.isfile(potfile):
            bakfile = potfile.replace('.pot', '.bak')
            silent_os_remove(bakfile)
            os.rename(potfile, bakfile)
            print 'Backup existing file to', bakfile
        os.rename(tmp_potfile, potfile)
        print 'Message templates written to', potfile
Esempio n. 5
0
    def create_js_messages(self):
        self.load_project_config()
        languages = []
        # we assume the the structure of messages is always
        # <self.locale_dir>/<lang>/LC_MESSAGES ...
        # to extract the languages known to the app
        locale_dir_prefix = self.locale_dir.split(os.sep)
        for fname in self.list_message_catalogs():
            languages.append(fname.split(os.sep)[len(locale_dir_prefix):][0])
        import gearshift.i18n.utils as utils
        srcdir = self.options.source_dir or get_package_name().split('.', 1)[0]
        def list_js_files():
            for root, dirs, files in os.walk(srcdir):
                if os.path.basename(root).lower() in ('cvs', '.svn'):
                    continue
                for fname in files:
                    name, ext = os.path.splitext(fname)
                    srcfile = os.path.join(root, fname)
                    if ext == '.js':
                        yield srcfile
        def escape(arg):
            if "'" in arg:
                return '"%s"' % arg
            return "'%s'" % arg
        for locale in languages:
            def gl():
                return locale
            utils._get_locale = gl
            messages = []
            for filename in list_js_files():
                for key in self.get_strings_in_js(os.path.join(filename))[0]:
                    key = unicode(key)
                    msg = unicode(_(key, locale))
                    messages.append((key, msg))
            # for a final return
            header = """
if (typeof(MESSAGES) == "undefined") {
    MESSAGES = {};
}

LANG = '%s';
_messages = [
""" % locale
            footer = """
             ];

for(var i in _messages) {
  MESSAGES[_messages[i][0]] = _messages[i][1];
 }
"""
            message_block = u",\n".join(["[%s , %s]" % (escape(msgid),
                escape(msgstr)) for msgid, msgstr in messages]).encode("utf-8")
            message_block = message_block + "\n"
            outfilename = os.path.join(srcdir, self.options.js_base_dir,
                    'messages-%s.js' % locale)
            print "Creating message file <%s>." % outfilename
            mf = open(outfilename, "w")
            mf.write(header)
            mf.write(message_block)
            mf.write(footer)
            mf.close()
Esempio n. 6
0
    def create_js_messages(self):
        self.load_project_config()
        languages = []
        # we assume the the structure of messages is always
        # <self.locale_dir>/<lang>/LC_MESSAGES ...
        # to extract the languages known to the app
        locale_dir_prefix = self.locale_dir.split(os.sep)
        for fname in self.list_message_catalogs():
            languages.append(fname.split(os.sep)[len(locale_dir_prefix):][0])
        import gearshift.i18n.utils as utils
        srcdir = self.options.source_dir or get_package_name().split('.', 1)[0]

        def list_js_files():
            for root, dirs, files in os.walk(srcdir):
                if os.path.basename(root).lower() in ('cvs', '.svn'):
                    continue
                for fname in files:
                    name, ext = os.path.splitext(fname)
                    srcfile = os.path.join(root, fname)
                    if ext == '.js':
                        yield srcfile

        def escape(arg):
            if "'" in arg:
                return '"%s"' % arg
            return "'%s'" % arg

        for locale in languages:

            def gl():
                return locale

            utils._get_locale = gl
            messages = []
            for filename in list_js_files():
                for key in self.get_strings_in_js(os.path.join(filename))[0]:
                    key = unicode(key)
                    msg = unicode(_(key, locale))
                    messages.append((key, msg))
            # for a final return
            header = """
if (typeof(MESSAGES) == "undefined") {
    MESSAGES = {};
}

LANG = '%s';
_messages = [
""" % locale
            footer = """
             ];

for(var i in _messages) {
  MESSAGES[_messages[i][0]] = _messages[i][1];
 }
"""
            message_block = u",\n".join([
                "[%s , %s]" % (escape(msgid), escape(msgstr))
                for msgid, msgstr in messages
            ]).encode("utf-8")
            message_block = message_block + "\n"
            outfilename = os.path.join(srcdir, self.options.js_base_dir,
                                       'messages-%s.js' % locale)
            print "Creating message file <%s>." % outfilename
            mf = open(outfilename, "w")
            mf.write(header)
            mf.write(message_block)
            mf.write(footer)
            mf.close()