Skip to content

Commit a1ccecd

Browse files
committed
Moved existing files into static-files, added vendor dir, manage.py, and wsgi script for updating on post-commit.
1 parent 2049606 commit a1ccecd

File tree

182 files changed

+104
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+104
-4
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor"]
2+
path = vendor
3+
url = git://github.com/toolness/hackasaurus-lib.git

README.md

+10-1

manage.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
import os
3+
from wsgiref.util import shift_path_info
4+
5+
ROOT = os.path.dirname(os.path.abspath(__file__))
6+
7+
def path(*a):
8+
return os.path.join(ROOT, *a)
9+
10+
sys.path.insert(0, path('wsgi-scripts'))
11+
sys.path.insert(0, path('vendor'))
12+
13+
import hackbook_dot_hackasaurus_dot_org
14+
import jinja2
15+
from hackasaurus.management import execute_manager
16+
from hackasaurus.lamp_emulation import load_php
17+
18+
static_files_dir = path('static-files')
19+
20+
def handle_html_file_as_jinja2_template(root_dir, fullpath):
21+
loader = jinja2.FileSystemLoader(root_dir, encoding='utf-8')
22+
env = jinja2.Environment(loader=loader)
23+
template = env.get_template(fullpath[len(root_dir):])
24+
return ('text/html', template.render().encode('utf-8'))
25+
26+
def handle_php_file(root_dir, fullpath):
27+
return ('text/html', load_php(root_dir, fullpath))
28+
29+
def wsgi_api_handler(env, start):
30+
if env['PATH_INFO'].startswith('/wsgi/'):
31+
shift_path_info(env)
32+
return hackbook_dot_hackasaurus_dot_org.application(env, start)
33+
34+
if __name__ == '__main__':
35+
execute_manager(
36+
build_dir=path('build'),
37+
static_files_dir=static_files_dir,
38+
ext_handlers={
39+
'.html': handle_html_file_as_jinja2_template,
40+
'.php': handle_php_file
41+
},
42+
handlers=[wsgi_api_handler],
43+
default_filenames=['index.html', 'index.php'],
44+
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

include/header.php renamed to static-files/include/header.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
</ul>
3535
</nav>
3636
37-
<?php /*<div class="colour">
37+
<!-- <div class="colour">
3838
<ul>
3939
<li class="red">Red</li>
40-
<!--<li class="orange">Orange</li>-->
40+
<li class="orange">Orange</li>
4141
<li class="yellow">Yellow</li>
4242
<li class="green">Green</li>
4343
<li class="blue">Blue</li>
4444
<li class="purple">Purple</li>
4545
<li class="pink">Pink</li>
4646
<li class="grey">Grey</li>
4747
</ul>
48-
</div> */ ?>
48+
</div> -->
4949
5050
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

vendor

Submodule vendor added at 1b41a5e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
import subprocess
4+
5+
ROOT = os.path.abspath(os.path.dirname(__file__))
6+
path = lambda *x: os.path.join(ROOT, *x)
7+
8+
endpoints = {}
9+
10+
def expose(endpoint):
11+
def decorator_maker(func):
12+
endpoints[endpoint] = func
13+
return func
14+
return decorator_maker
15+
16+
def application(env, start):
17+
if env['PATH_INFO'] in endpoints:
18+
return endpoints[env['PATH_INFO']](env, start)
19+
return error_404(env, start)
20+
21+
def error(env, start, status, message=None):
22+
if not message:
23+
message = status
24+
response_headers = [('Content-type', 'text/plain'),
25+
('Content-Length', str(len(message)))]
26+
start(status, response_headers)
27+
return [message]
28+
29+
def error_404(env, start):
30+
return error(env, start, '404 Not Found',
31+
'Not Found: %s' % env['PATH_INFO'])
32+
33+
@expose('/update-site')
34+
def update_site(env, start):
35+
retvals = []
36+
for cmds in [['pull'], ['submodule', 'init'], ['submodule', 'update']]:
37+
retvals.append(subprocess.call(['git'] + cmds, cwd=path('..')))
38+
status = '200 OK'
39+
output = str(retvals)
40+
response_headers = [('Content-type', 'text/plain'),
41+
('Content-Length', str(len(output)))]
42+
start(status, response_headers)
43+
return [output]

0 commit comments

Comments
 (0)