This repository was archived by the owner on Sep 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__generate.py
More file actions
69 lines (62 loc) · 2.73 KB
/
Copy path__generate.py
File metadata and controls
69 lines (62 loc) · 2.73 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import PyStatGen as pst
import yaml
from os import path, walk
import argparse
def main():
prs = argparse.ArgumentParser(description='Generate the website anew.')
prs.add_argument('-c', '--conf', type=str,
default="example_configuration.yml", dest='conf_path',
help='Path to the configuration file.')
args = prs.parse_args()
# Load conf
conf = yaml.load(open(args.conf_path, 'r').read())
tp = conf.get("templates")
ta = conf.get("target")
sc = conf.get("source")
# Check for errors
(stop, error_message) = pst.test_match(conf)
if stop:
print(error_message)
# Tasks~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Folder structure tasks
default_tasks = list()
check_list = [ta, path.join(ta, "css"), path.join(ta, "fonts"),
path.join(ta, "css", "default-skin"),
path.join(ta, "img"), path.join(ta, "img", "full"),
path.join(ta, "img", "thumb"), path.join(ta, "js")]
for directory in check_list:
try:
pst.test_writability(directory)
except pst.FileError as e:
default_tasks.append(pst.Task.with_details(pst.FileTypes.directory,
pst.TaskTypes.generate,
{"path": e.path}))
# Default folder content tasks
for folder in ["css", "img", "fonts", "js"]:
for d in walk(path.join(tp, folder)):
for f in d[2]:
src = path.join(d[0], f)
dst = path.join(d[0].replace(tp, ta), f)
tk = pst.Task.with_details(pst.FileTypes.misc,
pst.TaskTypes.copy,
{"src": src, "dst": dst})
default_tasks.append(tk)
copy_info = {"src": path.join(sc, "background.jpg"),
"dst": path.join(ta, "img/background.jpg")}
default_tasks.append(pst.Task.with_details(pst.FileTypes.image,
pst.TaskTypes.copy,
copy_info))
copy_info = {"src": path.join(sc, "share.png"),
"dst": path.join(ta, "img/share.png")}
default_tasks.append(pst.Task.with_details(pst.FileTypes.image,
pst.TaskTypes.copy,
copy_info))
# Website content tasks
tasker = pst.Tasker(conf)
content = tasker.read_content()
# Generate website
old_content = []
tasker.build_tasks(content, old_content)
pst.process(conf, default_tasks + tasker.tasks)
if __name__ == "__main__":
main()