-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c577483
commit 8e92a50
Showing
17 changed files
with
149 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
__version__ = "0.0.1" | ||
|
||
from sio3pack.files.file import File | ||
from sio3pack.files import LocalFile | ||
from sio3pack.packages.package import Package | ||
|
||
|
||
def from_file(file: str | File, django_settings=None) -> Package: | ||
def from_file(file: str | LocalFile, django_settings=None) -> Package: | ||
""" | ||
Initialize a package object from a file (archive or directory). | ||
:param file: The file path or File object. | ||
:param django_settings: Django settings object. | ||
:return: The package object. | ||
""" | ||
if isinstance(file, str): | ||
file = File(file) | ||
return Package.from_file(file, django_settings) | ||
file = LocalFile(file) | ||
return Package.from_file(file, django_settings=django_settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from sio3pack.files.filetracker_file import FiletrackerFile | ||
from sio3pack.files.local_file import LocalFile | ||
from sio3pack.files.file import File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,16 @@ | ||
import os.path | ||
|
||
|
||
class File: | ||
""" | ||
Base class for all files in a package. | ||
""" | ||
|
||
@classmethod | ||
def get_file_matching_extension(cls, dir: str, filename: str, extensions: list[str]) -> "File": | ||
""" | ||
Get the file with the given filename and one of the given extensions. | ||
:param dir: The directory to search in. | ||
:param filename: The filename. | ||
:param extensions: The extensions. | ||
:return: The file object. | ||
""" | ||
for ext in extensions: | ||
path = os.path.join(dir, filename + ext) | ||
if os.path.exists(path): | ||
return cls(path) | ||
raise FileNotFoundError | ||
|
||
def __init__(self, path: str): | ||
if not os.path.exists(path): | ||
raise FileNotFoundError | ||
self.path = path | ||
self.filename = os.path.basename(path) | ||
|
||
def __str__(self): | ||
return f"<{self.__class__.__name__} {self.path}>" | ||
|
||
def read(self) -> str: | ||
with open(self.path, "r") as f: | ||
return f.read() | ||
raise NotImplementedError() | ||
|
||
def write(self, text: str): | ||
with open(self.path, "w") as f: | ||
f.write(text) | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from sio3pack.graph import Graph | ||
from sio3pack.graph.graph import Graph | ||
from sio3pack.graph.graph_manager import GraphManager | ||
from sio3pack.graph.graph_op import GraphOperation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import json | ||
|
||
from sio3pack import File | ||
from sio3pack.files import File | ||
from sio3pack.graph.graph import Graph | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
class UnknownPackageType(Exception): | ||
pass | ||
def __init__(self, path: str) -> None: | ||
self.path = path | ||
super().__init__(f"Unknown package type for file {path}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from sio3pack.test import Test | ||
from sio3pack.test.test import Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.