-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversion_utils.py
More file actions
39 lines (33 loc) · 1.31 KB
/
version_utils.py
File metadata and controls
39 lines (33 loc) · 1.31 KB
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
# Utility functions for version discovery
import os
from datetime import datetime
from .preferences_utils import get_addon_preferences
def find_versions(filepath):
"""
Returns a list of (name, name, '') tuples for each subdirectory in filepath.
"""
prefs = get_addon_preferences()
debug = getattr(prefs, "debug", False)
version_list = []
if debug:
start_time = datetime.now()
print(f"DEBUG: find_versions START for path: {filepath}")
if not filepath or not os.path.isdir(filepath):
if debug:
print(f"DEBUG: find_versions: filepath invalid or not a directory: {filepath}")
return version_list
try:
entries = os.listdir(filepath)
for entry in entries:
path = os.path.join(filepath, entry)
if os.path.isdir(path):
version_list.append((entry, entry, ''))
if debug:
print(f"DEBUG: find_versions found {len(version_list)} versions in '{filepath}'. List: {version_list}")
except OSError as e:
if debug:
print(f"DEBUG: find_versions: Error accessing filepath {filepath}: {e}")
if debug:
elapsed = (datetime.now() - start_time).total_seconds()
print(f"DEBUG: (took: {elapsed:.6f}s) find_versions END for path: '{filepath}'")
return version_list