From 172242891def82c573af9137d0d5f1d5e01fca1a Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Wed, 2 Nov 2022 15:14:38 +0100 Subject: [PATCH] Fix up some code after aplanas' continued review --- git-importer.py | 2 +- lib/abstract_walker.py | 6 +++++- lib/db_revision.py | 5 +++-- lib/flat_walker.py | 11 +++-------- lib/git.py | 10 +++++----- lib/git_exporter.py | 9 ++++----- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/git-importer.py b/git-importer.py index f276bf3..eabadbf 100755 --- a/git-importer.py +++ b/git-importer.py @@ -91,7 +91,7 @@ def main(): return if not args.repodir: - args.repodir = pathlib.Path("repos/" + args.package) + args.repodir = pathlib.Path("repos") / args.package importer = Importer(URL_OBS, "openSUSE:Factory", args.package) importer.import_into_db() diff --git a/lib/abstract_walker.py b/lib/abstract_walker.py index e1370ba..2526908 100644 --- a/lib/abstract_walker.py +++ b/lib/abstract_walker.py @@ -1,6 +1,10 @@ -class AbstractWalker: +from abc import ABC, abstractmethod + + +class AbstractWalker(ABC): """Just a duck type, most likely not needed by python, but I find interface classes preferable (java school)""" + @abstractmethod def call(self, node, is_source): pass diff --git a/lib/db_revision.py b/lib/db_revision.py index cf2e4aa..da37166 100644 --- a/lib/db_revision.py +++ b/lib/db_revision.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging from hashlib import md5 +from pathlib import PurePath from typing import Optional from lib.db import DB @@ -223,11 +224,11 @@ class DBRevision: for entry in self.files_list(db): if old_files.get(entry["name"]) != f"{entry['md5']}-{entry['size']}": logging.debug(f"Download {entry['name']}") - to_download.append((entry["name"], entry["md5"])) + to_download.append((PurePath(entry["name"]), entry["md5"])) old_files.pop(entry["name"], None) for entry in old_files.keys(): logging.debug(f"Delete {entry}") - to_delete.append(entry) + to_delete.append(PurePath(entry)) return to_download, to_delete @staticmethod diff --git a/lib/flat_walker.py b/lib/flat_walker.py index 7b2df52..7176da6 100644 --- a/lib/flat_walker.py +++ b/lib/flat_walker.py @@ -9,12 +9,8 @@ class FlatNode: self.parent2 = parent2 def __str__(self) -> str: - p1_str = "" - if self.parent1: - p1_str = f" p1:{self.parent1.short_string()}" - p2_str = "" - if self.parent2: - p2_str = f" p2:{self.parent2.short_string()}" + p1_str = f" p1:{self.parent1.short_string()}" if self.parent1 else "" + p2_str = f" p2:{self.parent2.short_string()}" if self.parent2 else "" return f"{self.branch} c:{self.commit.short_string()}{p1_str}{p2_str}" @@ -36,8 +32,7 @@ class FlatTreeWalker(AbstractWalker): def handle_source_node(self, node) -> None: if self.rebase_devel and node.parent and node.parent.merged_into: self.add("devel", node.revision, node.parent.merged_into.revision) - return - if node.parent: + elif node.parent: self.add("devel", node.revision, node.parent.revision) elif self.last_merge: self.add("devel", node.revision, self.last_merge.parent.revision) diff --git a/lib/git.py b/lib/git.py index 53007cb..01d0a15 100644 --- a/lib/git.py +++ b/lib/git.py @@ -256,11 +256,11 @@ class Git: ) return any(fnmatch.fnmatch(filename, line) for line in patterns) - def remove(self, filename): - self.repo.index.remove(filename) - (self.path / filename).unlink() + def remove(self, file: pathlib.Path): + self.repo.index.remove(file.name) + (self.path / file).unlink() patterns = self.get_specific_lfs_gitattributes() - if filename in patterns: - patterns.remove(filename) + if file.name in patterns: + patterns.remove(file.name) self.add_specific_lfs_gitattributes(patterns) diff --git a/lib/git_exporter.py b/lib/git_exporter.py index f988205..5f89f94 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -1,5 +1,6 @@ import logging import os +from pathlib import Path import yaml @@ -121,10 +122,8 @@ class GitExporter: logging.debug(f"Committing {flat}") self.commit_flat(db, flat, branch_state) - def limit_download(self, file): - if file.endswith(".spec") or file.endswith(".changes"): - return True - return False + def limit_download(self, file: Path): + return file.suffix in (".spec", ".changes") def commit_flat(self, db, flat, branch_state): parents = [] @@ -144,7 +143,7 @@ class GitExporter: self.obs.download( flat.commit.project, flat.commit.package, - file, + file.name, flat.commit.expanded_srcmd5, self.git.path, file_md5=md5,