cwctl.py
branchstable
changeset 3700 fd550e4dc515
parent 3638 648d6dbec630
child 3707 78596919ede3
equal deleted inserted replaced
3699:20ba545e00e1 3700:fd550e4dc515
   683             StartInstanceCommand().start_instance(appid)
   683             StartInstanceCommand().start_instance(appid)
   684         print
   684         print
   685 
   685 
   686 
   686 
   687 class ShellCommand(Command):
   687 class ShellCommand(Command):
   688     """Run an interactive migration shell. This is a python shell with
   688     """Run an interactive migration shell on an instance. This is a python shell
   689     enhanced migration commands predefined in the namespace. An additional
   689     with enhanced migration commands predefined in the namespace. An additional
   690     argument may be given corresponding to a file containing commands to
   690     argument may be given corresponding to a file containing commands to execute
   691     execute in batch mode.
   691     in batch mode.
       
   692 
       
   693     By default it will connect to a local instance using an in memory
       
   694     connection, unless -P option is specified, in which case you will be
       
   695     connected through pyro. In the later case, you won't have access to
       
   696     repository internals (session, etc...) so most migration commands won't be
       
   697     available.
   692 
   698 
   693     <instance>
   699     <instance>
   694       the identifier of the instance to connect.
   700       the identifier of the instance to connect.
   695     """
   701     """
   696     name = 'shell'
   702     name = 'shell'
   697     arguments = '<instance> [batch command file]'
   703     arguments = '<instance> [batch command file]'
   698     options = (
   704     options = (
   699         ('system-only',
   705         ('system-only',
   700          {'short': 'S', 'action' : 'store_true',
   706          {'short': 'S', 'action' : 'store_true',
   701           'default': False,
       
   702           'help': 'only connect to the system source when the instance is '
   707           'help': 'only connect to the system source when the instance is '
   703           'using multiple sources. You can\'t use this option and the '
   708           'using multiple sources. You can\'t use this option and the '
   704           '--ext-sources option at the same time.'}),
   709           '--ext-sources option at the same time.',
       
   710           'group': 'local'
       
   711          }),
   705 
   712 
   706         ('ext-sources',
   713         ('ext-sources',
   707          {'short': 'E', 'type' : 'csv', 'metavar': '<sources>',
   714          {'short': 'E', 'type' : 'csv', 'metavar': '<sources>',
   708           'default': None,
       
   709           'help': "For multisources instances, specify to which sources the \
   715           'help': "For multisources instances, specify to which sources the \
   710 repository should connect to for upgrading. When unspecified or 'all' given, \
   716 repository should connect to for upgrading. When unspecified or 'all' given, \
   711 will connect to all defined sources. If 'migration' is given, appropriate \
   717 will connect to all defined sources. If 'migration' is given, appropriate \
   712 sources for migration will be automatically selected.",
   718 sources for migration will be automatically selected.",
       
   719           'group': 'local'
   713           }),
   720           }),
   714 
   721 
   715         ('force',
   722         ('force',
   716          {'short': 'f', 'action' : 'store_true',
   723          {'short': 'f', 'action' : 'store_true',
   717           'default' : False,
   724           'help': 'don\'t check instance is up to date.',
   718           'help': 'don\'t check instance is up to date.'}
   725           'group': 'local'
   719          ),
   726           }),
       
   727 
       
   728         ('pyro',
       
   729          {'short': 'P', 'action' : 'store_true',
       
   730           'help': 'connect to a running instance through Pyro.',
       
   731           'group': 'remote',
       
   732           }),
       
   733         ('pyro-ns-host',
       
   734          {'short': 'H', 'type' : 'string', 'metavar': '<host[:port]>',
       
   735           'help': 'Pyro name server host. If not set, will be detected by '
       
   736           'using a broadcast query.',
       
   737           'group': 'remote'
       
   738           }),
   720         )
   739         )
   721 
   740 
   722     def run(self, args):
   741     def run(self, args):
   723         appid = pop_arg(args, 99, msg="No instance specified !")
   742         appid = pop_arg(args, 99, msg="No instance specified !")
   724         config = cwcfg.config_for(appid)
   743         if self.config.pyro:
   725         if self.config.ext_sources:
   744             from cubicweb.dbapi import connect
   726             assert not self.config.system_only
   745             from cubicweb.server.utils import manager_userpasswd
   727             sources = self.config.ext_sources
   746             from cubicweb.server.migractions import ServerMigrationHelper
   728         elif self.config.system_only:
   747             login, pwd = manager_userpasswd(msg=None)
   729             sources = ('system',)
   748             cnx = connect(appid, login=login, password=pwd,
       
   749                           host=self.config.pyro_ns_host, mulcnx=False)
       
   750             repo = cnx._repo
       
   751             mih = ServerMigrationHelper(None, repo=repo, cnx=cnx,
       
   752                                          # hack so it don't try to load fs schema
       
   753                                         schema=1)
   730         else:
   754         else:
   731             sources = ('all',)
   755             config = cwcfg.config_for(appid)
   732         config.set_sources_mode(sources)
   756             if self.config.ext_sources:
   733         config.repairing = self.config.force
   757                 assert not self.config.system_only
   734         mih = config.migration_handler()
   758                 sources = self.config.ext_sources
       
   759             elif self.config.system_only:
       
   760                 sources = ('system',)
       
   761             else:
       
   762                 sources = ('all',)
       
   763             config.set_sources_mode(sources)
       
   764             config.repairing = self.config.force
       
   765             mih = config.migration_handler()
   735         if args:
   766         if args:
   736             for arg in args:
   767             for arg in args:
   737                 mih.process_script(arg)
   768                 mih.process_script(arg)
   738         else:
   769         else:
   739             mih.interactive_shell()
   770             mih.interactive_shell()
   740         mih.shutdown()
   771         if not self.config.pyro:
       
   772             mih.shutdown()
   741 
   773 
   742 
   774 
   743 class RecompileInstanceCatalogsCommand(InstanceCommand):
   775 class RecompileInstanceCatalogsCommand(InstanceCommand):
   744     """Recompile i18n catalogs for instances.
   776     """Recompile i18n catalogs for instances.
   745 
   777