Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Dec 1, 2024
1 parent fffba1a commit b093aa4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
20 changes: 11 additions & 9 deletions src/sio3pack/packages/package/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sio3pack import LocalFile
from sio3pack.files import File
from sio3pack.graph import Graph
from sio3pack.graph import Graph, GraphOperation
from sio3pack.packages.exceptions import UnknownPackageType
from sio3pack.test import Test
from sio3pack.utils.archive import Archive
Expand All @@ -16,14 +16,8 @@ class Package(RegisteredSubclassesBase):

abstract = True

def __init__(self, file: File):
def __init__(self):
super().__init__()
self.file = file
if isinstance(file, LocalFile):
if Archive.is_archive(file.path):
self.is_archive = True
else:
self.is_archive = False

@classmethod
def from_file(cls, file: LocalFile, django_settings=None):
Expand All @@ -32,6 +26,14 @@ def from_file(cls, file: LocalFile, django_settings=None):
return subclass(file, django_settings)
raise UnknownPackageType(file.path)

def _from_file(self, file: LocalFile):
self.file = file
if isinstance(file, LocalFile):
if Archive.is_archive(file.path):
self.is_archive = True
else:
self.is_archive = False

def get_task_id(self) -> str:
pass

Expand All @@ -56,7 +58,7 @@ def get_tests(self) -> list[Test]:
def get_test(self, test_id: str) -> Test:
pass

def get_package_graph(self) -> Graph:
def get_unpack_graph(self) -> GraphOperation | None:
pass

def get_run_graph(self, file: File, tests: list[Test] | None = None) -> Graph:
Expand Down
39 changes: 19 additions & 20 deletions src/sio3pack/packages/sinolpack/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,26 @@ def __del__(self):
if hasattr(self, "tmpdir"):
self.tmpdir.cleanup()

def __init__(self, file: File, django_settings=None):
super().__init__(file)

if isinstance(file, LocalFile):
if self.is_archive:
archive = Archive(file.path)
self.short_name = self._find_main_dir(archive)
self.tmpdir = tempfile.TemporaryDirectory()
archive.extract(to_path=self.tmpdir.name)
self.rootdir = os.path.join(self.tmpdir.name, self.short_name)
else:
self.short_name = os.path.basename(file.path)
self.rootdir = file.path

try:
graph_file = self.get_in_root("graph.json")
self.graph_manager = GraphManager.from_file(graph_file)
except FileNotFoundError:
self.has_custom_graph = False
def __init__(self):
super().__init__()

def _from_file(self, file: LocalFile, django_settings=None):
super()._from_file(file)
if self.is_archive:
archive = Archive(file.path)
self.short_name = self._find_main_dir(archive)
self.tmpdir = tempfile.TemporaryDirectory()
archive.extract(to_path=self.tmpdir.name)
self.rootdir = os.path.join(self.tmpdir.name, self.short_name)
else:
raise NotImplementedError()
self.short_name = os.path.basename(file.path)
self.rootdir = file.path

try:
graph_file = self.get_in_root("graph.json")
self.graph_manager = GraphManager.from_file(graph_file)
except FileNotFoundError:
self.has_custom_graph = False

self.django_settings = django_settings

Expand Down

0 comments on commit b093aa4

Please sign in to comment.