-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
op_empty_download_dir.py
52 lines (33 loc) · 1.32 KB
/
op_empty_download_dir.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
40
41
42
43
44
45
46
47
48
49
50
51
52
import bpy
import os
from .addon_prefs import get_addon_preferences
from .global_variables import manifest_file
from .print_functions import print_and_report
# empty directory
def empty_directory(self, filepath):
for f in os.listdir(filepath):
if f != manifest_file:
os.remove(os.path.join(filepath, f))
print_and_report(self, "Successfully emptied %s " % filepath, "INFO")
class ANTEMPLATES_OT_clear_downloads(bpy.types.Operator):
"""Clear existing templates"""
bl_idname = "antemplates.clear_downloads"
bl_label = "Clear Downloads"
bl_options = {'REGISTER', 'INTERNAL'}
@classmethod
def poll(cls, context):
return True
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
layout.label(text="You are about to delete downloaded templates", icon="QUESTION")
layout.label(text="Are you sure ?")
def execute(self, context):
prefs = get_addon_preferences()
download_folder = prefs.download_folder
if os.path.isdir(download_folder):
empty_directory(self, download_folder)
else:
print_and_report(self, "Download directory does not exist : %s" % download_folder, "WARNING")
return {'FINISHED'}