forked from hyde/hyde-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hyde.py
executable file
·105 lines (86 loc) · 3.87 KB
/
hyde.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
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
import os
import sys
import threading
from optparse import OptionParser
from hydeengine import Generator, Initializer, Server
#import cProfile
PROG_ROOT = os.path.dirname(os.path.realpath( __file__ ))
def main(argv):
parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 0.4")
parser.add_option("-s", "--sitepath",
dest = "site_path",
help = "Change the path of the site folder.")
parser.add_option("-i", "--init", action = 'store_true',
dest = "init", default = False,
help = "Create a new hyde site.")
parser.add_option("-f", "--force", action = 'store_true',
dest = "force_init", default = False, help = "")
parser.add_option("-t", "--template",
dest = "template",
help = "Choose which template you want to use.")
parser.add_option("-g", "--generate", action = "store_true",
dest = "generate", default = False,
help = "Generate the source for your hyde site.")
parser.add_option("-k", "--keep_watching", action = "store_true",
dest = "keep_watching", default = False,
help = "Start monitoring the source folder for changes.")
parser.add_option("-d", "--deploy_to",
dest = "deploy_to",
help = "Change the path of the deploy folder.")
parser.add_option("-w", "--webserve", action = "store_true",
dest = "webserve", default = False,
help = "Start an instance of the CherryPy webserver.")
parser.add_option("-p", "--port",
dest = "port", default=8080,
type='int',
help = "Port webserver should listen on (8080).")
parser.add_option("-a", "--address",
dest = "address", default='localhost',
help = "Address webserver should listen on (localhost).")
(options, args) = parser.parse_args()
if len(args):
parser.error("Unexpected arguments encountered.")
if not options.site_path:
options.site_path = os.getcwdu()
if options.deploy_to:
options.deploy_to = os.path.abspath(options.deploy_to)
if options.init:
initializer = Initializer(options.site_path)
initializer.initialize(PROG_ROOT,
options.template, options.force_init)
generator = None
server = None
def quit(*args, **kwargs):
if server and server.alive:
server.quit()
if generator:
generator.quit()
if options.generate:
generator = Generator(options.site_path)
generator.generate(options.deploy_to, options.keep_watching, quit)
if options.webserve:
server = Server(options.site_path, address=options.address, port=options.port)
server.serve(options.deploy_to, quit)
if ((options.generate and options.keep_watching)
or
options.webserve):
try:
print "Letting the server and/or the generator do their thing..."
if server:
server.block()
if generator:
generator.quit()
elif generator:
generator.block()
except:
print sys.exc_info()
quit()
if argv == []:
print parser.format_option_help()
if __name__ == "__main__":
main(sys.argv[1:])
# cProfile.run('main(sys.argv[1:])', filename='hyde.cprof')
# import pstats
# stats = pstats.Stats('hyde.cprof')
# stats.strip_dirs().sort_stats('time').print_stats(20)