-
Notifications
You must be signed in to change notification settings - Fork 7
/
planeteria.py
executable file
·80 lines (67 loc) · 2.11 KB
/
planeteria.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
#!/usr/bin/env python
"""
Planeteria rewrite.
Copyright James Vasile 2011
Released under the GNU Affero General Public License, version 3 or later.
"""
"""
Back End
generates the various pages
Front End
admin to various pages
"""
import os, sys
from optparse import OptionParser
import config as cfg
from config import opt
import logging
log = logging.getLogger('planeteria')
from galaxy import Galaxy
from planet import Planet
try:
os.makedirs(opt['data_dir'])
except OSError:
pass
planets = []
def parse_options():
parser = OptionParser()
parser.add_option("", "--force", action="store_true", dest="force_update", help="force downloading of cached upstream feeds", default=False),
parser.add_option("", "--no-update", action="store_true", dest="no_update", help="prevent downloading of upstream feeds", default=False),
parser.add_option('', '--delete-missing', dest="delete_missing", help="delete planets from db if they are not in file system", action="store_true", default=False)
parser.add_option('', '--clean', dest="clean", help="remove missing planets, unused feeds", action="store_true", default=False)
(options, args) = parser.parse_args()
opt['force_check'] = options.force_update
opt['no_update'] = options.no_update
if len(args) >= 1:
global planets
planets.extend(args)
if options.clean:
log.debug("Cleaning databse.")
galaxy = Galaxy(planets)
galaxy.load()
galaxy.delete_missing_planets()
galaxy.delete_unused_feeds()
elif options.delete_missing:
log.debug("Deleting missing planets.")
galaxy = Galaxy(planets)
galaxy.load()
galaxy.delete_missing_planets()
else:
return True
return False
def main():
import templates
for p,t in {'about':templates.About,
'index':templates.Index,
}.items():
t(opt).write(cfg.OUTPUT_DIR, "%s.html" % p)
galaxy = Galaxy(planets)
galaxy.load()
print "Galaxies loaded"
if not opt['no_update']:
galaxy.update()
galaxy.generate()
if __name__ == "__main__":
if parse_options():
print "Options parsed."
main()