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