1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
35 def getpgid(): |
35 def getpgid(): |
36 """win32 getpgid implementation""" |
36 """win32 getpgid implementation""" |
37 |
37 |
38 |
38 |
39 from os.path import exists, join, isfile, isdir, dirname, abspath |
39 from os.path import exists, join, isfile, isdir, dirname, abspath |
|
40 |
|
41 from urlparse import urlparse |
40 |
42 |
41 from logilab.common.clcommands import CommandLine |
43 from logilab.common.clcommands import CommandLine |
42 from logilab.common.shellutils import ASK |
44 from logilab.common.shellutils import ASK |
43 |
45 |
44 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
46 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
865 {'short': 'f', 'action' : 'store_true', |
867 {'short': 'f', 'action' : 'store_true', |
866 'help': 'don\'t check instance is up to date.', |
868 'help': 'don\'t check instance is up to date.', |
867 'group': 'local' |
869 'group': 'local' |
868 }), |
870 }), |
869 |
871 |
870 ('pyro', |
872 ('repo-uri', |
871 {'short': 'P', 'action' : 'store_true', |
873 {'short': 'H', 'type' : 'string', 'metavar': '<protocol>://<[host][:port]>', |
872 'help': 'connect to a running instance through Pyro.', |
874 'help': 'URI of the CubicWeb repository to connect to. URI can be \ |
873 'group': 'remote', |
875 pyro://[host:port] the Pyro name server host; if the pyro nameserver is not set, \ |
874 }), |
876 it will be detected by using a broadcast query, a ZMQ URL or \ |
875 ('pyro-ns-host', |
877 inmemory:// (default) use an in-memory repository.', |
876 {'short': 'H', 'type' : 'string', 'metavar': '<host[:port]>', |
|
877 'help': 'Pyro name server host. If not set, will be detected by ' |
|
878 'using a broadcast query.', |
|
879 'group': 'remote' |
878 'group': 'remote' |
880 }), |
879 }), |
881 ) |
880 ) |
882 |
881 |
883 def run(self, args): |
882 def run(self, args): |
884 appid = args.pop(0) |
883 appid = args.pop(0) |
885 if self.config.pyro: |
884 if self.config.repo_uri: |
|
885 uri = urlparse(self.config.repo_uri) |
|
886 if uri.scheme == 'pyro': |
|
887 cnxtype = uri.scheme |
|
888 hostport = uri.netloc |
|
889 elif uri.scheme == 'inmemory': |
|
890 cnxtype = '' |
|
891 hostport = '' |
|
892 else: |
|
893 cnxtype = 'zmq' |
|
894 hostport = self.config.repo_uri |
|
895 else: |
|
896 cnxtype = '' |
|
897 |
|
898 if cnxtype: |
886 from cubicweb import AuthenticationError |
899 from cubicweb import AuthenticationError |
887 from cubicweb.dbapi import connect |
900 from cubicweb.dbapi import connect, ConnectionProperties |
888 from cubicweb.server.utils import manager_userpasswd |
901 from cubicweb.server.utils import manager_userpasswd |
889 from cubicweb.server.migractions import ServerMigrationHelper |
902 from cubicweb.server.migractions import ServerMigrationHelper |
|
903 cnxprops = ConnectionProperties(cnxtype=cnxtype) |
|
904 |
890 while True: |
905 while True: |
891 try: |
906 try: |
892 login, pwd = manager_userpasswd(msg=None) |
907 login, pwd = manager_userpasswd(msg=None) |
893 cnx = connect(appid, login=login, password=pwd, |
908 cnx = connect(appid, login=login, password=pwd, |
894 host=self.config.pyro_ns_host, mulcnx=False) |
909 host=hostport, mulcnx=False, |
|
910 cnxprops=cnxprops) |
895 except AuthenticationError, ex: |
911 except AuthenticationError, ex: |
896 print ex |
912 print ex |
897 except (KeyboardInterrupt, EOFError): |
913 except (KeyboardInterrupt, EOFError): |
898 print |
914 print |
899 sys.exit(0) |
915 sys.exit(0) |