Skip to content

Commit 197bf75

Browse files
committed
Refactor in order to simplify further developments
Refector in order to simplify the addition of: - the option that prints Linux versions without all commits - progress bar - multithreading support Change-Id: Ifaa9993db34b04f56dad09e00fd8842bb0afe337
1 parent 4ba319c commit 197bf75

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

linux-version-finder

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ def version_key(version: str) -> int:
6565
return int(m.group(1)) * 10
6666

6767

68-
def main(
69-
commits: List[str],
70-
debug: bool = typer.Option(False, help="Print debug info."),
71-
):
72-
if debug:
73-
logging.basicConfig(level=logging.DEBUG)
74-
single_script_path = os.path.dirname(sys.argv[0]) + "/linux-version-finder-single"
68+
def find_commits_versions(
69+
commits: list[str], single_script_path: str
70+
) -> tuple[list[str], dict[str, list]]:
71+
"""Find all the versions associated to the commits
72+
73+
This is the first half of the tool and the part the require almost all the cpu/mem"""
7574
minor_versions = get_minor_versions()
7675
versions_count = collections.defaultdict(list)
7776
for commit in commits:
@@ -85,8 +84,13 @@ def main(
8584
for i in range(start, len(minor_versions)):
8685
minor_version = minor_versions[i]
8786
versions_count[minor_version].append(minor_version + "-rc0")
88-
logging.debug(versions_count)
87+
return minor_versions, versions_count
8988

89+
90+
def print_versions_with_all_commits(
91+
commits: list[str], minor_versions: list[str], versions_count: dict[str, list]
92+
) -> None:
93+
"""Print Linux versions that contains all the commits"""
9094
len_commits = len(commits)
9195
first = True
9296
for minor_version in reversed(minor_versions):
@@ -102,5 +106,18 @@ def main(
102106
print("")
103107

104108

109+
def main(
110+
commits: List[str],
111+
debug: bool = typer.Option(False, help="Print debug info."),
112+
):
113+
if debug:
114+
logging.basicConfig(level=logging.DEBUG)
115+
single_script_path = os.path.dirname(sys.argv[0]) + "/linux-version-finder-single"
116+
minor_versions, versions_count = find_commits_versions(commits, single_script_path)
117+
logging.debug(versions_count)
118+
119+
print_versions_with_all_commits(commits, minor_versions, versions_count)
120+
121+
105122
if __name__ == "__main__":
106123
typer.run(main)

0 commit comments

Comments
 (0)