-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add constants and clear asset operator
- Loading branch information
Showing
9 changed files
with
178 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
from os import path | ||
from typing import cast | ||
|
||
import bpy | ||
from dotenv import load_dotenv | ||
|
||
|
||
def remove_wrapped_slash(path: str) -> str: | ||
if path.startswith("/"): | ||
return path[1:] | ||
return path | ||
|
||
|
||
class Constants: | ||
def __init__(self): | ||
pass | ||
|
||
def initialize(self): | ||
""" | ||
Dotenv | ||
""" | ||
current_dir = path.dirname(path.realpath(__file__)) | ||
root_dir = path.dirname(path.dirname(current_dir)) | ||
dotenv_path = path.join(root_dir, ".env") | ||
load_dotenv(dotenv_path=dotenv_path) | ||
|
||
SERVER_URL = os.getenv("SERVER_URL") | ||
if SERVER_URL is None: | ||
raise Exception("SERVER_URL is not defined") | ||
self.SERVER_URL = remove_wrapped_slash(SERVER_URL) | ||
|
||
HTTP_PATH = os.getenv("HTTP_PATH") | ||
if HTTP_PATH is None: | ||
raise Exception("HTTP_PATH is not defined") | ||
self.HTTP_PATH = remove_wrapped_slash(HTTP_PATH) | ||
|
||
GRAPHQL_PATH = os.getenv("GRAPHQL_PATH") | ||
if GRAPHQL_PATH is None: | ||
raise Exception("GRAPHQL_PATH is not defined") | ||
self.GRAPHQL_PATH = remove_wrapped_slash(GRAPHQL_PATH) | ||
|
||
GRAPHQL_WS_PATH = os.getenv("GRAPHQL_WS_PATH") | ||
if GRAPHQL_WS_PATH is None: | ||
raise Exception("GRAPHQL_WS_PATH is not defined") | ||
self.GRAPHQL_WS_PATH = remove_wrapped_slash(GRAPHQL_WS_PATH) | ||
|
||
FILE_SERVER_URL = os.getenv("FILE_SERVER_URL") | ||
if FILE_SERVER_URL is None: | ||
raise Exception("FILE_SERVER_URL is not defined") | ||
self.FILE_SERVER_URL = remove_wrapped_slash(FILE_SERVER_URL) | ||
|
||
""" | ||
Assets | ||
""" | ||
library_path = cast( | ||
str, bpy.context.preferences.filepaths.asset_libraries["User Library"].path | ||
) | ||
self.ASSET_PATH = os.path.join(library_path, "LightDance") | ||
|
||
|
||
constants = Constants() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
|
||
import bpy | ||
|
||
from ...core.constants import constants | ||
from ...core.utils.notification import notify | ||
|
||
|
||
def remove_dir_files(dir_path: str): | ||
for content in os.listdir(dir_path): | ||
content_path = os.path.join(dir_path, content) | ||
if os.path.isdir(content_path): | ||
remove_dir_files(content_path) | ||
else: | ||
os.remove(content_path) | ||
|
||
|
||
class ClearAssets(bpy.types.Operator): | ||
bl_idname = "lightdance.clear_assets" | ||
bl_label = "Clear Assets" | ||
bl_options = {"REGISTER", "UNDO"} | ||
|
||
confirm: bpy.props.BoolProperty( # type: ignore | ||
name="I know what I am doing", | ||
default=False, | ||
) | ||
|
||
def execute(self, context: bpy.types.Context): | ||
confirm: bool = getattr(self, "confirm") | ||
|
||
if not confirm: | ||
notify("ERROR", "Cancelled") | ||
return {"CANCELLED"} | ||
|
||
remove_dir_files(constants.ASSET_PATH) | ||
notify("INFO", "Assets cleared") | ||
|
||
return {"FINISHED"} | ||
|
||
def invoke(self, context: bpy.types.Context, event: bpy.types.Event): | ||
return context.window_manager.invoke_props_dialog(self) | ||
|
||
|
||
def register(): | ||
bpy.utils.register_class(ClearAssets) | ||
|
||
|
||
def unregister(): | ||
bpy.utils.unregister_class(ClearAssets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters