"""
“Copyright 2021 Hangar.org”
This file is part of 3D-tester.
3D-tester is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
"""
import os, sys
from pathlib import Path
from bottle import route, run, error, abort, template, response, static_file
from utils import utils
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
OBJECT_DIR = os.path.join(BASE_DIR, 'objects')
@route('/static/', name='static')
def serve_static(filename):
return static_file(filename, root=os.path.join(BASE_DIR, 'static'))
@route('/vendor/', name='static')
def serve_static(filename):
return static_file(filename, root=os.path.join(BASE_DIR, 'vendor'))
@route('/objects/', name='static')
def serve_static(filename):
return static_file(filename, root=os.path.join(BASE_DIR, 'objects'))
@route('/')
@route('/list')
@route('/list/')
def index():
content = utils.get_directory_content(OBJECT_DIR)
return template('list-dir',
parent_dir="",
current_dir="",
content=content)
@route('/list/')
def list_dir(dir_path):
print("list path: ",dir_path)
#dir_path = dir_path.replace('/list/', '')
parts = dir_path.split('/')
print("list path: ",dir_path)
current_dir=os.path.join(OBJECT_DIR, *parts)
content = utils.get_directory_content(current_dir)
parts.pop()
parent_dir='/'.join(parts) if parts else ""
return template('list-dir',
parent_dir=parent_dir,
current_dir=dir_path.rstrip('/'),
content=content)
@route('/render/')
def render(file_path):
file_path = file_path.replace('/render/', '')
print(file_path)
current_path=os.path.join(OBJECT_DIR, file_path)
file = Path(current_path)
model_type = (Path(file.name).suffix).lstrip('.').lower()
current_dir=file_path.replace(file.name, '')
current_dir = current_dir.rstrip('/')
object_url = f"/objects/{current_dir}/{file.name}"
return template('render',
current_dir=current_dir,
name=file.name,
object_url=object_url,
model_type=model_type,
)
run(host='localhost', port=8080, debug=True)