goa/goactl.py
changeset 0 b97547f5f1fa
child 3 512e9bd0685a
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     1 """cubicweb on appengine plugins for cubicweb-ctl
       
     2 
       
     3 :organization: Logilab
       
     4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     6 """
       
     7 __docformat__ = "restructuredtext en"
       
     8 
       
     9 from os.path import exists, join, split, dirname, basename, normpath, abspath
       
    10 
       
    11 from cubicweb import BadCommandUsage
       
    12 from cubicweb import CW_SOFTWARE_ROOT
       
    13 from cubicweb.toolsutils import (Command, register_commands, copy_skeleton,
       
    14                               create_dir, create_symlink, create_copy)
       
    15 from cubicweb.cwconfig import CubicWebConfiguration
       
    16 
       
    17 from logilab import common as lgc
       
    18 from logilab.common.textutils import get_csv
       
    19 from logilab import constraint as lgcstr
       
    20 from logilab import mtconverter as lgmtc
       
    21 import rql, yams, yapps, simplejson, dateutil, vobject, docutils, roman
       
    22 
       
    23 SLINK_DIRECTORIES = (
       
    24     (lgc.__path__[0], 'logilab/common'),
       
    25     (lgmtc.__path__[0], 'logilab/mtconverter'),
       
    26     (lgcstr.__path__[0], 'logilab/constraint'),
       
    27     (rql.__path__[0], 'rql'),
       
    28     (simplejson.__path__[0], 'simplejson'),
       
    29     (yams.__path__[0], 'yams'),
       
    30     (yapps.__path__[0], 'yapps'),
       
    31     (dateutil.__path__[0], 'dateutil'),
       
    32     (vobject.__path__[0], 'vobject'),
       
    33     (docutils.__path__[0], 'docutils'),
       
    34     (roman.__file__.replace('.pyc', '.py'), 'roman.py'),
       
    35 
       
    36     (join(CW_SOFTWARE_ROOT, 'embedded', 'mx'), 'mx'),
       
    37     ('/usr/share/fckeditor/', 'fckeditor'),
       
    38 
       
    39     (join(CW_SOFTWARE_ROOT, 'web', 'data'), join('cubes', 'shared', 'data')), 
       
    40     (join(CW_SOFTWARE_ROOT, 'web', 'wdoc'), join('cubes', 'shared', 'wdoc')),
       
    41     (join(CW_SOFTWARE_ROOT, 'i18n'), join('cubes', 'shared', 'i18n')),
       
    42     (join(CW_SOFTWARE_ROOT, 'goa', 'tools'), 'tools'),
       
    43     (join(CW_SOFTWARE_ROOT, 'goa', 'bin'), 'bin'),
       
    44     )
       
    45 
       
    46 COPY_CW_FILES = (
       
    47     '__init__.py',
       
    48     '__pkginfo__.py',
       
    49     '_exceptions.py',
       
    50     'dbapi.py',
       
    51     'cwvreg.py',
       
    52     'cwconfig.py',
       
    53     'interfaces.py',
       
    54     'rset.py',
       
    55     'schema.py',
       
    56     'schemaviewer.py',
       
    57     'vregistry.py',
       
    58     
       
    59     'common/appobject.py',
       
    60     'common/entity.py',
       
    61     'common/html4zope.py',
       
    62     'common/mail.py',
       
    63     'common/migration.py',
       
    64     'common/mixins.py',
       
    65     'common/mttransforms.py',
       
    66     'common/registerers.py',
       
    67     'common/rest.py',
       
    68     'common/selectors.py',
       
    69     'common/view.py',
       
    70     'common/uilib.py',
       
    71     'common/utils.py',
       
    72 
       
    73     'server/hookhelper.py',
       
    74     'server/hooksmanager.py',
       
    75     'server/hooks.py',
       
    76     'server/migractions.py',
       
    77     'server/pool.py',
       
    78     'server/querier.py',
       
    79     'server/repository.py',
       
    80     'server/rqlrewrite.py',
       
    81     'server/securityhooks.py',
       
    82     'server/session.py',
       
    83     'server/serverconfig.py',
       
    84     'server/ssplanner.py',
       
    85     'server/utils.py',
       
    86     'server/sources/__init__.py',
       
    87 
       
    88     'entities/__init__.py',
       
    89     'entities/authobjs.py',
       
    90     'entities/lib.py',
       
    91     'entities/schemaobjs.py',
       
    92 
       
    93     'sobjects/__init__.py',
       
    94     'sobjects/notification.py',
       
    95     
       
    96 # XXX would be necessary for goa.testlib but require more stuff to be added
       
    97 #     such as server.serverconfig and so on (check devtools.__init__)
       
    98 #    'devtools/__init__.py',
       
    99 #    'devtools/fake.py',
       
   100     
       
   101     'web/__init__.py',
       
   102     'web/_exceptions.py',
       
   103     'web/action.py',
       
   104     'web/application.py',
       
   105     'web/box.py',
       
   106     'web/component.py',
       
   107     'web/controller.py',
       
   108     'web/form.py',
       
   109     'web/htmlwidgets.py',
       
   110     'web/httpcache.py',
       
   111     'web/request.py',
       
   112     'web/webconfig.py',
       
   113     'web/widgets.py',
       
   114 
       
   115     'web/views/__init__.py',
       
   116     'web/views/actions.py',
       
   117     'web/views/basecomponents.py',
       
   118     'web/views/basecontrollers.py',
       
   119     'web/views/baseforms.py',
       
   120     'web/views/basetemplates.py',
       
   121     'web/views/baseviews.py',
       
   122     'web/views/boxes.py',
       
   123     'web/views/calendar.py',
       
   124     'web/views/error.py',
       
   125     'web/views/editcontroller.py',
       
   126     'web/views/ibreadcrumbs.py',
       
   127     'web/views/idownloadable.py',
       
   128     'web/views/magicsearch.py',
       
   129     'web/views/management.py',
       
   130     'web/views/navigation.py',
       
   131     'web/views/startup.py',
       
   132     'web/views/wdoc.py',
       
   133     'web/views/urlpublishing.py',
       
   134     'web/views/urlrewrite.py',
       
   135     'web/views/xbel.py',
       
   136 
       
   137     'wsgi/__init__.py',
       
   138     'wsgi/handler.py',
       
   139     'wsgi/request.py',
       
   140     
       
   141     'goa/__init__.py',
       
   142     'goa/db.py',
       
   143     'goa/dbinit.py',
       
   144     'goa/dbmyams.py',
       
   145     'goa/goaconfig.py',
       
   146     'goa/goavreg.py',
       
   147     'goa/gaesource.py',
       
   148     'goa/rqlinterpreter.py',
       
   149     'goa/appobjects/__init__.py',
       
   150     'goa/appobjects/components.py', 
       
   151     'goa/appobjects/dbmgmt.py', 
       
   152     'goa/appobjects/gauthservice.py', 
       
   153     'goa/appobjects/sessions.py',
       
   154 
       
   155     'schemas/bootstrap.py',
       
   156     'schemas/base.py',
       
   157     )
       
   158 
       
   159 OVERRIDEN_FILES = (
       
   160     ('toolsutils.py', 'toolsutils.py'),
       
   161     ('mttransforms.py', 'common/mttransforms.py'),
       
   162     ('server__init__.py', 'server/__init__.py'),
       
   163     ('rqlannotation.py', 'server/rqlannotation.py'),
       
   164     )
       
   165 
       
   166 
       
   167 def create_init_file(pkgdir, pkgname):
       
   168     open(join(pkgdir, '__init__.py'), 'w').write('"""%s pkg"""' % pkgname)
       
   169 
       
   170 
       
   171 class NewGoogleAppCommand(Command):
       
   172     """Create a new google appengine application.
       
   173 
       
   174     <application directory>
       
   175       the path to the appengine application directory
       
   176     """
       
   177     name = 'newgapp'
       
   178     arguments = '<application directory>'
       
   179     
       
   180     def run(self, args):
       
   181         if len(args) != 1:
       
   182             raise BadCommandUsage("exactly one argument is expected")
       
   183         appldir, = args
       
   184         appldir = normpath(abspath(appldir))
       
   185         appid = basename(appldir)
       
   186         context = {'appname': appid}
       
   187         # goa application'skeleton
       
   188         copy_skeleton(join(CW_SOFTWARE_ROOT, 'goa', 'skel'),
       
   189                       appldir, context, askconfirm=True)
       
   190         # cubicweb core dependancies
       
   191         for directory, subdirectory in SLINK_DIRECTORIES:
       
   192             subdirectory = join(appldir, subdirectory)
       
   193             if not exists(split(subdirectory)[0]):
       
   194                 create_dir(split(subdirectory)[0])
       
   195             create_symlink(directory, join(appldir, subdirectory))
       
   196         create_init_file(join(appldir, 'logilab'), 'logilab')
       
   197         # copy supported part of cubicweb 
       
   198         create_dir(join(appldir, 'cubicweb'))
       
   199         for fpath in COPY_CW_FILES:
       
   200             target = join(appldir, 'cubicweb', fpath)
       
   201             if not exists(split(target)[0]):
       
   202                 create_dir(split(target)[0])
       
   203             create_symlink(join(CW_SOFTWARE_ROOT, fpath), target)
       
   204         # overriden files
       
   205         create_init_file(join(appldir, 'cubicweb/common'), 'cubicweb.common')
       
   206         for fpath, subfpath in OVERRIDEN_FILES:
       
   207             create_symlink(join(CW_SOFTWARE_ROOT, 'goa', 'overrides', fpath),
       
   208                            join(appldir, 'cubicweb', subfpath))
       
   209         # link every supported components
       
   210         cubesdir = join(appldir, 'cubes')
       
   211         cubesdir = CubicWebConfiguration.cubes_dir()
       
   212         for include in ('eaddressbook','ebasket', 'eblog','eclassfolders',
       
   213                         'eclasstags', 'ecomment', 'efile', 'elink',
       
   214                         'emailinglist', 'eperson', 'etask', 'ezone',
       
   215                         ):
       
   216             create_symlink(join(cubesdir, include), join(cubesdir, include))
       
   217         # generate sample config
       
   218         from cubicweb.goa.goaconfig import GAEConfiguration
       
   219         from cubicweb.common.migration import MigrationHelper
       
   220         config = GAEConfiguration(appid, appldir)
       
   221         if exists(config.main_config_file()):
       
   222             mih = MigrationHelper(config)
       
   223             mih.rewrite_configuration()
       
   224         else:
       
   225             config.save()
       
   226 
       
   227 
       
   228 register_commands((NewGoogleAppCommand,
       
   229                    ))