1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 12:53:00 +00:00
kiwi-scp/src/kiwi/projects.py

84 lines
1.9 KiB
Python
Raw Normal View History

2020-08-19 15:22:40 +00:00
import os
from kiwi.project import Project
class Projects:
__projects = None
def __getitem__(self, item):
return self.__projects[item]
def __str__(self):
return str([
project.get_name()
for project
in self.__projects
])
@classmethod
def from_names(cls, project_names):
result = cls()
result.__projects = [
Project(name)
for name in project_names if isinstance(name, str)
]
return result
@classmethod
def from_projects(cls, projects):
result = cls()
result.__projects = [
project
for project in projects if isinstance(project, Project)
]
return result
@classmethod
def from_dir(cls):
return cls.from_projects([
Project.from_file_name(file_name)
for file_name in os.listdir()
])
@classmethod
def from_args(cls, args):
if args is not None and 'projects' in args:
if isinstance(args.projects, list) and args.projects:
return cls.from_names(args.projects)
elif isinstance(args.projects, str):
return cls.from_names([args.projects])
return cls()
def empty(self):
return not self.__projects
def filter_exists(self):
result = Projects()
result.__projects = [
project
for project in self.__projects
if project.exists()
]
return result
def filter_enabled(self):
result = Projects()
result.__projects = [
project
for project in self.__projects
if project.is_enabled()
]
return result
def filter_disabled(self):
result = Projects()
result.__projects = [
project
for project in self.__projects
if project.is_disabled()
]
return result