Fix up some code after aplanas' continued review

This commit is contained in:
Stephan Kulow 2022-11-02 15:14:38 +01:00
parent 6ac0f90ec7
commit 172242891d
6 changed files with 21 additions and 22 deletions

View File

@ -91,7 +91,7 @@ def main():
return return
if not args.repodir: 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 = Importer(URL_OBS, "openSUSE:Factory", args.package)
importer.import_into_db() importer.import_into_db()

View File

@ -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 """Just a duck type, most likely not needed by python, but I
find interface classes preferable (java school)""" find interface classes preferable (java school)"""
@abstractmethod
def call(self, node, is_source): def call(self, node, is_source):
pass pass

View File

@ -2,6 +2,7 @@ from __future__ import annotations
import logging import logging
from hashlib import md5 from hashlib import md5
from pathlib import PurePath
from typing import Optional from typing import Optional
from lib.db import DB from lib.db import DB
@ -223,11 +224,11 @@ class DBRevision:
for entry in self.files_list(db): for entry in self.files_list(db):
if old_files.get(entry["name"]) != f"{entry['md5']}-{entry['size']}": if old_files.get(entry["name"]) != f"{entry['md5']}-{entry['size']}":
logging.debug(f"Download {entry['name']}") 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) old_files.pop(entry["name"], None)
for entry in old_files.keys(): for entry in old_files.keys():
logging.debug(f"Delete {entry}") logging.debug(f"Delete {entry}")
to_delete.append(entry) to_delete.append(PurePath(entry))
return to_download, to_delete return to_download, to_delete
@staticmethod @staticmethod

View File

@ -9,12 +9,8 @@ class FlatNode:
self.parent2 = parent2 self.parent2 = parent2
def __str__(self) -> str: def __str__(self) -> str:
p1_str = "" p1_str = f" p1:{self.parent1.short_string()}" if self.parent1 else ""
if self.parent1: p2_str = f" p2:{self.parent2.short_string()}" if self.parent2 else ""
p1_str = f" p1:{self.parent1.short_string()}"
p2_str = ""
if self.parent2:
p2_str = f" p2:{self.parent2.short_string()}"
return f"{self.branch} c:{self.commit.short_string()}{p1_str}{p2_str}" 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: def handle_source_node(self, node) -> None:
if self.rebase_devel and node.parent and node.parent.merged_into: if self.rebase_devel and node.parent and node.parent.merged_into:
self.add("devel", node.revision, node.parent.merged_into.revision) self.add("devel", node.revision, node.parent.merged_into.revision)
return elif node.parent:
if node.parent:
self.add("devel", node.revision, node.parent.revision) self.add("devel", node.revision, node.parent.revision)
elif self.last_merge: elif self.last_merge:
self.add("devel", node.revision, self.last_merge.parent.revision) self.add("devel", node.revision, self.last_merge.parent.revision)

View File

@ -256,11 +256,11 @@ class Git:
) )
return any(fnmatch.fnmatch(filename, line) for line in patterns) return any(fnmatch.fnmatch(filename, line) for line in patterns)
def remove(self, filename): def remove(self, file: pathlib.Path):
self.repo.index.remove(filename) self.repo.index.remove(file.name)
(self.path / filename).unlink() (self.path / file).unlink()
patterns = self.get_specific_lfs_gitattributes() patterns = self.get_specific_lfs_gitattributes()
if filename in patterns: if file.name in patterns:
patterns.remove(filename) patterns.remove(file.name)
self.add_specific_lfs_gitattributes(patterns) self.add_specific_lfs_gitattributes(patterns)

View File

@ -1,5 +1,6 @@
import logging import logging
import os import os
from pathlib import Path
import yaml import yaml
@ -121,10 +122,8 @@ class GitExporter:
logging.debug(f"Committing {flat}") logging.debug(f"Committing {flat}")
self.commit_flat(db, flat, branch_state) self.commit_flat(db, flat, branch_state)
def limit_download(self, file): def limit_download(self, file: Path):
if file.endswith(".spec") or file.endswith(".changes"): return file.suffix in (".spec", ".changes")
return True
return False
def commit_flat(self, db, flat, branch_state): def commit_flat(self, db, flat, branch_state):
parents = [] parents = []
@ -144,7 +143,7 @@ class GitExporter:
self.obs.download( self.obs.download(
flat.commit.project, flat.commit.project,
flat.commit.package, flat.commit.package,
file, file.name,
flat.commit.expanded_srcmd5, flat.commit.expanded_srcmd5,
self.git.path, self.git.path,
file_md5=md5, file_md5=md5,