예제 #1
0
 def _make_resource(cls, folder, name, *args, **kw):
     ShopFolder._make_resource(cls, folder, name, *args, **kw)
     # Image
     body = lfs.open(get_abspath(cls.img)).read()
     img = Image._make_resource(Image, folder,
                                '%s/logo.png' % name, body=body,
                                **{'state': 'public'})
     # Load zones
     shop = get_context().resource.parent
     zones = []
     handler = shop.get_resource('countries-zones').handler
     for record in handler.get_records():
         zones.append(handler.get_record_value(record, 'title'))
     # Create history
     cls.shipping_history_cls._make_resource(cls.shipping_history_cls,
                           folder, '%s/history' % name)
     # Import CSV with prices
     ShippingPrices._make_resource(ShippingPrices, folder,
                                   '%s/prices' % name)
     if getattr(cls, 'csv', None):
         table = ShippingPricesTable()
         csv = ro_database.get_handler(get_abspath(cls.csv), ShippingPricesCSV)
         for row in csv.get_rows():
             table.add_record(
               {'zone': str(zones.index(row.get_value('zone'))),
                'max-weight': row.get_value('max-weight'),
                'price': row.get_value('price')})
         folder.set_handler('%s/prices' % name, table)
예제 #2
0
파일: registry.py 프로젝트: hforge/shop
def register_shop(package, name):
    base_path = '../%s/%s' % (package, name)
    # Register shop
    shops.append(name)
    # Import project
    exec('import %s.%s' % (package, name))
    # Get config
    config_path = get_abspath('%s/setup.conf' % base_path)
    config = ro_database.get_handler(config_path, ITWSHOPConfig)
    # Register skin
    register_shop_skin(u'Skin %s' % name, package, '%s/ui/' % name, name, config)
    # Register domain for i18n
    register_domain(name, get_abspath('%s/locale' % base_path))
    # Register modules
    project_modules = []
    modules_path = get_abspath(join_paths(base_path, 'modules'))
    if exists(modules_path) or name == 'ecox':
        project_modules = [f for f in listdir(modules_path)
              if isdir(get_abspath('%s/%s' % (modules_path, f)))]
        for m in project_modules:
            exec('import %s.%s.modules.%s' % (package, name, m))
    # Print
    print 'Name: ',  name
    print 'URL: ', config.get_value('url')
    print 'Modules: [%s], %s' % (len(project_modules), project_modules)
예제 #3
0
def register_shop(package, name):
    base_path = '../%s/%s' % (package, name)
    # Register shop
    shops.append(name)
    # Import project
    exec('import %s.%s' % (package, name))
    # Get config
    config_path = get_abspath('%s/setup.conf' % base_path)
    config = ro_database.get_handler(config_path, ITWSHOPConfig)
    # Register skin
    register_shop_skin(u'Skin %s' % name, package, '%s/ui/' % name, name,
                       config)
    # Register domain for i18n
    register_domain(name, get_abspath('%s/locale' % base_path))
    # Register modules
    project_modules = []
    modules_path = get_abspath(join_paths(base_path, 'modules'))
    if exists(modules_path) or name == 'ecox':
        project_modules = [
            f for f in listdir(modules_path)
            if isdir(get_abspath('%s/%s' % (modules_path, f)))
        ]
        for m in project_modules:
            exec('import %s.%s.modules.%s' % (package, name, m))
    # Print
    print 'Name: ', name
    print 'URL: ', config.get_value('url')
    print 'Modules: [%s], %s' % (len(project_modules), project_modules)
예제 #4
0
파일: ws_neutral.py 프로젝트: hforge/itws
    def init_resource(self, **kw):
        kw['website_is_open'] = 'extranet'
        # TODO allow to choose language at website creation
        default_language = 'en'
        # Initialize ikaaro website (Parent class)
        WebSite.init_resource(self, **kw)
        # Init bars
        Website_BarAware.init_resource(self, **kw)
        # Add a sitemap
        self.make_resource('sitemap.xml', self.sitemap_class)
        # Create Robots.txt
        self.make_resource('robots.txt', RobotsTxt)
        # Add an image folder
        self.make_resource('images', Folder)
        # Tags
        self.make_resource('tags', self.tagsfolder_class,
                           language=default_language)
        # Add default news folder
        self.make_resource('news', self.newsfolder_class)
        # About
        self.make_resource('about-itws', AboutITWS,
                       title={default_language: MSG(u'About ITWS').gettext()})

        # Add link to news in menu
        theme = self.get_resource('theme')
        menu = theme.get_resource('menu/menu')
        menu.add_new_record({'path': '/news/',
                             'title': Property(MSG(u'News').gettext(),
                                               language='en')})
        # Create a 'Welcome' html-content item in ws-data
        # Order this item in the contentbar
        path = get_abspath(self.first_contenbar)
        handler = ro_database.get_handler('%s.%s' % (path, default_language),
                                          XHTMLFile)
        ws_data = self.get_resource('ws-data')
        ws_data.make_resource('welcome', HTMLContent,
                  title={default_language: MSG(u'Welcome').gettext()},
                  state='public',
                  display_title=True,
                  body=handler.to_str(),
                  language=default_language)
        table = ws_data.get_resource('order-contentbar')
        table.add_new_record({'name': 'welcome'})

        # Create a 'Welcome' html-content item in repository
        # Order this item in the sidebar
        path = get_abspath(self.first_sidebar)
        handler = ro_database.get_handler('%s.%s' % (path, default_language),
                                          XHTMLFile)
        repository = self.get_resource('repository')
        repository.make_resource('first-sidebar', HTMLContent,
                  title={default_language: MSG(u'My first sidebar').gettext()},
                  state='public',
                  display_title=True,
                  body=handler.to_str(),
                  language=default_language)
        table = ws_data.get_resource('order-sidebar')
        table.add_new_record({'name': 'first-sidebar'})
예제 #5
0
파일: root_views.py 프로젝트: hforge/ikaaro
    def get_namespace(self, resource, context):
        namespace = {}
        # Credits
        credits = get_abspath('CREDITS.txt')
        lines = lfs.open(credits).readlines()
        names = [ x[2:].strip() for x in lines if x.startswith('  ') ]
        namespace['hackers'] = names

        # Installed software
        root = context.root
        is_admin = root.is_admin(context.user, resource)
        namespace['is_admin'] = is_admin

        if is_admin:
            package2title = {
                'gio': u'pygobject',
                'lpod': u'lpOD',
                'sys': u'Python',
                'os': MSG(u'Operating System')}
            packages = [
                {'name': package2title.get(x, x),
                 'version': y or MSG('no version found')}
                for x, y in root.get_version_of_packages(context).items() ]

            location = (getuser(), gethostname(), context.server.target)
            namespace['packages'] = packages
            namespace['location'] = u'%s@%s:%s' % location

        # Ok
        return namespace
예제 #6
0
 def init_resource(self, **kw):
     super(Theme, self).init_resource(**kw)
     # Access
     self.set_value('share', 'everybody')
     # CSS file
     path = get_abspath('ui/themes/style.css')
     data = open(path).read()
     self.set_value('style', data)
     # Logo
     path = get_abspath('ui/themes/logo.png')
     data = open(path).read()
     self.set_value('logo', data)
     # Banner
     path = get_abspath('ui/themes/banner.jpg')
     data = open(path).read()
     self.set_value('banner', data)
예제 #7
0
    def get_namespace(self, resource, context):
        namespace = {}
        # Credits
        credits = get_abspath('CREDITS.txt')
        lines = lfs.open(credits).readlines()
        names = [x[2:].strip() for x in lines if x.startswith('  ')]
        namespace['hackers'] = names

        # Installed software
        root = context.root
        is_admin = root.is_admin(context.user, resource)
        namespace['is_admin'] = is_admin

        if is_admin:
            package2title = {
                'gio': u'pygobject',
                'lpod': u'lpOD',
                'sys': u'Python',
                'os': MSG(u'Operating System')
            }
            packages = [{
                'name': package2title.get(x, x),
                'version': y or MSG('no version found')
            } for x, y in root.get_version_of_packages(context).items()]

            location = (getuser(), gethostname(), context.server.target)
            namespace['packages'] = packages
            namespace['location'] = u'%s@%s:%s' % location

        # Ok
        return namespace
예제 #8
0
    def get_namespace(self, resource, context):
        namespace = {}
        # Credits
        credits = get_abspath("CREDITS.txt")
        lines = lfs.open(credits).readlines()
        names = [x[2:].strip() for x in lines if x.startswith("  ")]
        namespace["hackers"] = names

        # Installed software
        root = context.root
        is_admin = root.is_admin(context.user, resource)
        namespace["is_admin"] = is_admin

        if is_admin:
            package2title = {"gio": u"pygobject", "lpod": u"lpOD", "sys": u"Python", "os": MSG(u"Operating System")}
            packages = [
                {"name": package2title.get(x, x), "version": y or MSG("no version found")}
                for x, y in root.get_version_of_packages(context).items()
            ]

            location = (getuser(), gethostname(), context.server.target)
            namespace["packages"] = packages
            namespace["location"] = u"%s@%s:%s" % location

        # Ok
        return namespace
예제 #9
0
def register_shop_skin(title, package, path, name, config=None):
    from skin import ShopSkin
    path = '../%s/%s' % (package, path)
    path = get_abspath(path)
    # Register skin
    register_skin(name, ShopSkin(path, config=config))
    shop_skins.append({'name': '/ui/%s' % name, 'value': title})
예제 #10
0
 def init_resource(self, **kw):
     super(Theme, self).init_resource(**kw)
     # Access
     self.set_value('share', 'everybody')
     # CSS file
     path = get_abspath('ui/ikaaro/themes/style.css')
     data = open(path).read()
     self.set_value('style', data)
     # Logo
     path = get_abspath('ui/ikaaro/themes/logo.png')
     data = open(path).read()
     self.set_value('logo', data)
     # Banner
     path = get_abspath('ui/ikaaro/themes/banner.jpg')
     data = open(path).read()
     self.set_value('banner', data)
예제 #11
0
파일: registry.py 프로젝트: hforge/shop
def register_shop_skin(title, package, path, name, config=None):
    from skin import ShopSkin
    path = '../%s/%s' % (package, path)
    path = get_abspath(path)
    # Register skin
    register_skin(name, ShopSkin(path, config=config))
    shop_skins.append({'name': '/ui/%s' % name,
                       'value': title})
예제 #12
0
파일: server.py 프로젝트: matrixorz/ikaaro
 def listen(self, address, port):
     super(Server, self).listen(address, port)
     # Set ui
     context = StaticContext(local_path=get_abspath('ui'))
     self.set_context('/ui', context)
     for name in skin_registry:
         skin = skin_registry[name]
         context = StaticContext(local_path=skin.key)
         self.set_context('/ui/%s' % name, context)
예제 #13
0
파일: server.py 프로젝트: staverne/ikaaro
 def listen(self, address, port):
     super(Server, self).listen(address, port)
     # Set ui
     context = StaticContext(local_path=get_abspath('ui'))
     self.set_context('/ui', context)
     for name in skin_registry:
         skin = skin_registry[name]
         context = StaticContext(local_path=skin.key)
         self.set_context('/ui/%s' % name, context)
예제 #14
0
파일: theme.py 프로젝트: nkhine/ztm-ikaaro
 def init_resource(self, **kw):
     # Init resource
     BaseTheme.init_resource(self, **kw)
     # Get language
     website = self.parent
     language = website.get_default_language()
     # Banner (background set with CSS)
     path = get_abspath("data/k2-banner-ties.jpg")
     image = ro_database.get_handler(path, FileHandler)
     self.make_resource(
         "banner-itws",
         Image,
         body=image.to_str(),
         extension="jpg",
         filename="banner-itws.jpg",
         format="image/jpeg",
         state="public",
     )
     # Set banner title
     vhosts = website.get_property("vhosts")
     if vhosts:
         banner_title = vhosts[0]
     else:
         banner_title = website.get_title()
     self.set_property("banner_title", banner_title, language=language)
     # CSS file
     # TODO Add an API in ikaaro that allow to easily change CSS...
     path = get_abspath("ui/themes/style.css")
     body = open(path).read()
     style = self.get_resource("style")
     style.handler.load_state_from_string(body)
     style.handler.set_changed()
     # Custom 404
     self.make_resource("404", NotFoundPage)
     # Add footer
     self.make_resource("footer", FooterFolder)
     menu = self.get_resource("footer/menu")
     title = Property(MSG(u"Powered by itws").gettext(), language=language)
     menu.add_new_record({"title": title, "path": "/about-itws"})
     title = Property(MSG(u"Contact us").gettext(), language=language)
     menu.add_new_record({"title": title, "path": "/;contact"})
     # Turning footer
     self.make_resource("turning-footer", TurningFooterFolder)
예제 #15
0
파일: countries.py 프로젝트: hforge/shop
 def _make_resource(cls, folder, name, *args, **kw):
     OrderedTable._make_resource(cls, folder, name)
     table = BaseCountriesZones()
     zones = []
     csv = ro_database.get_handler(get_abspath('data/countries.csv'), CSVFile)
     for line in csv.get_rows():
         zone = unicode(line[1], 'utf-8')
         if zone not in zones:
             zones.append(zone)
             table.add_record({'title': Property(zone, language='fr')})
     folder.set_handler(name, table)
예제 #16
0
파일: theme.py 프로젝트: hforge/itws
 def init_resource(self, **kw):
     # Init resource
     BaseTheme.init_resource(self, **kw)
     # Get language
     website = self.parent
     language = website.get_default_language()
     # Banner (background set with CSS)
     path = get_abspath('data/k2-banner-ties.jpg')
     image = ro_database.get_handler(path, FileHandler)
     self.make_resource('banner-itws', Image, body=image.to_str(),
                        extension='jpg', filename='banner-itws.jpg',
                        format='image/jpeg', state='public')
     # Set banner title
     vhosts = website.get_property('vhosts')
     if vhosts:
         banner_title = vhosts[0]
     else:
         banner_title = website.get_title()
     self.set_property('banner_title', banner_title, language=language)
     # Drop logo property since itws uses banner_path property
     self.del_property('logo')
     # CSS file
     # TODO Add an API in ikaaro that allow to easily change CSS...
     path = get_abspath('ui/themes/style.css')
     body = open(path).read()
     style = self.get_resource('style')
     style.handler.load_state_from_string(body)
     style.handler.set_changed()
     # Custom 404
     self.make_resource('404', NotFoundPage)
     # Add footer
     self.make_resource('footer', FooterFolder)
     menu = self.get_resource('footer/menu')
     title = Property(MSG(u'Powered by itws').gettext(),
                      language=language)
     menu.add_new_record({'title': title, 'path': '/about-itws'})
     title = Property(MSG(u'Contact us').gettext(),
                      language=language)
     menu.add_new_record({'title': title, 'path': '/;contact'})
     # Turning footer
     self.make_resource('turning-footer', TurningFooterFolder)
예제 #17
0
 def _make_resource(cls, folder, name, *args, **kw):
     OrderedTable._make_resource(cls, folder, name)
     table = BaseCountriesZones()
     zones = []
     csv = ro_database.get_handler(get_abspath('data/countries.csv'),
                                   CSVFile)
     for line in csv.get_rows():
         zone = unicode(line[1], 'utf-8')
         if zone not in zones:
             zones.append(zone)
             table.add_record({'title': Property(zone, language='fr')})
     folder.set_handler(name, table)
예제 #18
0
 def init_resource(self, **kw):
     Diaporama.init_resource(self, **kw)
     # Check if the loading image is here!
     context = get_context()
     # XXX from handler level to the resource one,
     # finding the site_root and indexing image
     site_root = context.site_root
     if site_root.get_resource('images/loading', soft=True) is None:
         path = get_abspath('ui/loading.gif')
         with open(path) as file:
             body = file.read()
         site_root.make_resource('images/loading', Image,
                 format='image/gif', filename='loading.gif',
                 extension='gif', state='public', body=body)
예제 #19
0
파일: countries.py 프로젝트: hforge/shop
 def _make_resource(cls, folder, name, *args, **kw):
     Table._make_resource(cls, folder, name)
     # Import CSV with list of countries
     zones = []
     table = BaseCountries()
     csv = ro_database.get_handler(get_abspath('data/countries.csv'), CSVFile)
     for line in csv.get_rows():
         country = unicode(line[0], 'utf-8')
         zone = unicode(line[1], 'utf-8')
         if zone not in zones:
             zones.append(zone)
         table.add_record({'title': Property(country, language='fr'),
                           'zone': str(zones.index(zone)),
                           'enabled': True})
     folder.set_handler(name, table)
예제 #20
0
 def _make_resource(cls, folder, name, *args, **kw):
     Table._make_resource(cls, folder, name)
     # Import CSV with list of countries
     zones = []
     table = BaseCountries()
     csv = ro_database.get_handler(get_abspath('data/countries.csv'),
                                   CSVFile)
     for line in csv.get_rows():
         country = unicode(line[0], 'utf-8')
         zone = unicode(line[1], 'utf-8')
         if zone not in zones:
             zones.append(zone)
         table.add_record({
             'title': Property(country, language='fr'),
             'zone': str(zones.index(zone)),
             'enabled': True
         })
     folder.set_handler(name, table)
예제 #21
0
 def get_template(self, resource, context):
     style = resource.get_property('style')
     path = get_abspath('addthis_%s.stl' % style)
     return ro_database.get_handler(path, XMLFile)
예제 #22
0
    # (3) Remove enclosing format
    while center:
        if (center[0][0] == START_FORMAT and center[-1][0] == END_FORMAT
                and center[0][1][1] == center[-1][1][1]):
            left.append(center.pop(0))
            right.insert(0, center.pop())
        else:
            break

    # (4) Remove the spaces
    left, center, right = _remove_spaces(left, center, right, keep_spaces)

    return left, center, right


default_srx_handler = get_abspath('srx/default.srx', 'itools')
default_srx_handler = ro_database.get_handler(default_srx_handler, SRXFile)


def _split_message(message, srx_handler=None):
    # Concatenation!
    concat_text = []
    for type, value, line in message:
        if type == TEXT:
            concat_text.append(value[0])
    concat_text = u''.join(concat_text)

    # Get the rules
    if srx_handler is None:
        srx_handler = default_srx_handler
    # XXX we must handle the language here!
예제 #23
0
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Taverne Sylvain <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import get_abspath

# Import from ikaaro
from ikaaro.skins import register_skin

# Import from itws
from base import Feed_View

# Register skin
register_skin('feed_views', get_abspath('../ui/feed_views/'))

# Silent pyflakes
Feed_View
예제 #24
0
# -*- coding: UTF-8 -*-
# Copyright (C) 2005-2007 Juan David Ibáñez Palomar <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from tmx import TMXFile, Sentence, TMXUnit, TMXNote
from itools.xml import register_dtd

__all__ = ['TMXFile', 'Sentence', 'TMXUnit', 'TMXNote']

add_type('application/x-tmx', '.tmx')

# Register DTD
register_dtd(get_abspath('tmx14.dtd'), uri='http://www.lisa.org/tmx/tmx14.dtd')
예제 #25
0
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from itools.xml import register_dtd
from xliff import XLFFile, XLFUnit, XLFNote, File


__all__ = ['XLFFile', 'XLFUnit', 'XLFNote', 'File']


# Register mime type
add_type('application/x-xliff', '.xlf')

# Register DTD
# -//XLIFF//DTD XLIFF//EN
register_dtd(get_abspath('xliff.dtd'),
             urn='urn:publicid:-:XLIFF:DTD+XLIFF:EN')

예제 #26
0
 def get_template(self, resource, context):
     path = get_abspath('twitter.stl')
     return ro_database.get_handler(path, XMLFile)
예제 #27
0
 def rte_language(self):
     path = get_abspath('ui/ikaaro/tiny_mce/langs')
     languages = [ x[:-3] for x in lfs.get_names(path) ]
     return get_context().accept_language.select_language(languages)
예제 #28
0
        ext_modules.append(extension)

    # DOC indexation
    try:
        flags = get_compile_flags('wv2-config --cflags --libs')
    except EnvironmentError:
        err = "[WARNING] wv2 not found, DOC indexation won't work"
        print >> stderr, err
    else:
        sources = ['itools/office/doctotext.cc']
        extension = Extension('itools.office.doctotext', sources, **flags)
        ext_modules.append(extension)

    # Ok
    if itools_is_available:
        itools_setup(get_abspath(''), ext_modules=ext_modules)
        exit(0)

    # Ok
    description = """The itools library offers a collection of packages covering a wide
     range of capabilities.  Including support for many file formats (XML,
     CSV, HTML, etc.), a virtual file system (itools.fs), the simple
     template language (STL), an index and search engine, and much more."""
    classifiers = [
      'Development Status :: 4 - Beta',
      'Intended Audience :: Developers',
      'License :: OSI Approved :: GNU General Public License (GPL)',
      'Programming Language :: Python',
      'Topic :: Internet',
      'Topic :: Internet :: WWW/HTTP',
      'Topic :: Software Development',
예제 #29
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from domains import register_domain, get_domain, MSG
from mo import MOFile
from po import POFile, POUnit, encode_source

__all__ = [
    'encode_source',
    'register_domain',
    'get_domain',
    'MSG',
    'MOFile',
    'POFile',
    'POUnit',
]

add_type('text/x-gettext-translation', '.po')
add_type('text/x-gettext-translation-template', '.pot')
add_type('application/x-gettext-translation', '.mo')
add_type('application/x-gettext-translation', '.gmo')

# Register the itools domain
path = get_abspath('../locale')
register_domain('itools', path)
예제 #30
0
파일: widgets.py 프로젝트: staverne/ikaaro
 def ea_language(self):
     path = get_abspath('ui/editarea/langs')
     languages = [x[:-3] for x in lfs.get_names(path)]
     return get_context().accept_language.select_language(languages)
예제 #31
0
파일: skin.py 프로젝트: nicolasderam/shop
                return sidebar
            return site_root.get_resource('category-sidebar')
        return NeutralSkin.get_sidebar_resource(self, context)

    # Lazy (dynamic property)
    def get_lazy_current_category(self, context):
        here = context.resource
        shop = get_shop(here)
        here = context.resource
        if isinstance(here, shop.category_class):
            return here.get_title()
        elif isinstance(here, shop.product_class):
            return here.parent.get_title()
        return None


###########################################################################
# Register
###########################################################################
path = get_abspath('ui/shop/')
register_skin('shop', ShopSkin(path))

path = get_abspath('ui/backoffice/')
register_skin('backoffice', BackofficeSkin(path))

path = get_abspath('ui/modules/')
register_skin('modules', Skin(path))

path = get_abspath('ui/default_skin/')
register_skin('default_skin', ShopSkin(path))
예제 #32
0
# -*- coding: UTF-8 -*-
# Copyright (C) 2006-2008 Juan David Ibáñez Palomar <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from itools.xml import register_dtd
from xliff import XLFFile, XLFUnit, XLFNote, File

__all__ = ['XLFFile', 'XLFUnit', 'XLFNote', 'File']

# Register mime type
add_type('application/x-xliff', '.xlf')

# Register DTD
# -//XLIFF//DTD XLIFF//EN
register_dtd(get_abspath('xliff.dtd'), urn='urn:publicid:-:XLIFF:DTD+XLIFF:EN')
예제 #33
0
파일: widgets.py 프로젝트: staverne/ikaaro
 def rte_language(self):
     path = get_abspath('ui/tiny_mce/langs')
     languages = [x[:-3] for x in lfs.get_names(path)]
     return get_context().accept_language.select_language(languages)
예제 #34
0
from webpage import WebPage


# Check for required software
for name, import_path, reason in [
        ("poppler", "itools.pdf.pdftotext", "PDF indexation"),
        ("wv2", "itools.office.doctotext", "DOC indexation"),
        ("xlrd", "xlrd", "XLS indexation")]:
    try:
        __import__(import_path)
    except ImportError:
        print '%s: You need to install "%s" and reinstall itools.' % (reason,
                name)


# The version
__version__ = get_version()


# Import required modules
import users

# Register the itools domain
path = get_abspath('locale')
register_domain('ikaaro', path)

# Register document types
register_document_type(WebPage)
register_document_type(Folder)
register_document_type(File)
예제 #35
0
파일: schema.py 프로젝트: Ramel/itools
    ]

    contexts = [
        (meta_uri, 'keyword', 'metadata'),
        (meta_uri, 'user-defined', 'metadata'),
        (text_uri, 'index-entry-span', 'text index'),
        (text_uri, 'h', 'heading'),
        (text_uri, 'p', 'paragraph'),
    ]


###########################################################################
# Make the namespaces
###########################################################################
# Read the Relax NG schema
rng_file = get_abspath('OpenDocument-v1.2-cd05-schema.rng')
rng_file = ODFRelaxNGFile(rng_file)
rng_file.auto_register()

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
namespace_fo = get_namespace(fo_uri)
register_namespace(namespace_fo(uri=fo_uri_2))

svg_uri_2 = 'http://www.w3.org/2000/svg'
namespace_svg = get_namespace(svg_uri)
register_namespace(namespace_svg(uri=svg_uri_2))

# Specific to OpenOffice
officeooo = XMLNamespace(uri='http://openoffice.org/2009/office',
                         prefix='officeooo',
예제 #36
0
    (style_uri, 'list-level-label-alignment'),
]


###########################################################################
# Make the namespaces
###########################################################################
def duplicate_ns(namespaces, first_uri, second_uri):
    ns = copy(namespaces[first_uri])
    ns.uri = second_uri
    ns.prefix = None
    namespaces[second_uri] = ns


# Read the Relax NG schema
rng_file = get_abspath('OpenDocument-strict-schema-v1.1.rng')
rng_file = ro_database.get_handler(rng_file, RelaxNGFile)
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name in unknown_elements:
    elements = namespaces[uri].elements
    if element_name in elements:
        raise ValueError, 'element "%s" is defined twice' % element_name
    elements[element_name] = ElementSchema(element_name,
예제 #37
0
 def ea_language(self):
     path = get_abspath('ui/ikaaro/editarea/langs')
     languages = [ x[:-3] for x in lfs.get_names(path) ]
     return get_context().accept_language.select_language(languages)
예제 #38
0
파일: skin.py 프로젝트: hforge/shop
            return site_root.get_resource('category-sidebar')
        return NeutralSkin.get_sidebar_resource(self, context)


    # Lazy (dynamic property)
    def get_lazy_current_category(self, context):
        here = context.resource
        shop = get_shop(here)
        here = context.resource
        if isinstance(here, shop.category_class):
            return here.get_title()
        elif isinstance(here, shop.product_class):
            return here.parent.get_title()
        return None


###########################################################################
# Register
###########################################################################
path = get_abspath('ui/shop/')
register_skin('shop', ShopSkin(path))

path = get_abspath('ui/backoffice/')
register_skin('backoffice', BackofficeSkin(path))

path = get_abspath('ui/modules/')
register_skin('modules', Skin(path))

path = get_abspath('ui/default_skin/')
register_skin('default_skin', ShopSkin(path))
예제 #39
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from domains import register_domain, get_domain, MSG, get_language_msg
from mo import MOFile
from po import POFile, POUnit, encode_source


__all__ = [
    'encode_source',
    'register_domain',
    'get_domain',
    'MSG',
    'MOFile',
    'POFile',
    'POUnit',
    # Utility functions
    'get_language_msg',
    ]


add_type('text/x-gettext-translation', '.po')
add_type('text/x-gettext-translation-template', '.pot')
add_type('application/x-gettext-translation', '.mo')
add_type('application/x-gettext-translation', '.gmo')

# Register the itools domain
path = get_abspath('../locale')
register_domain('itools', path)
예제 #40
0
 def get_template(self):
     path = get_abspath('google_analytics_graph.stl')
     return ro_database.get_handler(path, XMLFile)
예제 #41
0
파일: __init__.py 프로젝트: staverne/ikaaro
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Juan David Ibáñez Palomar <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import get_abspath

# Import from ikaaro
from ikaaro.registry import register_document_type
from ikaaro.skins import register_skin
from blog import Post

# Register skin
path = get_abspath('ui')
register_skin('blog', path)

# Add blogs to websites
register_document_type(Post)
예제 #42
0
from ikaaro.skins import register_skin

# Import from ikaaro.agenda
from agenda import ConfigAgenda
from agenda_views import DailyView, MonthlyView, WeeklyView
from event import Event, EventModel, Event_Edit, Event_NewInstance
from event import Event_Render
from calendars import Calendar, Calendars_Enumerate, Calendars_View
from emails import Event_Reminder_Email

__all__ = [
    'Calendar',
    'Calendars_Enumerate',
    'Calendars_View',
    'Event',
    'EventModel',
    'DailyView',
    'MonthlyView',
    'WeeklyView',
    # Emails
    'Event_Reminder_Email'
]

# Register
register_document_type(Event)
register_skin('agenda', get_abspath('ui'))
Configuration.register_module(ConfigAgenda)

# Silent pyflakes
Event_Render, Event_Edit, Event_NewInstance
예제 #43
0
 def get_template(self, resource, context):
     path = get_abspath('google_analytics.stl')
     return ro_database.get_handler(path, XMLFile)
예제 #44
0
파일: __init__.py 프로젝트: TZM/zmgc
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import get_abspath

# Import from ikaaro
from ikaaro.skins import register_skin

# Import from tzm
from tzm.skins import ProjectSkin

# Import from here
from project import Projects, Project

# Silent pyflakes
Projects, Project

# Register skin
path = get_abspath("ui")
register_skin("project", ProjectSkin(path))
예제 #45
0
from ikaaro.skins import register_skin

# Import from goodforms
from utils import is_print


class Skin(BaseSkin):

    is_backoffice_skin = False

    def get_template(self, context):
        if is_print(get_context()):
            return self.get_resource('/ui/goodforms/print.xhtml')
        return super(Skin, self).get_template(context)

    def get_styles(self, context):
        #styles = super(Skin, self).get_styles(context)
        styles = []
        styles.append('/ui/goodforms/dist/style.css')
        styles.append('/ui/goodforms/fancybox/jquery.fancybox-1.3.1.css')
        return styles

    def get_scripts(self, context):
        scripts = super(Skin, self).get_scripts(context)
        scripts.append('/ui/goodforms/zeroclipboard/ZeroClipboard.js')
        scripts.append('/ui/goodforms/fancybox/jquery.fancybox-1.3.1.pack.js')
        return scripts


register_skin('goodforms', Skin(get_abspath('ui/goodforms')))
예제 #46
0
import docutils

# Import from itools
from itools.core import get_abspath, get_version
from itools.gettext import register_domain

# Import from ikaaro
from ikaaro.skins import register_skin

# Import from wiki
from folder import WikiFolder


# The version
__version__ = get_version()

# Register skin
register_skin('wiki', get_abspath('ui'))

# Register the wiki domain
register_domain('wiki', get_abspath('locale'))

# Updates
if argv[0].endswith('icms-update.py'):
    import obsolete
    obsolete

# Silent pyflakes
docutils
WikiFolder
예제 #47
0
파일: root.py 프로젝트: nicolasderam/ikaaro
# Import from ikaaro
from config import Configuration
from config_register import RegisterForm, TermsOfService_View
from context import CMSContext
from fields import Char_Field
from folder import Folder
from resource_views import LoginView
from skins import skin_registry
from root_views import PoweredBy, ContactForm
from root_views import NotFoundView, ForbiddenView, NotAllowedView
from root_views import UploadStatsView, UpdateDocs, UnavailableView
from update import UpdateInstanceView


# itools source and target languages
config = get_abspath('setup.conf')
config = ro_database.get_handler(config,  ConfigFile)
itools_source_language = config.get_value('source_language')
itools_target_languages = config.get_value('target_languages')


# Force email to send UTF-8 mails in plain text
add_charset('utf-8', QP, None, 'utf-8')
add_codec('utf-8', 'utf_8')



class CtrlView(BaseView):

    access = True
예제 #48
0
파일: about.py 프로젝트: hforge/itws


class AboutITWS(Folder):
    """
    Default about-iws webpage
    """

    class_id = 'about-itws'
    class_title = MSG(u'About ITWS')
    class_views = ['view', 'edit', 'browse_content']


    def get_catalog_values(self):
        return merge_dicts(Folder.get_catalog_values(self),
                           workflow_state='public')


    def get_document_types(self):
        return []


    # Views
    view = AboutITWS_View()
    browse_content = Folder_BrowseContent(access='is_admin')



# Register
register_skin('about', Skin(get_abspath('ui/about')))
예제 #49
0
파일: __init__.py 프로젝트: kennym/itools
# -*- coding: UTF-8 -*-
# Copyright (C) 2005-2007 Juan David Ibáñez Palomar <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import add_type, get_abspath
from tmx import TMXFile, Sentence, TMXUnit, TMXNote
from itools.xml import register_dtd


__all__ = ['TMXFile', 'Sentence', 'TMXUnit', 'TMXNote']


add_type('application/x-tmx', '.tmx')

# Register DTD
register_dtd(get_abspath('tmx14.dtd'),
             uri='http://www.lisa.org/tmx/tmx14.dtd')
예제 #50
0
파일: odf.py 프로젝트: mmather02/itools
    def greek(self):
        """Anonymize the ODF file.
        """
        # Verify PIL is installed
        if PILImage is None:
            err = 'The greeking feature requires the Python Imaging Library'
            raise ImportError, err

        folder = lfs.open(get_abspath('.'))
        err = 'Unexpected "%s" file will be omitted from the greeked document'

        modified_files = {}
        for filename in self.get_contents():
            extension = splitext(filename)[1]
            startswith = filename.startswith
            # Files to keep as they are
            # TODO the manifest.xml file should be properly updated
            keep = ['mimetype', 'settings.xml', 'META-INF/manifest.xml']
            if filename in keep:
                pass

            # Content, metadata and style
            elif filename in ['content.xml', 'meta.xml', 'styles.xml']:
                events = self.get_events(filename)
                translation = translate(events, GreekCatalog)
                modified_files[filename] = stream_to_str(translation)

            # Thumbnails
            elif startswith('Thumbnails'):
                if extension == '.pdf':
                    modified_files[filename] = folder.open('thumb.pdf').read()
                elif extension == '.png':
                    modified_files[filename] = folder.open('thumb.png').read()
                else:
                    # Unexpected (TODO use the logging system)
                    modified_files[filename] = None
                    print err % filename

            # SVM files (usually they are in the Pictures folder)
            elif extension == '.svm':
                modified_files[filename] = folder.open('square.svm').read()

            # Pictures
            elif startswith('Pictures') or startswith('media'):
                # Try with PIL
                file = self.get_file(filename)
                file = StringIO(file)
                image = PILImage.open(file)
                format = image.format
                image = image.convert('RGB')
                image.filename = filename
                draw = PILImageDraw.Draw(image)

                # Make a cross
                h, l = image.size
                draw.rectangle((0, 0, h - 1, l - 1),
                               fill="grey",
                               outline="black")
                draw.line((0, 0, h - 1, l - 1), fill="black")
                draw.line((0, l - 1, h - 1, 0), fill="black")

                # Save
                data = StringIO()
                image.save(data, format)
                modified_files[filename] = data.getvalue()

            # Unexpected (TODO use the logging system)
            else:
                modified_files[filename] = None
                print err % filename

        return zip_data(self.data, modified_files)
예제 #51
0
파일: twitter.py 프로젝트: hforge/shop
 def get_template(self, resource, context):
     path = get_abspath('twitter.stl')
     return ro_database.get_handler(path, XMLFile)
예제 #52
0
import root
import text
from webpage import WebPage

# Check for required software
for name, import_path, reason in [
    ("poppler", "itools.pdf.pdftotext", "PDF indexation"),
    ("wv2", "itools.office.doctotext", "DOC indexation"),
    ("xlrd", "xlrd", "XLS indexation")
]:
    try:
        __import__(import_path)
    except ImportError:
        print '%s: You need to install "%s" and reinstall itools.' % (reason,
                                                                      name)

# The version
__version__ = get_version()

# Import required modules
import users

# Register the itools domain
path = get_abspath('locale')
register_domain('ikaaro', path)

# Register document types
register_document_type(WebPage)
register_document_type(Folder)
register_document_type(File)
예제 #53
0
파일: schema.py 프로젝트: kennym/itools
unknown_elements = [
    (style_uri, 'default-page-layout'),
    (style_uri, 'list-level-label-alignment'),
    ]

###########################################################################
# Make the namespaces
###########################################################################
def duplicate_ns(namespaces, first_uri, second_uri):
    ns = copy(namespaces[first_uri])
    ns.uri = second_uri
    ns.prefix = None
    namespaces[second_uri] = ns

# Read the Relax NG schema
rng_file = get_abspath('OpenDocument-strict-schema-v1.1.rng')
rng_file = ro_database.get_handler(rng_file, RelaxNGFile)
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name in unknown_elements:
    elements = namespaces[uri].elements
    if element_name in elements:
        raise ValueError, 'element "%s" is defined twice' % element_name
    elements[element_name] = ElementSchema(element_name,
예제 #54
0
파일: setup.py 프로젝트: hforge/wiki
# -*- coding: UTF-8 -*-
# Copyright (C) 2007-2009 J. David Ibanez <*****@*****.**>
# Copyright (C) 2010 Hervé Cauwelier <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import get_abspath
from itools.pkg import setup


if __name__ == '__main__':
    path = get_abspath('./')
    setup(path)
예제 #55
0
# Import from ikaaro
from config import Configuration
from config_register import RegisterForm, TermsOfService_View
from context import CMSContext
from fields import Char_Field
from folder import Folder
from resource_views import LoginView
from skins import skin_registry
from utils import get_base_path_query
from root_views import PoweredBy, ContactForm
from root_views import NotFoundView, ForbiddenView, NotAllowedView
from root_views import UploadStatsView, UpdateDocs, UnavailableView
from update import UpdateInstanceView

# itools source and target languages
config = get_abspath('setup.conf')
config = ConfigFile(config)
itools_source_language = config.get_value('source_language')
itools_target_languages = config.get_value('target_languages')

# Force email to send UTF-8 mails in plain text
add_charset('utf-8', QP, None, 'utf-8')
add_codec('utf-8', 'utf_8')


class CtrlView(BaseView):

    access = True

    def GET(self, resource, context):
        context.content_type = 'text/plain'
예제 #56
0
파일: test.py 프로젝트: hforge/itools
test_modules = [test_core, test_csv, test_database, test_datatypes, test_dispatcher,
    test_gettext, test_handlers, test_html, test_i18n, test_ical, test_odf,
    test_rss, test_srx, test_stl, test_tmx, test_uri, test_fs,
    test_validators, test_web, test_workflow, test_xliff, test_xml, test_xmlfile]


loader = TestLoader()

if __name__ == '__main__':
    usage = '%prog [OPTIONS]'
    description = 'Run ikaaro tests'
    parser = OptionParser(usage, description=description)
    parser.add_option('-m', '--mode', default='standard', help='tests mode')
    options, args = parser.parse_args()
    suite = TestSuite()
    for module in test_modules:
        suite.addTest(loader.loadTestsFromModule(module))
    if options.mode == 'standard':
        ret = TextTestRunner(verbosity=1).run(suite)
    elif options.mode == 'junitxml':
        path = get_abspath('./junit.xml')
        print('Result is here: %s' % path)
        f = file(path, 'wb')
        result = JUnitXmlResult(f)
        result.startTestRun()
        ret = suite.run(result)
        result.stopTestRun()
    exit_code = not ret.wasSuccessful()
    exit(exit_code)
예제 #57
0
# Copyright (C) 2010 Juan David Ibáñez Palomar <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.core import get_abspath

# Import from ikaaro
from ikaaro.registry import register_document_type
from ikaaro.skins import register_skin
from blog import Post


# Register skin
path = get_abspath('ui')
register_skin('blog', path)

# Add blogs to websites
register_document_type(Post)
예제 #58
0
    # (3) Remove enclosing format
    while center:
        if (center[0][0] == START_FORMAT and center[-1][0] == END_FORMAT and
            center[0][1][1] == center[-1][1][1]):
            left.append(center.pop(0))
            right.insert(0, center.pop())
        else:
            break

    # (4) Remove the spaces
    left, center, right = _remove_spaces(left, center, right, keep_spaces)

    return left, center, right


default_srx_handler = get_abspath('srx/default.srx', 'itools')
default_srx_handler = ro_database.get_handler(default_srx_handler, SRXFile)
def _split_message(message, srx_handler=None):
    # Concatenation!
    concat_text = []
    for type, value, line in message:
        if type == TEXT:
            concat_text.append(value[0])
    concat_text = u''.join(concat_text)

    # Get the rules
    if srx_handler is None:
        srx_handler = default_srx_handler
    # XXX we must handle the language here!
    rules = srx_handler.get_compiled_rules('en')