Work
This commit is contained in:
59
storage/project_storage.py
Normal file
59
storage/project_storage.py
Normal file
@ -0,0 +1,59 @@
|
||||
import os
|
||||
import json
|
||||
from typing import Iterable
|
||||
from model import Project, ProjectItem, ItemType
|
||||
from properties import config
|
||||
|
||||
def loadProject(self, projFilePath) -> Project:
|
||||
p = Project(projFilePath, self)
|
||||
p.rootDir = os.path.dirname(projFilePath)
|
||||
|
||||
|
||||
def saveProject(self, project : Project):
|
||||
pass
|
||||
|
||||
"""
|
||||
Determines the type of the project item.
|
||||
"""
|
||||
def getItemType(self, projectItem : ProjectItem) -> ItemType:
|
||||
path = projectItem.absolutePath()
|
||||
|
||||
if os.path.isdir(path):
|
||||
return ItemType.DIRECTORY
|
||||
|
||||
elif os.path.isfile(path):
|
||||
_, ext = os.path.splitext(path)
|
||||
ext = ext.lower().lstrip('.') # remove leading .
|
||||
|
||||
if ext == config.PROJECT_EXTENSION:
|
||||
return ItemType.PROJECT
|
||||
|
||||
elif ext == config.SEQUENCE_EXTENSION:
|
||||
return ItemType.SEQUENCE
|
||||
|
||||
elif ext == config.COMPOSITION_EXTENSION:
|
||||
return ItemType.COMPOSITION
|
||||
|
||||
elif ext in config.DEBUG_SUPPORTED_AUDIO:
|
||||
return ItemType.AUDIO
|
||||
|
||||
elif ext in config.DEBUG_SUPPORTED_VIDEO:
|
||||
return ItemType.VIDEO
|
||||
|
||||
elif ext in config.DEBUG_SUPPORTED_IMAGE:
|
||||
return ItemType.IMAGE
|
||||
|
||||
elif ext in config.DEBUG_SUPPORTED_SUB:
|
||||
return ItemType.SUBTITLES
|
||||
|
||||
return ItemType.UNKNOWN
|
||||
|
||||
|
||||
def getItemChildren(self, projectItem : ProjectItem) -> Iterable[ProjectItem]:
|
||||
if projectItem.itemType() == ItemType.DIRECTORY:
|
||||
for item in os.listdir(projectItem.absolutePath()):
|
||||
yield ProjectItem(item, projectItem.project, self, projectItem)
|
||||
|
||||
def getProjectItems(self, project : Project) -> Iterable[ProjectItem]:
|
||||
for item in os.listdir(project.rootDir):
|
||||
yield ProjectItem(item, project, self, None)
|
Reference in New Issue
Block a user