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