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.
29 lines
750 B
Python
29 lines
750 B
Python
from .home import Home
|
|
from .linker import LinkFiles
|
|
from .cargo import CargoInstall
|
|
from .run import Run
|
|
|
|
class Resource:
|
|
resource_types = [Home, LinkFiles, CargoInstall, Run]
|
|
|
|
@classmethod
|
|
def from_name(cls, name):
|
|
"""
|
|
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, section):
|
|
parts = name.split(' ')
|
|
name = parts[0]
|
|
try:
|
|
label = parts[1]
|
|
except IndexError:
|
|
label = None
|
|
T = cls.from_name(name)
|
|
return T(label, section)
|