##// END OF EJS Templates
shell: remove module level imports
super-admin -
r5364:f90791c0 default
parent child Browse files
Show More
@@ -1,80 +1,85 b''
1 1
2 2
3 3 # Copyright (C) 2013-2023 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 interactive shell paster command for RhodeCode
23 23 """
24 24
25 25 import os
26 26 import sys
27 27 import logging
28 28
29 29 from rhodecode.lib.paster_commands import BasePasterCommand
30 30
31 31 # fix rhodecode import
32 32 from os.path import dirname as dn
33 33 rc_path = dn(dn(dn(os.path.realpath(__file__))))
34 34 sys.path.append(rc_path)
35 35
36 36 log = logging.getLogger(__name__)
37 37
38 38 welcome_banner = """Welcome to RhodeCode iShell.
39 39 Type `exit` to exit the shell.
40 40 iShell is interactive shell to interact directly with the
41 41 internal RhodeCode APIs. You can rescue your lost password,
42 42 or reset some user/system settings.
43 43 """
44 44
45 45
46 46 class Command(BasePasterCommand):
47 47
48 48 max_args = 1
49 49 min_args = 1
50 50
51 51 usage = "CONFIG_FILE"
52 52 group_name = "RhodeCode"
53 53 takes_config_file = -1
54 54 parser = BasePasterCommand.standard_parser(verbose=True)
55 55 summary = "Interactive shell"
56 56
57 def import_all_from_module(self, module_name):
58 import importlib
59 module = importlib.import_module(module_name)
60 globals().update({k: v for k, v in module.__dict__.items() if not k.startswith('_')})
61
57 62 def command(self):
58 63 #get SqlAlchemy session
59 64 self._init_session()
60 65
61 66 # imports, used in ipython shell
62 67 import os
63 68 import sys
64 69 import time
65 70 import shutil
66 71 import datetime
67 from rhodecode.model.db import *
72 self.import_all_from_module('rhodecode.model.db')
68 73
69 74 try:
70 75 from IPython import embed
71 76 from traitlets.config import Config
72 77 cfg = Config()
73 78 cfg.InteractiveShellEmbed.confirm_exit = False
74 79 embed(config=cfg, banner1=welcome_banner)
75 80 except ImportError:
76 81 print('ipython installation required for ishell')
77 82 sys.exit(-1)
78 83
79 84 def update_parser(self):
80 85 pass
@@ -1,67 +1,73 b''
1 1
2 2
3 3 # Copyright (C) 2016-2023 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 interactive shell for pyramid
23 23 """
24 24
25 25 import os
26 26 import sys
27 27 import logging
28 28
29 29 # fix rhodecode import
30 30 from os.path import dirname as dn
31 31 rc_path = dn(dn(dn(os.path.realpath(__file__))))
32 32 sys.path.append(rc_path)
33 33
34 34 log = logging.getLogger(__name__)
35 35
36 36 welcome_banner = """Welcome to RhodeCode iShell.\n
37 37 Type `exit` to exit the shell.
38 38 iShell is interactive shell to interact directly with the
39 39 internal RhodeCode APIs. You can rescue your lost password,
40 40 or reset some user/system settings.
41 41 """
42 42
43 43
44 def import_all_from_module(module_name):
45 import importlib
46 module = importlib.import_module(module_name)
47 globals().update({k: v for k, v in module.__dict__.items() if not k.startswith('_')})
48
49
44 50 def ipython_shell_runner(env, help):
45 51
46 52 # imports, used in ipython shell
47 53 import os
48 54 import sys
49 55 import time
50 56 import shutil
51 57 import datetime
52 58 from rhodecode.model import user, user_group, repo, repo_group
53 from rhodecode.model.db import *
59 import_all_from_module('rhodecode.model.db')
54 60
55 61 try:
56 62 import IPython
57 63 from traitlets.config import Config
58 64
59 65 cfg = Config()
60 66 cfg.InteractiveShellEmbed.confirm_exit = False
61 67 cfg.TerminalInteractiveShell.banner2 = \
62 68 welcome_banner + '\n' + help + '\n'
63 69 IPython.start_ipython(argv=[], user_ns=env, config=cfg)
64 70
65 71 except ImportError:
66 72 print('ipython installation required for ishell')
67 73 sys.exit(-1)
General Comments 0
You need to be logged in to leave comments. Login now