You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
908 B
Python

from configparser import SectionProxy
from .home import Home
from .linker import LinkFiles
from .cargo import CargoInstall
from .run import Run
from . import git
class Resource:
resource_types: list[type] = [
Home,
LinkFiles,
CargoInstall,
Run,
git.Repo,
]
@classmethod
def from_name(cls, name: str) -> type:
"""
from_name is to be implemented by resource classes
"""
for T in cls.resource_types:
if T.resource_name == name:
return T
raise ValueError(f"No section type has name {name}")
@classmethod
def from_section(cls, name: str, section: SectionProxy):
parts = name.split(" ")
name = parts[0]
try:
label = parts[1]
except IndexError:
label = None
T = cls.from_name(name)
return T(label, section)