/
frontendInterface.py
39 lines (29 loc) · 1.25 KB
/
frontendInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import copy
import bcf.writer as w
import bcf.project as p
from interfaces.identifiable import Identifiable
from interfaces.hierarchy import Hierarchy
from interfaces.state import State
def deleteObject(project, object):
if not issubclass(type(object), Identifiable):
raise ValueError("Cannot delete {} since it doesn't inherit from"\
" interfaces.Identifiable".format(object))
if not issubclass(type(object), Hierarchy):
raise ValueError("Cannot delete {} since it seems to be not part of" \
" the data model. It has to inherit from"\
" hierarchy.Hierarchy".format(object))
# find out the name of the object in its parent
object.state = State.States.DELETED
projectCpy = copy.deepcopy(project)
newObject = projectCpy.searchObject(object)
w.addUpdate(projectCpy, newObject, None)
result = w.processProjectUpdates()
# `result == None` if the update could not be processed.
# ==> `result == projectCpy` will be returned to stay on the errorenous
# state and give the user the chance to fix the issue.
if result is not None:
return result[0]
# otherwise the updated project is returned
else:
project.deleteObject(object)
return project