Changeset - 891c380afcc1
[Not reviewed]
default
1 1 2
drewp@bigasterisk.com - 20 months ago 2023-05-19 20:59:07
drewp@bigasterisk.com
move py code under light9, add import test
3 files changed with 25 insertions and 12 deletions:
0 comments (0 inline, 0 general)
bin/homepage
Show inline comments
 
@@ -4,7 +4,7 @@ CONF=/tmp/light9_nginx.conf
 
ROOT=`dirname $0`/..
 
ROOT=${ROOT:a}
 

	
 
bin/homepageConfig > /tmp/light9_nginx_routes.conf && \
 
bin/python light9/homepage/write_config.py /tmp/light9_nginx_routes.conf && \
 
cat > $CONF <<EOF
 
worker_processes 1;
 

	
 
@@ -32,7 +32,6 @@ http {
 
 }
 
}
 
EOF
 
head -1 /tmp/light9_nginx_routes.conf
 
pnpm vite -c light9/homepage/vite.config.ts &
 
/usr/sbin/nginx -c $CONF
 
wait
light9/homepage/write_config.py
Show inline comments
 
file renamed from bin/homepageConfig to light9/homepage/write_config.py
 
#!bin/python
 
from run_local import log
 
import sys
 
from urllib.parse import urlparse
 

	
 
from light9 import showconfig
 
from light9.namespaces import L9
 
from urllib.parse import urlparse
 
from light9.run_local import log
 

	
 

	
 
def main():
 
    [outPath] = sys.argv[1:]
 

	
 
log.info('generating config')
 
graph = showconfig.getGraph()
 

	
 
netHome = graph.value(showconfig.showUri(), L9['networking'])
 
webServer = graph.value(netHome, L9['webServer'])
 
if not webServer:
 
    raise ValueError('no %r :webServer' % netHome)
 
print("listen %s;" % urlparse(webServer).port)
 

	
 
    with open(outPath, 'wt') as out:
 
        line = "listen %s;" % urlparse(str(webServer)).port
 
        print(line, file=out)
 
        log.info(line)
 

	
 
def location(path, server, viteServer):
 
    print(f"""
 
@@ -41,16 +48,16 @@ def location(path, server, viteServer):
 
      proxy_pass {viteServer}; 
 
    }}
 

	
 
    """)
 

	
 
        """,
 
                  file=out)
 

	
 
for role, server in sorted(graph.predicate_objects(netHome)):
 
    if not server.startswith('http') or role == L9['webServer']:
 
            if not str(server).startswith('http') or role == L9['webServer']:
 
        continue
 
    path = graph.value(role, L9['urlPath'])
 
    if not path:
 
        continue
 
    server = server.rstrip('/')
 
            server = str(server).rstrip('/')
 
    viteServer = server.replace('82', '83') # rewrite this please
 
    location(path, server, viteServer)
 

	
 
@@ -59,4 +66,8 @@ root = showconfig.root()[:-len(showPath)
 
print(f"""
 
    location /{showPath} {{
 
      root {root};
 
    }}""")
 
        }}""", file=out)
 

	
 

	
 
if __name__ == '__main__':
 
    main()
 
\ No newline at end of file
light9/homepage/write_config_test.py
Show inline comments
 
new file 100644
 
def test_import():
 
    import write_config
 
    # no crash
0 comments (0 inline, 0 general)