Skip to content

Commit 0b4d6e0

Browse files
authored
Merge pull request #4163 from ferdnyc/test-intersect
Some query class / unit tests fixes and enhancements
2 parents dd25437 + f5b978f commit 0b4d6e0

File tree

2 files changed

+103
-111
lines changed

2 files changed

+103
-111
lines changed

src/classes/query.py

+17-26
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
from classes.app import get_app
3333

3434

35-
# Get project data reference
36-
app = get_app()
37-
project = app.project
38-
39-
4035
class QueryObject:
4136
""" This class allows one or more project data objects to be queried """
4237

@@ -56,7 +51,7 @@ def save(self, OBJECT_TYPE):
5651
if not self.id and self.type == "insert":
5752

5853
# Insert record, and Generate id
59-
self.id = project.generate_id()
54+
self.id = get_app().project.generate_id()
6055

6156
# save id in data (if attribute found)
6257
self.data["id"] = copy.deepcopy(self.id)
@@ -67,23 +62,23 @@ def save(self, OBJECT_TYPE):
6762
self.key.append({"id": self.id})
6863

6964
# Insert into project data
70-
app.updates.insert(copy.deepcopy(OBJECT_TYPE.object_key), copy.deepcopy(self.data))
65+
get_app().updates.insert(copy.deepcopy(OBJECT_TYPE.object_key), copy.deepcopy(self.data))
7166

7267
# Mark record as 'update' now... so another call to this method won't insert it again
7368
self.type = "update"
7469

7570
elif self.id and self.type == "update":
7671

7772
# Update existing project data
78-
app.updates.update(self.key, self.data)
73+
get_app().updates.update(self.key, self.data)
7974

8075
def delete(self, OBJECT_TYPE):
8176
""" Delete the object from the project data store """
8277

8378
# Delete if object found and not pending insert
8479
if self.id and self.type == "update":
8580
# Delete from project data store
86-
app.updates.delete(self.key)
81+
get_app().updates.delete(self.key)
8782
self.type = "delete"
8883

8984
def title(self):
@@ -95,7 +90,7 @@ def filter(OBJECT_TYPE, **kwargs):
9590
""" Take any arguments given as filters, and find a list of matching objects """
9691

9792
# Get a list of all objects of this type
98-
parent = project.get(OBJECT_TYPE.object_key)
93+
parent = get_app().project.get(OBJECT_TYPE.object_key)
9994

10095
if not parent:
10196
return []
@@ -242,30 +237,25 @@ def get(**kwargs):
242237
def absolute_path(self):
243238
""" Get absolute file path of file """
244239

245-
# Get project folder (if any)
246-
project_folder = None
247-
if project.current_filepath:
248-
project_folder = os.path.dirname(project.current_filepath)
249-
250-
# Convert relative file path into absolute (if needed)
251240
file_path = self.data["path"]
252-
if not os.path.isabs(file_path) and project_folder:
253-
file_path = os.path.abspath(os.path.join(project_folder, self.data["path"]))
241+
if os.path.isabs(file_path):
242+
return file_path
243+
244+
# Try to expand path relative to project folder
245+
app = get_app()
246+
if (app and hasattr("project", app)
247+
and hasattr("current_filepath", app.project)):
248+
project_folder = os.path.dirname(app.project.current_filepath)
249+
file_path = os.path.abspath(os.path.join(project_folder, file_path))
254250

255-
# Return absolute path of file
256251
return file_path
257252

258253
def relative_path(self):
259254
""" Get relative path (based on the current working directory) """
260255

261-
# Get absolute file path
262256
file_path = self.absolute_path()
263-
264257
# Convert path to relative (based on current working directory of Python)
265-
file_path = os.path.relpath(file_path, info.CWD)
266-
267-
# Return relative path
268-
return file_path
258+
return os.path.relpath(file_path, info.CWD)
269259

270260

271261
class Marker(QueryObject):
@@ -317,6 +307,7 @@ def __lt__(self, other):
317307
def __gt__(self, other):
318308
return self.data.get('number', 0) > other.data.get('number', 0)
319309

310+
320311
class Effect(QueryObject):
321312
""" This class allows Effects to be queried, updated, and deleted from the project data. """
322313
object_name = "effects" # Derived classes should define this
@@ -334,7 +325,7 @@ def filter(**kwargs):
334325
""" Take any arguments given as filters, and find a list of matching objects """
335326

336327
# Get a list of clips
337-
clips = project.get("clips")
328+
clips = get_app().project.get("clips")
338329
matching_objects = []
339330

340331
# Loop through all clips

0 commit comments

Comments
 (0)