Burathar
4 years ago
8 changed files with 86 additions and 64 deletions
@ -1 +1,3 @@ |
|||||||
from .project import Project |
from .project import Project |
||||||
|
from .user import User |
||||||
|
from .yaml_serializable import YamlSerializable |
||||||
|
@ -1,63 +1,16 @@ |
|||||||
from pathlib import Path |
from pathlib import Path |
||||||
import yaml |
|
||||||
from biscd import config |
from biscd import config |
||||||
|
from .yaml_serializable import YamlSerializable |
||||||
|
|
||||||
class Project: |
class Project(YamlSerializable): |
||||||
_storage_file = Path(config.config_dir()) / 'projects.yaml' |
|
||||||
|
|
||||||
storage = {} |
|
||||||
|
|
||||||
def __init__(self, name, branche='master'): |
|
||||||
self.name = name |
|
||||||
self.branche = branche |
|
||||||
|
|
||||||
@property |
@property |
||||||
def config_dict(self): |
def _storage_file(self): |
||||||
project_dict = self.__dict__.copy() |
return Path(config.config_dir()) / 'projects.yaml' |
||||||
project_dict.pop('name') |
|
||||||
return {self.name: project_dict} |
|
||||||
|
|
||||||
def save(self): |
|
||||||
projects = self._get_projects_from_file() |
|
||||||
if self.name in ([*project][0] for project in projects): |
|
||||||
projects[self.name] = self.config_dict |
|
||||||
else: |
|
||||||
projects.append(self.config_dict) |
|
||||||
print(projects) |
|
||||||
self._save_projects_to_file(projects) |
|
||||||
|
|
||||||
@classmethod |
@property |
||||||
def get(cls, name): |
def _yaml_object_name(self): |
||||||
project_dict = next(project for project in cls._get_projects_from_file() if [*project][0] == name) |
return 'projects' |
||||||
if project_dict is None: |
|
||||||
return None |
|
||||||
project_name = [*project_dict][0] |
|
||||||
project_dict = project_dict.get(project_name) |
|
||||||
|
|
||||||
project_dict['name'] = project_name |
|
||||||
|
|
||||||
project = cls('placeholder') |
|
||||||
project.__dict__ = project_dict |
|
||||||
return project |
|
||||||
|
|
||||||
|
|
||||||
@classmethod |
|
||||||
def list(cls): |
|
||||||
projects = cls._get_projects_from_file() |
|
||||||
project_list = [] |
|
||||||
for project in projects: |
|
||||||
name = [*project][0] |
|
||||||
project_list.append(name) |
|
||||||
return project_list |
|
||||||
|
|
||||||
@classmethod |
|
||||||
def _get_projects_from_file(cls): |
|
||||||
with open(cls._storage_file) as file: |
|
||||||
projects = yaml.load(file, yaml.FullLoader).get('projects') |
|
||||||
return projects |
|
||||||
|
|
||||||
@classmethod |
def __init__(self, name=None, branche='master'): |
||||||
def _save_projects_to_file(cls, projects): |
self.name = name |
||||||
projects_object = {'projects' : projects} |
self.branche = branche |
||||||
with open(cls._storage_file, 'w') as file: |
|
||||||
yaml.dump(projects_object, file) |
|
Loading…
Reference in new issue