diff --git a/src/kiwi/project.py b/src/kiwi/project.py index 60e1beb..8b59149 100644 --- a/src/kiwi/project.py +++ b/src/kiwi/project.py @@ -127,83 +127,3 @@ class Project: return False return True - - -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 diff --git a/src/kiwi/projects.py b/src/kiwi/projects.py new file mode 100644 index 0000000..4459363 --- /dev/null +++ b/src/kiwi/projects.py @@ -0,0 +1,83 @@ +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 diff --git a/src/kiwi/subcommand.py b/src/kiwi/subcommand.py index 18b518a..59a64ee 100644 --- a/src/kiwi/subcommand.py +++ b/src/kiwi/subcommand.py @@ -4,7 +4,7 @@ import os # local from .parser import Parser -from .project import Projects +from .projects import Projects class SubCommand: diff --git a/src/kiwi/subcommands/conf.py b/src/kiwi/subcommands/conf.py index 77296fb..86a379e 100644 --- a/src/kiwi/subcommands/conf.py +++ b/src/kiwi/subcommands/conf.py @@ -6,7 +6,7 @@ import subprocess from .._constants import CONF_DIRECTORY_NAME from ..subcommand import SubCommand from ..config import LoadedConfig -from ..project import Projects +from ..projects import Projects from ..rootkit import Rootkit, prefix_path_mnt diff --git a/src/kiwi/subcommands/list.py b/src/kiwi/subcommands/list.py index 63e773d..cd75af8 100644 --- a/src/kiwi/subcommands/list.py +++ b/src/kiwi/subcommands/list.py @@ -5,7 +5,8 @@ import yaml # local from ..subcommand import ServiceCommand -from ..project import Project, Projects +from ..project import Project +from ..projects import Projects def _print_list(strings):