1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """cubicweb on appengine plugins for cubicweb-ctl |
|
19 |
|
20 """ |
|
21 __docformat__ = "restructuredtext en" |
|
22 |
|
23 from os.path import exists, join, split, basename, normpath, abspath |
|
24 from logilab.common.clcommands import register_commands |
|
25 |
|
26 from cubicweb import CW_SOFTWARE_ROOT, BadCommandUsage |
|
27 from cubicweb.toolsutils import (Command, copy_skeleton, create_symlink, |
|
28 create_dir) |
|
29 from cubicweb.cwconfig import CubicWebConfiguration |
|
30 |
|
31 |
|
32 def slink_directories(): |
|
33 import rql, yams, yapps, docutils, roman |
|
34 try: |
|
35 import json as simplejson |
|
36 except ImportError: |
|
37 import simplejson |
|
38 from logilab import common as lgc |
|
39 from logilab import constraint as lgcstr |
|
40 from logilab import mtconverter as lgmtc |
|
41 dirs = [ |
|
42 (lgc.__path__[0], 'logilab/common'), |
|
43 (lgmtc.__path__[0], 'logilab/mtconverter'), |
|
44 (lgcstr.__path__[0], 'logilab/constraint'), |
|
45 (rql.__path__[0], 'rql'), |
|
46 (simplejson.__path__[0], 'simplejson'), |
|
47 (yams.__path__[0], 'yams'), |
|
48 (yapps.__path__[0], 'yapps'), |
|
49 (docutils.__path__[0], 'docutils'), |
|
50 (roman.__file__.replace('.pyc', '.py'), 'roman.py'), |
|
51 |
|
52 ('/usr/share/fckeditor/', 'fckeditor'), |
|
53 |
|
54 (join(CW_SOFTWARE_ROOT, 'web', 'data'), join('cubes', 'shared', 'data')), |
|
55 (join(CW_SOFTWARE_ROOT, 'web', 'wdoc'), join('cubes', 'shared', 'wdoc')), |
|
56 (join(CW_SOFTWARE_ROOT, 'i18n'), join('cubes', 'shared', 'i18n')), |
|
57 (join(CW_SOFTWARE_ROOT, 'goa', 'tools'), 'tools'), |
|
58 (join(CW_SOFTWARE_ROOT, 'goa', 'bin'), 'bin'), |
|
59 ] |
|
60 |
|
61 try: |
|
62 import dateutil |
|
63 import vobject |
|
64 dirs.extend([ (dateutil.__path__[0], 'dateutil'), |
|
65 (vobject.__path__[0], 'vobject') ] ) |
|
66 except ImportError: |
|
67 pass |
|
68 return dirs |
|
69 |
|
70 COPY_CW_FILES = ( |
|
71 '__init__.py', |
|
72 '__pkginfo__.py', |
|
73 '_exceptions.py', |
|
74 'appobject.py', |
|
75 'dbapi.py', |
|
76 'cwvreg.py', |
|
77 'cwconfig.py', |
|
78 'entity.py', |
|
79 'interfaces.py', |
|
80 'i18n.py', |
|
81 'mail.py', |
|
82 'migration.py', |
|
83 'mixins.py', |
|
84 'mttransforms.py', |
|
85 'rqlrewrite.py', |
|
86 'rset.py', |
|
87 'schema.py', |
|
88 'schemaviewer.py', |
|
89 'selectors.py', |
|
90 'uilib.py', |
|
91 'utils.py', |
|
92 'vregistry.py', |
|
93 'view.py', |
|
94 |
|
95 'ext/html4zope.py', |
|
96 'ext/rest.py', |
|
97 |
|
98 'server/hookhelper.py', |
|
99 'server/hooksmanager.py', |
|
100 'server/hooks.py', |
|
101 'server/migractions.py', |
|
102 'server/pool.py', |
|
103 'server/querier.py', |
|
104 'server/repository.py', |
|
105 'server/securityhooks.py', |
|
106 'server/session.py', |
|
107 'server/serverconfig.py', |
|
108 'server/ssplanner.py', |
|
109 'server/utils.py', |
|
110 'server/sources/__init__.py', |
|
111 |
|
112 'entities/__init__.py', |
|
113 'entities/authobjs.py', |
|
114 'entities/lib.py', |
|
115 'entities/schemaobjs.py', |
|
116 'entities/wfobjs.py', |
|
117 |
|
118 'sobjects/__init__.py', |
|
119 'sobjects/notification.py', |
|
120 |
|
121 # XXX would be necessary for goa.testlib but require more stuff to be added |
|
122 # such as server.serverconfig and so on (check devtools.__init__) |
|
123 # 'devtools/__init__.py', |
|
124 # 'devtools/fake.py', |
|
125 |
|
126 'web/__init__.py', |
|
127 'web/_exceptions.py', |
|
128 'web/action.py', |
|
129 'web/application.py', |
|
130 'web/box.py', |
|
131 'web/component.py', |
|
132 'web/controller.py', |
|
133 'web/form.py', |
|
134 'web/htmlwidgets.py', |
|
135 'web/httpcache.py', |
|
136 'web/request.py', |
|
137 'web/webconfig.py', |
|
138 |
|
139 'web/views/__init__.py', |
|
140 'web/views/actions.py', |
|
141 'web/views/basecomponents.py', |
|
142 'web/views/basecontrollers.py', |
|
143 'web/views/baseforms.py', |
|
144 'web/views/basetemplates.py', |
|
145 'web/views/baseviews.py', |
|
146 'web/views/boxes.py', |
|
147 'web/views/calendar.py', |
|
148 'web/views/error.py', |
|
149 'web/views/editcontroller.py', |
|
150 'web/views/ibreadcrumbs.py', |
|
151 'web/views/idownloadable.py', |
|
152 'web/views/magicsearch.py', |
|
153 'web/views/management.py', |
|
154 'web/views/navigation.py', |
|
155 'web/views/startup.py', |
|
156 'web/views/vcard.py', |
|
157 'web/views/wdoc.py', |
|
158 'web/views/urlpublishing.py', |
|
159 'web/views/urlrewrite.py', |
|
160 'web/views/xbel.py', |
|
161 |
|
162 'wsgi/__init__.py', |
|
163 'wsgi/handler.py', |
|
164 'wsgi/request.py', |
|
165 |
|
166 'goa/__init__.py', |
|
167 'goa/db.py', |
|
168 'goa/dbinit.py', |
|
169 'goa/dbmyams.py', |
|
170 'goa/goaconfig.py', |
|
171 'goa/goavreg.py', |
|
172 'goa/gaesource.py', |
|
173 'goa/rqlinterpreter.py', |
|
174 'goa/appobjects/__init__.py', |
|
175 'goa/appobjects/components.py', |
|
176 'goa/appobjects/dbmgmt.py', |
|
177 'goa/appobjects/gauthservice.py', |
|
178 'goa/appobjects/sessions.py', |
|
179 |
|
180 'schemas/bootstrap.py', |
|
181 'schemas/base.py', |
|
182 ) |
|
183 |
|
184 OVERRIDEN_FILES = ( |
|
185 ('toolsutils.py', 'toolsutils.py'), |
|
186 ('mttransforms.py', 'mttransforms.py'), |
|
187 ('server__init__.py', 'server/__init__.py'), |
|
188 ('rqlannotation.py', 'server/rqlannotation.py'), |
|
189 ) |
|
190 |
|
191 |
|
192 def create_init_file(pkgdir, pkgname): |
|
193 open(join(pkgdir, '__init__.py'), 'w').write('"""%s pkg"""' % pkgname) |
|
194 |
|
195 |
|
196 class NewGoogleAppCommand(Command): |
|
197 """Create a new google appengine instance. |
|
198 |
|
199 <instance directory> |
|
200 the path to the appengine instance directory |
|
201 """ |
|
202 name = 'newgapp' |
|
203 arguments = '<instance directory>' |
|
204 |
|
205 def run(self, args): |
|
206 if len(args) != 1: |
|
207 raise BadCommandUsage("exactly one argument is expected") |
|
208 appldir, = args |
|
209 appldir = normpath(abspath(appldir)) |
|
210 appid = basename(appldir) |
|
211 context = {'appname': appid} |
|
212 # goa instance'skeleton |
|
213 copy_skeleton(join(CW_SOFTWARE_ROOT, 'goa', 'skel'), |
|
214 appldir, context, askconfirm=True) |
|
215 # cubicweb core dependencies |
|
216 for directory, subdirectory in slink_directories(): |
|
217 subdirectory = join(appldir, subdirectory) |
|
218 if not exists(split(subdirectory)[0]): |
|
219 create_dir(split(subdirectory)[0]) |
|
220 create_symlink(directory, join(appldir, subdirectory)) |
|
221 create_init_file(join(appldir, 'logilab'), 'logilab') |
|
222 # copy supported part of cubicweb |
|
223 create_dir(join(appldir, 'cubicweb')) |
|
224 for fpath in COPY_CW_FILES: |
|
225 target = join(appldir, 'cubicweb', fpath) |
|
226 if not exists(split(target)[0]): |
|
227 create_dir(split(target)[0]) |
|
228 create_symlink(join(CW_SOFTWARE_ROOT, fpath), target) |
|
229 # overriden files |
|
230 for fpath, subfpath in OVERRIDEN_FILES: |
|
231 create_symlink(join(CW_SOFTWARE_ROOT, 'goa', 'overrides', fpath), |
|
232 join(appldir, 'cubicweb', subfpath)) |
|
233 # link every supported components |
|
234 packagesdir = join(appldir, 'cubes') |
|
235 create_init_file(join(appldir, 'cubes'), 'cubes') |
|
236 for include in ('addressbook','basket', 'blog','folder', |
|
237 'tag', 'comment', 'file', 'link', |
|
238 'mailinglist', 'person', 'task', 'zone', |
|
239 ): |
|
240 create_symlink(CubicWebConfiguration.cube_dir(include), |
|
241 join(packagesdir, include)) |
|
242 # generate sample config |
|
243 from cubicweb.goa.goaconfig import GAEConfiguration |
|
244 from cubicweb.migration import MigrationHelper |
|
245 config = GAEConfiguration(appid, appldir) |
|
246 if exists(config.main_config_file()): |
|
247 mih = MigrationHelper(config) |
|
248 mih.rewrite_configuration() |
|
249 else: |
|
250 config.save() |
|
251 |
|
252 |
|
253 register_commands((NewGoogleAppCommand, |
|
254 )) |
|