-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
executable file
·94 lines (75 loc) · 2.88 KB
/
generate.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# This application is a hack (For now)
# All I want it to accomplish is to generate a static version
# of ArthikTangi.com (literally translates to, 'Financial Strain')
__version__ = "0.0.1"
import os
import sys
import time
import shutil
from readers import csvreader
from writers import staticwriter
from writers import defaultwriter
from settings import get_settings
class Comatic:
def __init__(self, settings):
"""
Do some initialization stuff here
"""
self.output_path = settings['OUTPUT_PATH']
self.settings = settings
self.output_root = os.path.abspath(os.path.expanduser(self.settings['OUTPUT_PATH']))
self.destpath = os.path.join(self.settings['OUTPUT_PATH'], 'static')
self.themepath = os.path.join( 'themes', self.settings['THEME'])
self.theme_staticpath = os.path.join(self.themepath, 'static')
self.theme_templatepath = os.path.join(self.themepath, 'templates')
self.dest_themepath = os.path.join(self.destpath, self.settings['THEME'])
def output_folder_ready(self, outdir):
"""
Ask to remove the output folder if it exists
"""
if os.path.isdir(outdir) is False:
return True
else:
response = raw_input('CAUTION! Read file path carefully.\nThe path "%s" already exists. Remove? (y/n)' % outdir)
if response is 'y' or response is 'Y':
#remove directory
shutil.rmtree(outdir)
return True
else:
return False
def init_path(self):
if not any(p in sys.path for p in ['', '.']):
sys.path.insert(0, '')
def copy_static_files(self):
if (self.output_folder_ready(self.output_root)):
for folder in self.settings['STATIC']:
staticwriter(os.path.abspath(os.path.expanduser(folder)),
os.path.abspath(os.path.expanduser(self.destpath)))
# Copying Theme files!
staticwriter(os.path.abspath(os.path.expanduser(self.theme_staticpath)),
os.path.abspath(os.path.expanduser(self.dest_themepath)))
else:
print "Copying static files failed"
# Read the comic details
def run(self):
"""
copy static files.
read comic csv.
write comics.
rejoice.
"""
# copying static files
self.copy_static_files()
#read comic CSV
comiclist = csvreader(os.path.abspath(os.path.expanduser(self.settings['COMIC_CSV'])))
#write comics!
defaultwriter(comiclist, self.theme_templatepath, self.output_root, self.settings)
print "Done"
def main():
settings = get_settings()
comatic = Comatic(settings)
comatic.init_path()
comatic.run()
if __name__ == "__main__":
main()