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