cwctl.py
branchstable
changeset 4064 3b12e4192983
parent 3715 e3ccadb126d7
child 4181 c79135c217df
child 4524 2eb36514ad6d
equal deleted inserted replaced
4062:d16b2927afe6 4064:3b12e4192983
    10     from os import kill, getpgid
    10     from os import kill, getpgid
    11 except ImportError:
    11 except ImportError:
    12     def kill(*args): pass
    12     def kill(*args): pass
    13     def getpgid(): pass
    13     def getpgid(): pass
    14 
    14 
    15 from os.path import exists, join, isfile, isdir
    15 from os.path import exists, join, isfile, isdir, dirname, abspath
    16 
    16 
    17 from logilab.common.clcommands import register_commands, pop_arg
    17 from logilab.common.clcommands import register_commands, pop_arg
    18 from logilab.common.shellutils import ASK
    18 from logilab.common.shellutils import ASK
    19 
    19 
    20 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, underline_title
    20 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, underline_title
   305         # configuration'specific stuff
   305         # configuration'specific stuff
   306         print
   306         print
   307         helper.bootstrap(cubes, self.config.config_level)
   307         helper.bootstrap(cubes, self.config.config_level)
   308         # write down configuration
   308         # write down configuration
   309         config.save()
   309         config.save()
       
   310         self._handle_win32(config, appid)
   310         print '-> generated %s' % config.main_config_file()
   311         print '-> generated %s' % config.main_config_file()
   311         # handle i18n files structure
   312         # handle i18n files structure
   312         # in the first cube given
   313         # in the first cube given
   313         print '-> preparing i18n catalogs'
   314         print '-> preparing i18n catalogs'
   314         from cubicweb.common import i18n
   315         from cubicweb.common import i18n
   329             # this directory should be owned by the uid of the server process
   330             # this directory should be owned by the uid of the server process
   330             print 'set %s as owner of the data directory' % config['uid']
   331             print 'set %s as owner of the data directory' % config['uid']
   331             chown(config.appdatahome, config['uid'])
   332             chown(config.appdatahome, config['uid'])
   332         print '\n-> creation done for %r.\n' % config.apphome
   333         print '\n-> creation done for %r.\n' % config.apphome
   333         helper.postcreate()
   334         helper.postcreate()
       
   335 
       
   336     def _handle_win32(self, config, appid):
       
   337         if sys.platform != 'win32':
       
   338             return
       
   339         service_template = """
       
   340 import sys
       
   341 import win32serviceutil
       
   342 sys.path.insert(0, r"%(CWPATH)s")
       
   343 
       
   344 from cubicweb.etwist.service import CWService
       
   345 
       
   346 classdict = {'_svc_name_': 'cubicweb-%(APPID)s',
       
   347              '_svc_display_name_': 'CubicWeb ' + '%(CNAME)s',
       
   348              'instance': '%(APPID)s'}
       
   349 %(CNAME)sService = type('%(CNAME)sService', (CWService,), classdict)
       
   350 
       
   351 if __name__ == '__main__':
       
   352     win32serviceutil.HandleCommandLine(%(CNAME)sService)
       
   353 """
       
   354         open(join(config.apphome, 'win32svc.py'), 'wb').write(
       
   355             service_template % {'APPID': appid,
       
   356                                 'CNAME': appid.capitalize(),
       
   357                                 'CWPATH': abspath(join(dirname(__file__), '..'))})
   334 
   358 
   335 
   359 
   336 class DeleteInstanceCommand(Command):
   360 class DeleteInstanceCommand(Command):
   337     """Delete an instance. Will remove instance's files and
   361     """Delete an instance. Will remove instance's files and
   338     unregister it.
   362     unregister it.