Adding Auto shutdown functionality

pull/135/head
Torrin Leonard 2022-06-18 14:21:25 -04:00
rodzic 472d942b9f
commit f32f2baf3c
2 zmienionych plików z 71 dodań i 3 usunięć

Wyświetl plik

@ -23,6 +23,7 @@ import os
import sys
import json
import importlib
from datetime import datetime, timezone
# "a little hacky bs" - Matthew TheBrochacho ;)
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
@ -70,6 +71,7 @@ if "bpy" in locals():
# Used for updating text and buttons in UI panels
combinations: int = 0
recommended_limit: int = 0
dt = datetime.now(timezone.utc).astimezone() # Date Time in UTC local
@persistent
@ -376,7 +378,15 @@ class BMNFTS_PGT_Input_Properties(bpy.types.PropertyGroup):
)
# Other Panel:
enableAutoSave: bpy.props.BoolProperty(name="Auto Save Before Generation")
enableAutoSave: bpy.props.BoolProperty(name="Auto Save Before Generation", description="Automatically saves your Blender file when 'Generate NFTs & Create Metadata' button is clicked")
# Auto Shutodwn:
enableAutoShutdown: bpy.props.BoolProperty(name="Auto Shutdown", description="Automatically shuts down your computer after a Batch is finished Generating")
specify_timeBool: bpy.props.BoolProperty(name="Shutdown in a Given Amount of Time", description="Wait a given amount of time after a Batch is generated before Automatic Shutdown")
hours: bpy.props.IntProperty(default=0, min=0)
minutes: bpy.props.IntProperty(default=0, min=0)
# API Panel properties:
@ -516,6 +526,12 @@ class exportNFTs(bpy.types.Operator):
enableMaterials = bpy.context.scene.input_tool.enableMaterials
materialsFile = bpy.path.abspath(bpy.context.scene.input_tool.materialsFile)
enableAutoShutdown = bpy.context.scene.input_tool.enableAutoShutdown
specify_timeBool = bpy.context.scene.input_tool.specify_timeBool
hours = bpy.context.scene.input_tool.hours
minutes = bpy.context.scene.input_tool.minutes
# fail state variables, set to no fail due to resume_failed_batch() Operator in BMNFTS_PT_GenerateNFTs Panel
fail_state = False
failed_batch = None
@ -941,6 +957,30 @@ class BMNFTS_PT_Other(bpy.types.Panel):
row = layout.row()
row.prop(input_tool_scene, "enableAutoSave")
# Auto Shutdown:
row = layout.row()
row.prop(input_tool_scene, "enableAutoShutdown")
row.label(text="*Must Run Blender as Admin")
if bpy.context.scene.input_tool.enableAutoShutdown:
row = layout.row()
row.prop(input_tool_scene, "specify_timeBool")
time_row1 = layout.row()
time_row1.label(text=f"Hours")
time_row1.prop(input_tool_scene, "hours", text="")
time_row2 = layout.row()
time_row2.label(text=f"Minutes")
time_row2.prop(input_tool_scene, "minutes", text="")
if not bpy.context.scene.input_tool.specify_timeBool:
time_row1.enabled = False
time_row2.enabled = False
else:
time_row1.enabled = True
time_row2.enabled = True
layout.label(text=f"Running Blend_My_NFTs Headless:")
save_path = bpy.path.abspath(bpy.context.scene.input_tool.save_path)

Wyświetl plik

@ -7,6 +7,7 @@ import os
import time
import json
import datetime
import platform
from .loading_animation import Loader
from .Constants import bcolors, removeList, remove_file_by_extension
from .Metadata import createCardanoMetadata, createSolanaMetaData, createErc721MetaData
@ -112,18 +113,20 @@ def render_and_save_NFTs(input):
Renders the NFT DNA in a Batch#.json, where # is renderBatch in config.py. Turns off the viewport camera and
the render camera for all items in hierarchy.
"""
print(f"\nFAILED BATCH = {input.failed_batch}\n")
print(f"\nBATCH TO GENERATE = {input.batchToGenerate}\n")
time_start_1 = time.time()
# If failed Batch is detected and user is resuming its generation:
if input.fail_state:
print(f"{bcolors.ERROR}\nResuming Failed Batch {input.failed_batch}\n{bcolors.RESET}")
NFTs_in_Batch, hierarchy, BatchDNAList = getBatchData(input.failed_batch, input.batch_json_save_path)
for a in range(input.failed_dna):
del BatchDNAList[0]
x = input.failed_dna + 1
# If user is generating the normal way:
else:
print(f"\nGenerating Batch {input.batchToGenerate}\n")
NFTs_in_Batch, hierarchy, BatchDNAList = getBatchData(input.batchToGenerate, input.batch_json_save_path)
save_generation_state(input)
x = 1
@ -459,3 +462,28 @@ def render_and_save_NFTs(input):
batch_infoFolder = os.path.join(input.nftBatch_save_path, "Batch" + str(input.batchToGenerate), "batch_info.json")
save_batch(batch_info, batch_infoFolder)
# Automatic Shutdown:
# If user selects automatic shutdown but did not specify time after Batch completion
def shutdown(time):
plateform = platform.system()
if plateform == "Windows":
os.system(f"shutdown /s /t {time}")
if plateform == "Darwin":
os.system(f"shutdown /s /t {time}")
if input.enableAutoShutdown and not input.specify_timeBool:
shutdown(0)
# If user selects automatic shutdown and specify time after Batch completion
if input.enableAutoShutdown and input.specify_timeBool:
hours = (int(input.hours)/60)/60
minutes = int(input.minutes)/60
total_sleep_time = hours + minutes
# time.sleep(total_sleep_time)
shutdown(total_sleep_time)