|
1 | | -import os |
2 | | -import errno |
3 | | -import shutil |
4 | | - |
5 | 1 | from leapp.actors import Actor |
6 | 2 | from leapp.models import InstalledRPM |
7 | 3 | from leapp.tags import DownloadPhaseTag, IPUWorkflowTag |
8 | 4 | from leapp.libraries.common.cllaunch import run_on_cloudlinux |
| 5 | +from leapp.libraries.actor import clearpackageconflicts |
9 | 6 |
|
10 | 7 |
|
11 | 8 | class ClearPackageConflicts(Actor): |
12 | 9 | """ |
13 | | - Remove several python package files manually to resolve conflicts between versions of packages to be upgraded. |
| 10 | + Remove several Python package files manually to resolve conflicts |
| 11 | + between versions of packages to be upgraded. |
| 12 | +
|
| 13 | + When the corresponding packages are detected, |
| 14 | + the conflicting files are removed to allow for an upgrade to the new package versions. |
| 15 | +
|
| 16 | + While most packages are handled automatically by the package manager, |
| 17 | + some specific packages require direct intervention to resolve conflicts |
| 18 | + between their own versions on different OS releases. |
14 | 19 | """ |
15 | 20 |
|
16 | 21 | name = "clear_package_conflicts" |
17 | 22 | consumes = (InstalledRPM,) |
18 | 23 | produces = () |
19 | 24 | tags = (DownloadPhaseTag.Before, IPUWorkflowTag) |
20 | | - rpm_lookup = None |
21 | | - |
22 | | - def has_package(self, name): |
23 | | - """ |
24 | | - Check whether the package is installed. |
25 | | - Looks only for the package name, nothing else. |
26 | | - """ |
27 | | - if self.rpm_lookup: |
28 | | - return name in self.rpm_lookup |
29 | | - |
30 | | - def problem_packages_installed(self, problem_packages): |
31 | | - """ |
32 | | - Check whether any of the problem packages are present in the system. |
33 | | - """ |
34 | | - for pkg in problem_packages: |
35 | | - if self.has_package(pkg): |
36 | | - self.log.debug("Conflicting package {} detected".format(pkg)) |
37 | | - return True |
38 | | - return False |
39 | | - |
40 | | - def clear_problem_files(self, problem_files, problem_dirs): |
41 | | - """ |
42 | | - Go over the list of problem files and directories and remove them if they exist. |
43 | | - They'll be replaced by the new packages. |
44 | | - """ |
45 | | - for p_dir in problem_dirs: |
46 | | - try: |
47 | | - if os.path.isdir(p_dir): |
48 | | - shutil.rmtree(p_dir) |
49 | | - self.log.debug("Conflicting directory {} removed".format(p_dir)) |
50 | | - except OSError as e: |
51 | | - if e.errno != errno.ENOENT: |
52 | | - raise |
53 | | - |
54 | | - for p_file in problem_files: |
55 | | - try: |
56 | | - if os.path.isfile(p_file): |
57 | | - os.remove(p_file) |
58 | | - self.log.debug("Conflicting file {} removed".format(p_file)) |
59 | | - except OSError as e: |
60 | | - if e.errno != errno.ENOENT: |
61 | | - raise |
62 | | - |
63 | | - def alt_python37_handle(self): |
64 | | - """ |
65 | | - These alt-python37 packages are conflicting with their own builds for EL8. |
66 | | - """ |
67 | | - problem_packages = [ |
68 | | - "alt-python37-six", |
69 | | - "alt-python37-pytz", |
70 | | - ] |
71 | | - problem_files = [] |
72 | | - problem_dirs = [ |
73 | | - "/opt/alt/python37/lib/python3.7/site-packages/six-1.15.0-py3.7.egg-info", |
74 | | - "/opt/alt/python37/lib/python3.7/site-packages/pytz-2017.2-py3.7.egg-info", |
75 | | - ] |
76 | | - |
77 | | - if self.problem_packages_installed(problem_packages): |
78 | | - self.clear_problem_files(problem_files, problem_dirs) |
79 | | - |
80 | | - def lua_cjson_handle(self): |
81 | | - """ |
82 | | - lua-cjson package is conflicting with the incoming lua-cjson package for EL8. |
83 | | - """ |
84 | | - problem_packages = [ |
85 | | - "lua-cjson" |
86 | | - ] |
87 | | - problem_files = [ |
88 | | - "/usr/lib64/lua/5.1/cjson.so", |
89 | | - "/usr/share/lua/5.1/cjson/tests/bench.lua", |
90 | | - "/usr/share/lua/5.1/cjson/tests/genutf8.pl", |
91 | | - "/usr/share/lua/5.1/cjson/tests/test.lua", |
92 | | - ] |
93 | | - problem_dirs = [] |
94 | | - |
95 | | - if self.problem_packages_installed(problem_packages): |
96 | | - self.clear_problem_files(problem_files, problem_dirs) |
97 | 25 |
|
98 | 26 | @run_on_cloudlinux |
99 | 27 | def process(self): |
100 | | - # todo: (CLOS-3205) investigate why set is needed here |
101 | | - self.rpm_lookup = [rpm for rpm in self.consume(InstalledRPM)] |
102 | | - self.alt_python37_handle() |
| 28 | + clearpackageconflicts.process() |
0 commit comments