-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistry.py
103 lines (85 loc) · 3.46 KB
/
registry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Sylvain Taverne <[email protected]>
#
# 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 standard library
from os import listdir
from os.path import isdir, exists, join as join_paths
# Import from itools
from itools.core import get_abspath
from itools.gettext import MSG, register_domain
from itools.handlers import ro_database
# Import from ikaaro
from ikaaro.forms import SelectWidget, MultilineWidget, TextWidget, DateWidget
from ikaaro.skins import register_skin
# Import from itws
from forms import ProductSelectorWidget
from utils import ITWSHOPConfig
####################################
## Register shop / skin
## XXX Hardcoded !!
####################################
shops = []
shop_skins = []
def get_shops():
return shops
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})
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)
####################################
## Register widgets
####################################
shop_widgets = [('select', MSG(u'Select Widget'), SelectWidget),
('multiline-widget', MSG(u'Multiline Widget'), MultilineWidget),
('product-widget', MSG(u'Product Widget'), ProductSelectorWidget),
('date-widget', MSG(u'Date Widget'), DateWidget),
('text-widget', MSG(u'Text Widget'), TextWidget)]
def register_widget(name, title, widget):
shop_widgets.append((name, title, widget))
####################################
## Register datatypes
####################################
shop_datatypes = []
def register_datatype(name, title, datatype):
shop_datatypes.append((name, title, datatype))