xmipp3-installer 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xmipp3_installer/__init__.py +1 -0
- xmipp3_installer/__main__.py +6 -0
- xmipp3_installer/api_client/api_client.py +50 -0
- xmipp3_installer/api_client/assembler/installation_info_assembler.py +181 -0
- xmipp3_installer/application/__init__.py +1 -0
- xmipp3_installer/application/cli/__init__.py +1 -0
- xmipp3_installer/application/cli/arguments/__init__.py +8 -0
- xmipp3_installer/application/cli/arguments/modes.py +130 -0
- xmipp3_installer/application/cli/arguments/params.py +76 -0
- xmipp3_installer/application/cli/cli.py +271 -0
- xmipp3_installer/application/cli/parsers/base_help_formatter.py +244 -0
- xmipp3_installer/application/cli/parsers/error_handler_parser.py +68 -0
- xmipp3_installer/application/cli/parsers/format.py +35 -0
- xmipp3_installer/application/cli/parsers/general_help_formatter.py +92 -0
- xmipp3_installer/application/cli/parsers/mode_help_formatter.py +115 -0
- xmipp3_installer/application/logger/__init__.py +0 -0
- xmipp3_installer/application/logger/errors.py +28 -0
- xmipp3_installer/application/logger/logger.py +230 -0
- xmipp3_installer/application/logger/predefined_messages.py +66 -0
- xmipp3_installer/application/user_interactions.py +16 -0
- xmipp3_installer/installer/__init__.py +1 -0
- xmipp3_installer/installer/constants/__init__.py +17 -0
- xmipp3_installer/installer/constants/paths.py +32 -0
- xmipp3_installer/installer/handlers/__init__.py +1 -0
- xmipp3_installer/installer/handlers/cmake/__init__.py +1 -0
- xmipp3_installer/installer/handlers/cmake/cmake_constants.py +27 -0
- xmipp3_installer/installer/handlers/cmake/cmake_handler.py +69 -0
- xmipp3_installer/installer/handlers/conda_handler.py +13 -0
- xmipp3_installer/installer/handlers/generic_package_handler.py +18 -0
- xmipp3_installer/installer/handlers/git_handler.py +185 -0
- xmipp3_installer/installer/handlers/shell_handler.py +114 -0
- xmipp3_installer/installer/handlers/versions_manager.py +98 -0
- xmipp3_installer/installer/installer_service.py +66 -0
- xmipp3_installer/installer/modes/__init__.py +1 -0
- xmipp3_installer/installer/modes/mode_all_executor.py +63 -0
- xmipp3_installer/installer/modes/mode_clean/__init__.py +1 -0
- xmipp3_installer/installer/modes/mode_clean/mode_clean_all_executor.py +44 -0
- xmipp3_installer/installer/modes/mode_clean/mode_clean_bin_executor.py +94 -0
- xmipp3_installer/installer/modes/mode_clean/mode_clean_executor.py +45 -0
- xmipp3_installer/installer/modes/mode_cmake/__init__.py +1 -0
- xmipp3_installer/installer/modes/mode_cmake/mode_cmake_executor.py +55 -0
- xmipp3_installer/installer/modes/mode_cmake/mode_compile_and_install_executor.py +49 -0
- xmipp3_installer/installer/modes/mode_cmake/mode_config_build_executor.py +64 -0
- xmipp3_installer/installer/modes/mode_config_executor.py +46 -0
- xmipp3_installer/installer/modes/mode_executor.py +43 -0
- xmipp3_installer/installer/modes/mode_get_sources_executor.py +132 -0
- xmipp3_installer/installer/modes/mode_git_executor.py +41 -0
- xmipp3_installer/installer/modes/mode_selector.py +25 -0
- xmipp3_installer/installer/modes/mode_sync/mode_add_model_executor.py +104 -0
- xmipp3_installer/installer/modes/mode_sync/mode_get_models_executor.py +51 -0
- xmipp3_installer/installer/modes/mode_sync/mode_sync_executor.py +48 -0
- xmipp3_installer/installer/modes/mode_sync/mode_test_executor.py +91 -0
- xmipp3_installer/installer/modes/mode_version_executor.py +164 -0
- xmipp3_installer/installer/orquestrator.py +37 -0
- xmipp3_installer/installer/urls.py +8 -0
- xmipp3_installer/repository/__init__.py +1 -0
- xmipp3_installer/repository/config.py +241 -0
- xmipp3_installer/repository/config_vars/__init__.py +0 -0
- xmipp3_installer/repository/config_vars/config_values_adapter.py +107 -0
- xmipp3_installer/repository/config_vars/default_values.py +36 -0
- xmipp3_installer/repository/config_vars/variables.py +48 -0
- xmipp3_installer/repository/invalid_config_line.py +15 -0
- xmipp3_installer/shared/file_operations.py +18 -0
- xmipp3_installer/shared/singleton.py +25 -0
- xmipp3_installer-1.0.0.dist-info/LICENSE +674 -0
- xmipp3_installer-1.0.0.dist-info/METADATA +729 -0
- xmipp3_installer-1.0.0.dist-info/RECORD +70 -0
- xmipp3_installer-1.0.0.dist-info/WHEEL +5 -0
- xmipp3_installer-1.0.0.dist-info/entry_points.txt +2 -0
- xmipp3_installer-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""### Help formatter specific for generic usage mode."""
|
|
2
|
+
|
|
3
|
+
from xmipp3_installer.application.cli.arguments import modes
|
|
4
|
+
from xmipp3_installer.application.cli.parsers import format
|
|
5
|
+
from xmipp3_installer.application.cli.parsers.base_help_formatter import BaseHelpFormatter
|
|
6
|
+
from xmipp3_installer.application.logger.logger import logger
|
|
7
|
+
|
|
8
|
+
class GeneralHelpFormatter(BaseHelpFormatter):
|
|
9
|
+
"""
|
|
10
|
+
### Overrides the default help formatter to display a custom help message.
|
|
11
|
+
"""
|
|
12
|
+
def format_help(self):
|
|
13
|
+
"""
|
|
14
|
+
### Prints the help message of the argument parser.
|
|
15
|
+
"""
|
|
16
|
+
help_message = "Run Xmipp's installer script\n\nUsage: xmipp [options]\n"
|
|
17
|
+
for section in list(modes.MODES.keys()):
|
|
18
|
+
help_message += self.__get_section_message(section)
|
|
19
|
+
help_message += f"\n{self.__get_epilog()}"
|
|
20
|
+
help_message += self.__get_note()
|
|
21
|
+
return format.get_formatting_tabs(help_message)
|
|
22
|
+
|
|
23
|
+
def __get_mode_args_str(self, mode: str) -> str:
|
|
24
|
+
"""
|
|
25
|
+
### This method returns the args text for a given mode.
|
|
26
|
+
|
|
27
|
+
### Params:
|
|
28
|
+
- mode (str): Mode to get args text for.
|
|
29
|
+
|
|
30
|
+
### Returns:
|
|
31
|
+
- (str): Args text for given mode.
|
|
32
|
+
"""
|
|
33
|
+
arg_list = modes.MODE_ARGS[mode]
|
|
34
|
+
param_names = []
|
|
35
|
+
for param in arg_list:
|
|
36
|
+
param_name = self._get_param_first_name(param)
|
|
37
|
+
if param_name:
|
|
38
|
+
param_names.append(f'[{param_name}]')
|
|
39
|
+
return ' '.join(param_names)
|
|
40
|
+
|
|
41
|
+
def __get_mode_args_and_help_str(self, previous_text: str, mode: str) -> str:
|
|
42
|
+
"""
|
|
43
|
+
### This method returns the args and help text for a given mode.
|
|
44
|
+
|
|
45
|
+
### Params:
|
|
46
|
+
- previous_text (str): Text inserted before the one to be returned.
|
|
47
|
+
- mode (str): Mode to get help text for.
|
|
48
|
+
|
|
49
|
+
### Returns:
|
|
50
|
+
- (str): Args and help text for given mode.
|
|
51
|
+
"""
|
|
52
|
+
return self._text_with_limits(
|
|
53
|
+
previous_text + self.__get_mode_args_str(mode),
|
|
54
|
+
self._get_mode_help(mode)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def __get_epilog(self) -> str:
|
|
58
|
+
"""
|
|
59
|
+
### Returns the epilogue.
|
|
60
|
+
|
|
61
|
+
#### Returns:
|
|
62
|
+
- (str): Epilogue.
|
|
63
|
+
"""
|
|
64
|
+
epilogue = "Example 1: ./xmipp\n"
|
|
65
|
+
epilogue += "Example 2: ./xmipp compileAndInstall -j 4\n"
|
|
66
|
+
return epilogue
|
|
67
|
+
|
|
68
|
+
def __get_note(self) -> str:
|
|
69
|
+
"""
|
|
70
|
+
### Returns the additional note message.
|
|
71
|
+
|
|
72
|
+
#### Returns:
|
|
73
|
+
- (str): Note message.
|
|
74
|
+
"""
|
|
75
|
+
note_message = "Note: You can also view a specific help message for each mode with \"./xmipp [mode] -h\".\n"
|
|
76
|
+
note_message += f"Example: ./xmipp {modes.MODE_ALL} -h\n"
|
|
77
|
+
return logger.yellow(note_message)
|
|
78
|
+
|
|
79
|
+
def __get_section_message(self, section: str) -> str:
|
|
80
|
+
"""
|
|
81
|
+
### Returns the given section's message.
|
|
82
|
+
|
|
83
|
+
#### Params:
|
|
84
|
+
- section (str): Section name.
|
|
85
|
+
|
|
86
|
+
#### Return:
|
|
87
|
+
- (str): Section's message.
|
|
88
|
+
"""
|
|
89
|
+
section_message = self._get_help_separator() + f"\t# {section} #\n\n"
|
|
90
|
+
for mode in list(modes.MODES[section].keys()):
|
|
91
|
+
section_message += self.__get_mode_args_and_help_str(f"\t{mode} ", mode)
|
|
92
|
+
return section_message
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""### Help formatter specific for non-generic usage modes."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from xmipp3_installer.application.cli import arguments
|
|
6
|
+
from xmipp3_installer.application.cli.arguments import modes, params
|
|
7
|
+
from xmipp3_installer.application.cli.parsers import format
|
|
8
|
+
from xmipp3_installer.application.cli.parsers.base_help_formatter import BaseHelpFormatter
|
|
9
|
+
from xmipp3_installer.application.logger.logger import logger
|
|
10
|
+
|
|
11
|
+
class ModeHelpFormatter(BaseHelpFormatter):
|
|
12
|
+
"""
|
|
13
|
+
### Overrides the default help formatter to display a custom help message deppending on the mode selected.
|
|
14
|
+
"""
|
|
15
|
+
def format_help(self):
|
|
16
|
+
"""
|
|
17
|
+
### This method prints the help message of the argument parser.
|
|
18
|
+
"""
|
|
19
|
+
mode = self.__get_mode()
|
|
20
|
+
help_message = f"{self._get_mode_help(mode, general=False)}\n\n"
|
|
21
|
+
help_message += self.__get_args_message(mode)
|
|
22
|
+
help_message += self.__get_examples_message(mode)
|
|
23
|
+
return format.get_formatting_tabs(help_message)
|
|
24
|
+
|
|
25
|
+
def __get_mode(self):
|
|
26
|
+
"""
|
|
27
|
+
### Returns the execution mode.
|
|
28
|
+
|
|
29
|
+
#### Returns:
|
|
30
|
+
- (str): Execution mode.
|
|
31
|
+
"""
|
|
32
|
+
# Retrieved from the parent help message
|
|
33
|
+
# Message received is the format_help output of the main parser's
|
|
34
|
+
# formatter, adding the mode at the end
|
|
35
|
+
return self._prog.split(' ')[-1]
|
|
36
|
+
|
|
37
|
+
def __get_args_message(self, mode: str) -> str:
|
|
38
|
+
"""
|
|
39
|
+
### Returns the help section containing all the parameters.
|
|
40
|
+
|
|
41
|
+
#### Params:
|
|
42
|
+
- mode (str): Usage mode selected.
|
|
43
|
+
|
|
44
|
+
#### Returns:
|
|
45
|
+
- (str): Help section containing all parameters.
|
|
46
|
+
"""
|
|
47
|
+
args = modes.MODE_ARGS[mode]
|
|
48
|
+
help_message = ''
|
|
49
|
+
options_str = ''
|
|
50
|
+
separator = ''
|
|
51
|
+
|
|
52
|
+
if len(args) > 0:
|
|
53
|
+
arg_names = [self._get_param_first_name(arg_name) for arg_name in args]
|
|
54
|
+
if self.__args_contain_optional(arg_names):
|
|
55
|
+
help_message += logger.yellow("Note: only params starting with '-' are optional. The rest are required.\n")
|
|
56
|
+
options_str = ' [options]'
|
|
57
|
+
separator = self._get_help_separator() + '\t# Options #\n\n'
|
|
58
|
+
|
|
59
|
+
help_message += f'Usage: {arguments.XMIPP_PROGRAM_NAME} {mode}{options_str}\n{separator}'
|
|
60
|
+
help_message += self.__get_args_info(args)
|
|
61
|
+
return help_message
|
|
62
|
+
|
|
63
|
+
def __args_contain_optional(self, arg_names: List[str]) -> bool:
|
|
64
|
+
"""
|
|
65
|
+
### Returns True if the param name list contains at least one optional param.
|
|
66
|
+
|
|
67
|
+
### Params:
|
|
68
|
+
- arg_names (list[str]): List containing the param names.
|
|
69
|
+
|
|
70
|
+
### Returns:
|
|
71
|
+
- (bool): True if there is at least one optional param. False otherwise.
|
|
72
|
+
"""
|
|
73
|
+
for name in arg_names:
|
|
74
|
+
if name.startswith('-'):
|
|
75
|
+
return True
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
def __get_args_info(self, args: List[str]) -> str:
|
|
79
|
+
"""
|
|
80
|
+
### Returns the info of each param.
|
|
81
|
+
|
|
82
|
+
#### Params:
|
|
83
|
+
- args (list[str]): List of parameters.
|
|
84
|
+
|
|
85
|
+
#### Returns:
|
|
86
|
+
- (str): Info of all parameters.
|
|
87
|
+
"""
|
|
88
|
+
help_message = ''
|
|
89
|
+
for arg in args:
|
|
90
|
+
help_message += self._text_with_limits(
|
|
91
|
+
'\t' + ', '.join(format.get_param_names(arg)),
|
|
92
|
+
params.PARAMS[arg][params.DESCRIPTION]
|
|
93
|
+
)
|
|
94
|
+
return help_message
|
|
95
|
+
|
|
96
|
+
def __get_examples_message(self, mode: str) -> str:
|
|
97
|
+
"""
|
|
98
|
+
### Returns the message section containig usage examples.
|
|
99
|
+
|
|
100
|
+
#### Params:
|
|
101
|
+
- mode (str): Usage mode selected.
|
|
102
|
+
|
|
103
|
+
#### Returns:
|
|
104
|
+
- (str): Message section containing usage examples.
|
|
105
|
+
"""
|
|
106
|
+
help_message = ''
|
|
107
|
+
examples = modes.MODE_EXAMPLES[mode]
|
|
108
|
+
for i in range(len(examples)):
|
|
109
|
+
number_str = '' if len(examples) == 1 else f' {i+1}'
|
|
110
|
+
help_message += f"\nExample{number_str}: {examples[i]}"
|
|
111
|
+
|
|
112
|
+
if len(examples) > 0:
|
|
113
|
+
help_message += '\n'
|
|
114
|
+
|
|
115
|
+
return help_message
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""### Contains all constants needed for handling errors during Xmipp's installation."""
|
|
2
|
+
|
|
3
|
+
from xmipp3_installer.installer.urls import CMAKE_INSTALL_DOCS_URL
|
|
4
|
+
from xmipp3_installer.installer.constants import paths
|
|
5
|
+
|
|
6
|
+
# Error codes
|
|
7
|
+
INTERRUPTED_ERROR = -1
|
|
8
|
+
OK = 0
|
|
9
|
+
UNKOW_ERROR = 1
|
|
10
|
+
SOURCE_CLONE_ERROR = 2
|
|
11
|
+
CMAKE_ERROR = 3
|
|
12
|
+
CMAKE_CONFIGURE_ERROR = 4
|
|
13
|
+
CMAKE_COMPILE_ERROR = 5
|
|
14
|
+
CMAKE_INSTALL_ERROR = 6
|
|
15
|
+
IO_ERROR = 7
|
|
16
|
+
|
|
17
|
+
# Error messages
|
|
18
|
+
__CHECK_LOG_MESSAGE = f'Check the inside file \'{paths.LOG_FILE}\'.'
|
|
19
|
+
ERROR_CODES = {
|
|
20
|
+
INTERRUPTED_ERROR: ['Process was interrupted by the user.', ''],
|
|
21
|
+
UNKOW_ERROR: ['', ''],
|
|
22
|
+
SOURCE_CLONE_ERROR: ['Error cloning xmipp repository with git.', 'Please review the internet connection and the git package.'],
|
|
23
|
+
CMAKE_ERROR: ['There was an error with CMake.', f'Please install it by following the instructions at {CMAKE_INSTALL_DOCS_URL}'],
|
|
24
|
+
CMAKE_CONFIGURE_ERROR: ['Error configuring with CMake.', __CHECK_LOG_MESSAGE],
|
|
25
|
+
CMAKE_COMPILE_ERROR: ['Error compiling with CMake.', __CHECK_LOG_MESSAGE],
|
|
26
|
+
CMAKE_INSTALL_ERROR: ['Error installing with CMake.', __CHECK_LOG_MESSAGE],
|
|
27
|
+
IO_ERROR: ['Input/output error.', 'This error can be caused by the installer not being able to read/write/create/delete a file. Check your permissions on this directory.']
|
|
28
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""### Provides a global logger."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import shutil
|
|
5
|
+
from io import BufferedReader
|
|
6
|
+
|
|
7
|
+
from xmipp3_installer.shared.singleton import Singleton
|
|
8
|
+
from xmipp3_installer.application.logger import errors
|
|
9
|
+
from xmipp3_installer.installer import urls
|
|
10
|
+
|
|
11
|
+
class Logger(Singleton):
|
|
12
|
+
"""
|
|
13
|
+
### Logger class for keeping track of installation messages.
|
|
14
|
+
"""
|
|
15
|
+
__UP = "\x1B[1A\r"
|
|
16
|
+
__REMOVE_LINE = '\033[K'
|
|
17
|
+
__BOLD = "\033[1m"
|
|
18
|
+
__BLUE = "\033[34m"
|
|
19
|
+
__RED = "\033[91m"
|
|
20
|
+
__GREEN = "\033[92m"
|
|
21
|
+
__YELLOW = "\033[93m"
|
|
22
|
+
__END_FORMAT = "\033[0m"
|
|
23
|
+
__FORMATTING_CHARACTERS = [__UP, __REMOVE_LINE, __BOLD, __BLUE, __RED, __GREEN, __YELLOW, __END_FORMAT]
|
|
24
|
+
|
|
25
|
+
def __init__(self):
|
|
26
|
+
"""
|
|
27
|
+
### Constructor.
|
|
28
|
+
|
|
29
|
+
#### Params:
|
|
30
|
+
- ouputToConsoloe (bool): Print messages to console.
|
|
31
|
+
"""
|
|
32
|
+
self.__log_file = None
|
|
33
|
+
self.__len_last_printed_elem = 0
|
|
34
|
+
self.__allow_substitution = True
|
|
35
|
+
|
|
36
|
+
def green(self, text: str) -> str:
|
|
37
|
+
"""
|
|
38
|
+
### This function returns the given text formatted in green color.
|
|
39
|
+
|
|
40
|
+
#### Params:
|
|
41
|
+
- text (str): Text to format.
|
|
42
|
+
|
|
43
|
+
#### Returns:
|
|
44
|
+
- (str): Text formatted in green color.
|
|
45
|
+
"""
|
|
46
|
+
return self.__format_text(text, self.__GREEN)
|
|
47
|
+
|
|
48
|
+
def yellow(self, text: str) -> str:
|
|
49
|
+
"""
|
|
50
|
+
### This function returns the given text formatted in yellow color.
|
|
51
|
+
|
|
52
|
+
#### Params:
|
|
53
|
+
- text (str): Text to format.
|
|
54
|
+
|
|
55
|
+
#### Returns:
|
|
56
|
+
- (str): Text formatted in yellow color.
|
|
57
|
+
"""
|
|
58
|
+
return self.__format_text(text, self.__YELLOW)
|
|
59
|
+
|
|
60
|
+
def red(self, text: str) -> str:
|
|
61
|
+
"""
|
|
62
|
+
### This function returns the given text formatted in red color.
|
|
63
|
+
|
|
64
|
+
#### Params:
|
|
65
|
+
- text (str): Text to format.
|
|
66
|
+
|
|
67
|
+
#### Returns:
|
|
68
|
+
- (str): Text formatted in red color.
|
|
69
|
+
"""
|
|
70
|
+
return self.__format_text(text, self.__RED)
|
|
71
|
+
|
|
72
|
+
def blue(self, text: str) -> str:
|
|
73
|
+
"""
|
|
74
|
+
### This function returns the given text formatted in blue color.
|
|
75
|
+
|
|
76
|
+
#### Params:
|
|
77
|
+
- text (str): Text to format.
|
|
78
|
+
|
|
79
|
+
#### Returns:
|
|
80
|
+
- (str): Text formatted in blue color.
|
|
81
|
+
"""
|
|
82
|
+
return self.__format_text(text, self.__BLUE)
|
|
83
|
+
|
|
84
|
+
def bold(self, text: str) -> str:
|
|
85
|
+
"""
|
|
86
|
+
### This function returns the given text formatted in bold.
|
|
87
|
+
|
|
88
|
+
#### Params:
|
|
89
|
+
- text (str): Text to format.
|
|
90
|
+
|
|
91
|
+
#### Returns:
|
|
92
|
+
- (str): Text formatted in bold.
|
|
93
|
+
"""
|
|
94
|
+
return self.__format_text(text, self.__BOLD)
|
|
95
|
+
|
|
96
|
+
def start_log_file(self, log_path: str):
|
|
97
|
+
"""
|
|
98
|
+
### Initiates the log file.
|
|
99
|
+
|
|
100
|
+
#### Params:
|
|
101
|
+
- log_path (str): Path to the log file.
|
|
102
|
+
"""
|
|
103
|
+
if self.__log_file is None:
|
|
104
|
+
self.__log_file = open(log_path, 'w')
|
|
105
|
+
|
|
106
|
+
def close(self):
|
|
107
|
+
"""
|
|
108
|
+
### Closes the log file.
|
|
109
|
+
"""
|
|
110
|
+
if self.__log_file:
|
|
111
|
+
self.__log_file.close()
|
|
112
|
+
self.__log_file = None
|
|
113
|
+
|
|
114
|
+
def set_allow_substitution(self, allow_substitution: bool):
|
|
115
|
+
"""
|
|
116
|
+
### Modifies console output behaviour, allowing or disallowing substitutions.
|
|
117
|
+
|
|
118
|
+
#### Params:
|
|
119
|
+
- allow_substitution (bool): If False, console outputs won't be substituted.
|
|
120
|
+
"""
|
|
121
|
+
self.__allow_substitution = allow_substitution
|
|
122
|
+
|
|
123
|
+
def __call__(self, text: str, show_in_terminal: bool=True, substitute: bool=False):
|
|
124
|
+
"""
|
|
125
|
+
### Log a message.
|
|
126
|
+
|
|
127
|
+
#### Params:
|
|
128
|
+
- text (str): Message to be logged. Supports fancy formatting.
|
|
129
|
+
- show_in_terminal (bool): Optional. If True, text is also printed through terminal.
|
|
130
|
+
- substitute (bool): Optional. If True, previous line is substituted with new text. Only used when show_in_terminal = True.
|
|
131
|
+
"""
|
|
132
|
+
if self.__log_file is not None:
|
|
133
|
+
print(self.__remove_non_printable(text), file=self.__log_file, flush=True)
|
|
134
|
+
|
|
135
|
+
if show_in_terminal:
|
|
136
|
+
text = self.__substitute_lines(text) if self.__allow_substitution and substitute else text
|
|
137
|
+
print(text, flush=True)
|
|
138
|
+
# Store length of printed string for next substitution calculation
|
|
139
|
+
self.__len_last_printed_elem = len(self.__remove_non_printable(text))
|
|
140
|
+
|
|
141
|
+
def log_error(self, error_msg: str, ret_code: int=1, add_portal_link: bool=True):
|
|
142
|
+
"""
|
|
143
|
+
### Prints an error message.
|
|
144
|
+
|
|
145
|
+
#### Params:
|
|
146
|
+
- error_msg (str): Error message to show.
|
|
147
|
+
- ret_code (int): Optional. Return code to end the exection with.
|
|
148
|
+
- add_portal_link (bool): If True, a message linking the documentation portal is shown.
|
|
149
|
+
"""
|
|
150
|
+
error = errors.ERROR_CODES.get(ret_code, errors.ERROR_CODES[errors.UNKOW_ERROR])
|
|
151
|
+
error_str = error_msg + '\n\n' if error_msg else ''
|
|
152
|
+
error_str += f'Error {ret_code}: {error[0]}'
|
|
153
|
+
error_str += f"\n{error[1]}" if error[1] else ''
|
|
154
|
+
if add_portal_link:
|
|
155
|
+
error_str += f'\nMore details on the Xmipp documentation portal: {urls.DOCUMENTATION_URL}'
|
|
156
|
+
|
|
157
|
+
self.__call__(self.red(error_str), show_in_terminal=True)
|
|
158
|
+
|
|
159
|
+
def log_in_streaming(self, stream: BufferedReader, show_in_terminal: bool=False, substitute: bool=False, err: bool=False):
|
|
160
|
+
"""
|
|
161
|
+
### Receives a process output stream and logs its lines.
|
|
162
|
+
|
|
163
|
+
#### Params:
|
|
164
|
+
- stream (BufferedReader): Function to run.
|
|
165
|
+
- show_in_terminal (bool): Optional. If True, output will also be printed through terminal.
|
|
166
|
+
- substitute (bool): Optional. If True, output will replace previous line. Only used when show is True.
|
|
167
|
+
- err (bool): Optional. If True, the stream contains an error. Otherwise, it is regular output.
|
|
168
|
+
"""
|
|
169
|
+
if show_in_terminal and self.__allow_substitution and substitute:
|
|
170
|
+
print("")
|
|
171
|
+
|
|
172
|
+
for line in iter(stream.readline, b''):
|
|
173
|
+
line = line.decode().replace("\n", "")
|
|
174
|
+
if err:
|
|
175
|
+
line = self.red(line)
|
|
176
|
+
self.__call__(line, show_in_terminal=show_in_terminal, substitute=substitute)
|
|
177
|
+
|
|
178
|
+
def __remove_non_printable(self, text: str) -> str:
|
|
179
|
+
"""
|
|
180
|
+
### This function returns the given text without non printable characters.
|
|
181
|
+
|
|
182
|
+
#### Params:
|
|
183
|
+
- text (str): Text to remove format.
|
|
184
|
+
|
|
185
|
+
#### Returns:
|
|
186
|
+
- (str): Text without format.
|
|
187
|
+
"""
|
|
188
|
+
for formatting_char in self.__FORMATTING_CHARACTERS:
|
|
189
|
+
text = text.replace(formatting_char, "")
|
|
190
|
+
return text
|
|
191
|
+
|
|
192
|
+
def __get_n_last_lines(self) -> int:
|
|
193
|
+
"""
|
|
194
|
+
### This function returns the number of lines of the terminal the last print occupied.
|
|
195
|
+
|
|
196
|
+
#### Returns:
|
|
197
|
+
- (int): Number of lines of the last print.
|
|
198
|
+
"""
|
|
199
|
+
return math.ceil(self.__len_last_printed_elem / shutil.get_terminal_size().columns)
|
|
200
|
+
|
|
201
|
+
def __format_text(self, text: str, format_code: str) -> str:
|
|
202
|
+
"""
|
|
203
|
+
### Returns the given text formatted in the given format code.
|
|
204
|
+
|
|
205
|
+
#### Params:
|
|
206
|
+
- text (str): Text to format.
|
|
207
|
+
- format_code (str): Formatting character.
|
|
208
|
+
|
|
209
|
+
#### Returns:
|
|
210
|
+
- (str): Text formatted.
|
|
211
|
+
"""
|
|
212
|
+
return f"{format_code}{text}{self.__END_FORMAT}"
|
|
213
|
+
|
|
214
|
+
def __substitute_lines(self, text: str) -> str:
|
|
215
|
+
"""
|
|
216
|
+
### Removes the appropiate lines from the terminal to show a given text.
|
|
217
|
+
|
|
218
|
+
#### Params:
|
|
219
|
+
- text (str): Text to show substituting some lines.
|
|
220
|
+
|
|
221
|
+
#### Returns:
|
|
222
|
+
- (str): Text with line substitution characters as a prefix.
|
|
223
|
+
"""
|
|
224
|
+
substitution_chars = [f'{self.__UP}{self.__REMOVE_LINE}' for _ in range(self.__get_n_last_lines())]
|
|
225
|
+
return f"{''.join(substitution_chars)}{text}"
|
|
226
|
+
|
|
227
|
+
"""
|
|
228
|
+
### Global logger.
|
|
229
|
+
"""
|
|
230
|
+
logger = Logger()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from xmipp3_installer.application.logger.logger import logger
|
|
2
|
+
from xmipp3_installer.installer.handlers import git_handler
|
|
3
|
+
|
|
4
|
+
__SECTION_MESSAGE_LEN = 60
|
|
5
|
+
|
|
6
|
+
def get_done_message() -> str:
|
|
7
|
+
"""
|
|
8
|
+
### Returns the standard message string to use when a task is completed.
|
|
9
|
+
|
|
10
|
+
#### Returns:
|
|
11
|
+
- (str): Task completion message.
|
|
12
|
+
"""
|
|
13
|
+
return logger.green("Done")
|
|
14
|
+
|
|
15
|
+
def get_working_message() -> str:
|
|
16
|
+
"""
|
|
17
|
+
### Returns the standard message string to use when a task is in progress.
|
|
18
|
+
|
|
19
|
+
#### Returns:
|
|
20
|
+
- (str): Task in progress message.
|
|
21
|
+
"""
|
|
22
|
+
return logger.yellow("Working...")
|
|
23
|
+
|
|
24
|
+
def get_section_message(text: str) -> str:
|
|
25
|
+
"""
|
|
26
|
+
### Returns the given text as a section header.
|
|
27
|
+
|
|
28
|
+
#### Params:
|
|
29
|
+
- text (str): Title of the section.
|
|
30
|
+
|
|
31
|
+
#### Returns:
|
|
32
|
+
- (str): Formatted section header.
|
|
33
|
+
"""
|
|
34
|
+
text_len = len(text)
|
|
35
|
+
remaining_len = __SECTION_MESSAGE_LEN - text_len
|
|
36
|
+
if remaining_len < 4:
|
|
37
|
+
return text
|
|
38
|
+
|
|
39
|
+
n_dashes = remaining_len - 2
|
|
40
|
+
n_final_dashes = int(n_dashes / 2)
|
|
41
|
+
n_initial_dashes = n_dashes - n_final_dashes
|
|
42
|
+
final_dashes = ''.join(['-' for _ in range(n_final_dashes)])
|
|
43
|
+
initial_dashes = ''.join(['-' for _ in range(n_initial_dashes)])
|
|
44
|
+
return f"{initial_dashes} {text} {final_dashes}"
|
|
45
|
+
|
|
46
|
+
def get_success_message(tag_version: str) -> str:
|
|
47
|
+
"""
|
|
48
|
+
### Returns the message shown when Xmipp is compiled successfully.
|
|
49
|
+
|
|
50
|
+
#### Params:
|
|
51
|
+
- tag_version (str): Version number of the latest release.
|
|
52
|
+
|
|
53
|
+
#### Returms:
|
|
54
|
+
- (str): Success message.
|
|
55
|
+
"""
|
|
56
|
+
release_name = tag_version if git_handler.is_tag() else git_handler.get_current_branch()
|
|
57
|
+
|
|
58
|
+
box_wrapper = '* *'
|
|
59
|
+
half_len_box_wrapper = int(len(box_wrapper) / 2)
|
|
60
|
+
release_message = f'Xmipp {release_name} has been successfully installed, enjoy it!'
|
|
61
|
+
total_len = len(release_message) + len(box_wrapper)
|
|
62
|
+
release_message = f'{box_wrapper[:half_len_box_wrapper]}{logger.green(release_message)}{box_wrapper[half_len_box_wrapper:]}'
|
|
63
|
+
margin_line = f"*{' ' * (total_len - 2)}*"
|
|
64
|
+
box_border = '*' * total_len
|
|
65
|
+
|
|
66
|
+
return '\n'.join(["", box_border, margin_line, release_message, margin_line, box_border])
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
def get_user_confirmation(confirmation_text: str, case_sensitive: bool=True) -> bool:
|
|
2
|
+
"""
|
|
3
|
+
### Receives confirmation from user input.
|
|
4
|
+
|
|
5
|
+
#### Params:
|
|
6
|
+
- confirmation_text (str): The text the user needs to input to confirm.
|
|
7
|
+
- case_sensitive (bool): Optional. If True, the text entered has to exactly match.
|
|
8
|
+
|
|
9
|
+
#### Returns:
|
|
10
|
+
- (bool): True if the user confirmed, False otherwise.
|
|
11
|
+
"""
|
|
12
|
+
received_input = input()
|
|
13
|
+
if not case_sensitive:
|
|
14
|
+
received_input = received_input.lower()
|
|
15
|
+
confirmation_text = confirmation_text.lower()
|
|
16
|
+
return received_input == confirmation_text
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""### Contains the main logic of the project."""
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""### Contains constants used to configure the installer."""
|
|
2
|
+
|
|
3
|
+
# Repository names
|
|
4
|
+
XMIPP = 'xmipp'
|
|
5
|
+
XMIPP_CORE = 'xmippCore'
|
|
6
|
+
XMIPP_VIZ = 'xmippViz'
|
|
7
|
+
XMIPP_SOURCES = [XMIPP_CORE, XMIPP_VIZ]
|
|
8
|
+
|
|
9
|
+
# Branch names
|
|
10
|
+
DEVEL_BRANCHNAME = 'devel'
|
|
11
|
+
MASTER_BRANCHNAME = 'master'
|
|
12
|
+
|
|
13
|
+
# Context
|
|
14
|
+
VERSIONS_CONTEXT_KEY = "versions"
|
|
15
|
+
|
|
16
|
+
# Others
|
|
17
|
+
TAIL_LOG_NCHARS = 300
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from xmipp3_installer.installer import constants
|
|
4
|
+
|
|
5
|
+
# General paths
|
|
6
|
+
SOURCES_PATH = "src"
|
|
7
|
+
BUILD_PATH = "build"
|
|
8
|
+
INSTALL_PATH = "dist"
|
|
9
|
+
BINARIES_PATH = os.path.join(INSTALL_PATH, "bin")
|
|
10
|
+
#CMAKE_CACHE_PATH = os.path.join(BUILD_PATH, 'CMakeCache.txt')
|
|
11
|
+
SCIPION_SOFTWARE_EM = os.path.join("scipionfiles", "downloads", "scipion", "software", "em")
|
|
12
|
+
|
|
13
|
+
# General file paths
|
|
14
|
+
LOG_FILE = 'compilation.log'
|
|
15
|
+
LIBRARY_VERSIONS_FILE = os.path.join(BUILD_PATH, 'versions.txt')
|
|
16
|
+
CONFIG_FILE = 'xmipp.conf'
|
|
17
|
+
VERSION_INFO_FILE = "version-info.json"
|
|
18
|
+
|
|
19
|
+
# Source paths
|
|
20
|
+
def get_source_path(source: str) -> str:
|
|
21
|
+
"""
|
|
22
|
+
### Returns the path to the given source.
|
|
23
|
+
|
|
24
|
+
#### Params:
|
|
25
|
+
- source (str): Source name.
|
|
26
|
+
|
|
27
|
+
#### Returns:
|
|
28
|
+
- (str): Path to the source.
|
|
29
|
+
"""
|
|
30
|
+
return os.path.abspath(os.path.join(SOURCES_PATH, source))
|
|
31
|
+
XMIPP_CORE_PATH = get_source_path(constants.XMIPP_CORE)
|
|
32
|
+
XMIPP_SOURCE_PATHS = [get_source_path(source) for source in constants.XMIPP_SOURCES]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""### Contains the handlers, providing interfaces to interact with different systems."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""### Contains CMake handler & different related constants."""
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""### Contains all needed CMake constants."""
|
|
2
|
+
|
|
3
|
+
from xmipp3_installer.repository.config_vars import variables
|
|
4
|
+
|
|
5
|
+
DEFAULT_CMAKE = 'cmake'
|
|
6
|
+
|
|
7
|
+
# CMake cache file variables to look for
|
|
8
|
+
XMIPP_USE_CUDA=variables.CUDA
|
|
9
|
+
XMIPP_USE_MPI=variables.MPI
|
|
10
|
+
XMIPP_USE_MATLAB=variables.MATLAB
|
|
11
|
+
XMIPP_LINK_TO_SCIPION=variables.LINK_SCIPION
|
|
12
|
+
CMAKE_BUILD_TYPE='CMAKE_BUILD_TYPE'
|
|
13
|
+
CMAKE_C_COMPILER=variables.CC
|
|
14
|
+
CMAKE_CXX_COMPILER=variables.CXX
|
|
15
|
+
CMAKE_CUDA_COMPILER=variables.CUDA_COMPILER
|
|
16
|
+
|
|
17
|
+
# CMake saved version variables
|
|
18
|
+
CMAKE_PYTHON = 'Python3'
|
|
19
|
+
CMAKE_CUDA = 'CUDA'
|
|
20
|
+
CMAKE_MPI = 'MPI'
|
|
21
|
+
CMAKE_HDF5 = 'HDF5'
|
|
22
|
+
CMAKE_JPEG = 'JPEG'
|
|
23
|
+
CMAKE_SQLITE = 'SQLite3'
|
|
24
|
+
CMAKE_JAVA = 'Java'
|
|
25
|
+
CMAKE_CMAKE = 'CMake'
|
|
26
|
+
CMAKE_GCC = 'CC'
|
|
27
|
+
CMAKE_GPP = 'CXX'
|