forked from HorriblePeople/CardMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOS_Helper.py
41 lines (36 loc) · 1.25 KB
/
OS_Helper.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
'''
OS Helpers
'''
import os, glob
import PIL_Helper
def Delete(filename):
filelist = glob.glob(filename)
for f in filelist:
os.remove(f)
def CleanDirectory(path=".", mkdir="workspace", rmstring="*.*"):
dir_path = os.path.join(path, mkdir)
if not os.path.exists(dir_path):
os.mkdir(dir_path)
else:
Delete(os.path.join(dir_path, rmstring))
return dir_path
def BuildPage(card_list, page_num, page_width, page_height,
workspace_path):
PIL_Helper.BuildPage(card_list, page_width, page_height,
os.path.join(
workspace_path,
"page_{0:>03}.png".format(page_num)
)
)
def BuildBack(card_list, page_num, page_width, page_height,
workspace_path):
back_list=[]
for i in range(0,page_height):
for j in range(1,page_width+1):
back_list.append(card_list[(i+1)*page_width-j])
PIL_Helper.BuildPage(back_list, page_width, page_height,
os.path.join(
workspace_path,
"backs_{0:>03}.png".format(page_num)
)
)