Compare commits

..

No commits in common. "b39855cf70532f0b7cc73c9d80ffaf542073a442" and "05373a86fafd71ea5c30abf0cf512451f44e6554" have entirely different histories.

3 changed files with 51 additions and 54 deletions

12
.gitignore vendored
View File

@ -1,14 +1,6 @@
.venv
**/__pycache__
*.pyc
.DS_Store
nohup.out
.venv/
.beaker/data/*
!.beaker/data/.noremove
.gadogado
nohup.out

View File

@ -1,5 +1,5 @@
# CostaPy
a Python WSGI Web Framework. Build with Bottle and Mako.
Python Web Framework. Build with Bottle and Mako.
## License
@ -20,65 +20,69 @@ 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 https://www.gnu.org/licenses/.
# Getting Starter
## Requirement & Installation
## Requirement
### Clone the repository
You need a `git`, `python`, `pip`, and `venv` before using CostaPy.
Clone the repository with `--recursive` when cloning the repo.
Install them using the following commands on your `Debian` or `Ubuntu` system.
git clone https://gitea.ditaajipratama.net/aji/costapy.git --recursive
```bash
sudo apt update
sudo apt install git python3 python3-venv python3-pip
```
Note that if you forgot the `--recursive` flag you can do:
or you can use the following command to install similar packages using `brew`, the package manager for `macOS`:
git submodule update --init
```bash
brew install git python3
```
Installs Python 3 with `brew`, which includes `python3`, `pip3`, and the `venv` module. If you don't have Homebrew installed on your `macOS`, you can install it first.
Note that when submodules have other submodules you need recursive option.
or go to the [git downloads page](https://git-scm.com/downloads) and a [Python downloads page](https://www.python.org/downloads/) and download the latest version of git Python for `Windows`.
git submodule update --init --recursive
## Installation
### Dependencies
Download from repository
```bash
git clone https://gitea.ditaajipratama.net/aji/costapy.git
```
You need this libraries to use CostaPy:
- bottle
- gunicorn
- beaker
- mako
Go to the directory and install with this command:
You can install it with run this command
```bash
cd costapy
bash install.sh
```
sh install.sh
Use `cat install.sh` if you want to see a completed command.
Here is the completed command
sudo apt-get install -y python3-pip
pip install --upgrade pip
pip install bottle
pip install gunicorn
pip install beaker
pip install mako
## Usage
Use this command below to start the web service and it will run on port `11000` by default
```bash
.venv/bin/python3 costa.py costapy-welcome
```
Here, `costapy-welcome` is the label of your service. You can replace it with any name you prefer.
Use this command to start the web service
## Trivia
python3 costa.py
- Why must `venv`?
You can use nohup too and running it in the background like this
`venv` is a module in Python that provides support for creating lightweight, isolated Python environments, known as virtual environments. Each virtual environment has its own installation directories and can have its own versions of Python packages, independent of the system-wide Python environment.
nohup python3 costa.py &
When deploying a Python application, using a virtual environment ensures that only the required packages (and their specific versions) are bundled. This reduces the risk of deploying unnecessary packages or incompatible versions that could lead to runtime errors.
## Configuration
Using `venv` is a widely accepted best practice in the Python community. It encourages good habits in dependency management, ensuring that projects are self-contained and reducing the potential for "dependency hell."
### Global Variable (config/globalvar.py)
When a project is no longer needed, deleting its virtual environment is straightforward and does not affect other projects or the system's Python environment.
`globalvar.py` is the place for storing your Global Variable.
- Why I add `venv` on my `gitignore`?
`baseurl` </br>
Is the variable for your base URL (without `/` in the end).
Committing `venv` to Git is gross. Virtual environments can contain thousands of files and their size can be in gigabytes. Committing them to Git can overload and clutter your source code repo with unnecessary files and cause confusion for anyone trying to clone and run the source code on their machine.
`title` </br>
Is the variable for your web title.
### Directory (config/directory.py)
`directory.py` is the place for storing your path. It is useful to calling the path more efficiently.
## Handling the modules
Handling the module is in `handler.py`.

View File

@ -1,3 +1,4 @@
import sys
import os
class main:
@ -7,10 +8,10 @@ class main:
def get_html(location):
html_dict = {}
html_page_list = os.listdir(location)
html_page_list = os.listdir( location )
for html_page in html_page_list:
full_path = os.path.join(location, html_page)
if os.path.isfile(full_path): # Ensure it's a file, not a directory
with open(full_path, 'r') as html_handle:
html_dict[html_page] = html_handle.read()
full_path = location + "/" + html_page
html_handle = open( full_path , 'r' )
html_raw = html_handle.read()
html_dict[html_page] = html_raw
return html_dict