mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-21 20:33:00 +00:00
move Projects class
This commit is contained in:
parent
bf5bed8734
commit
e6f87277c6
5 changed files with 87 additions and 83 deletions
|
@ -127,83 +127,3 @@ class Project:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
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
|
|
||||||
|
|
83
src/kiwi/projects.py
Normal file
83
src/kiwi/projects.py
Normal file
|
@ -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
|
|
@ -4,7 +4,7 @@ import os
|
||||||
|
|
||||||
# local
|
# local
|
||||||
from .parser import Parser
|
from .parser import Parser
|
||||||
from .project import Projects
|
from .projects import Projects
|
||||||
|
|
||||||
|
|
||||||
class SubCommand:
|
class SubCommand:
|
||||||
|
|
|
@ -6,7 +6,7 @@ import subprocess
|
||||||
from .._constants import CONF_DIRECTORY_NAME
|
from .._constants import CONF_DIRECTORY_NAME
|
||||||
from ..subcommand import SubCommand
|
from ..subcommand import SubCommand
|
||||||
from ..config import LoadedConfig
|
from ..config import LoadedConfig
|
||||||
from ..project import Projects
|
from ..projects import Projects
|
||||||
from ..rootkit import Rootkit, prefix_path_mnt
|
from ..rootkit import Rootkit, prefix_path_mnt
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ import yaml
|
||||||
|
|
||||||
# local
|
# local
|
||||||
from ..subcommand import ServiceCommand
|
from ..subcommand import ServiceCommand
|
||||||
from ..project import Project, Projects
|
from ..project import Project
|
||||||
|
from ..projects import Projects
|
||||||
|
|
||||||
|
|
||||||
def _print_list(strings):
|
def _print_list(strings):
|
||||||
|
|
Loading…
Reference in a new issue