This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 18b8231
Showing
15 changed files
with
667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Push to Space | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
environment: Testing | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Push to Space | ||
uses: neobrains/space-deployment-github-action@v0.5 | ||
with: | ||
access_token: ${{ secrets.DETA_ACCESS_TOKEN }} | ||
project_id: ${{ secrets.DETA_PROJECT_ID }} | ||
space_push: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Custom ignores | ||
__pycache__/ | ||
.vscode/ | ||
.vs/ | ||
.idea/ | ||
.deta/ | ||
.space/ | ||
.env | ||
.venv/ | ||
env/ | ||
[Bb]uild/ | ||
[Dd]ist/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
*.exe | ||
[Ll]og*/ | ||
!*.spec | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
#*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
app_name: "Terminal" | ||
title: "Terminal" | ||
tagline: "Access to a Micro's underlying command shell." | ||
theme_color: "#555555" | ||
git: "https://github.com/lemonyte/deta-terminal" | ||
--- | ||
|
||
Terminal gives you access to a Micro's underlying operating system and file system. | ||
This app was created for debugging purposes, and just out of curiosity. | ||
|
||
## Usage | ||
|
||
Similar to how you would use a terminal app on your computer, you type commands and view the output. | ||
However, note that the Deta Micro runtime (essentially the AWS Lambda runtime) is very limited, so many commands and executables are not present. | ||
Basic commands like `ls`, `cat`, and `echo` work, but things like `apt` and `curl` are not available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Spacefile Docs: https://go.deta.dev/docs/spacefile/v0 | ||
v: 0 | ||
icon: ./static/icon.png | ||
micros: | ||
- name: terminal | ||
src: ./ | ||
engine: python3.9 | ||
primary: true | ||
run: uvicorn main:app | ||
dev: uvicorn main:app --reload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Lemonyte | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import subprocess | ||
|
||
from fastapi import FastAPI | ||
from fastapi.responses import HTMLResponse | ||
from fastapi.staticfiles import StaticFiles | ||
|
||
from models import Command, Result | ||
|
||
app = FastAPI() | ||
app.mount('/static', StaticFiles(directory='static'), name='static') | ||
|
||
|
||
@app.get('/', response_class=HTMLResponse) | ||
async def root(): | ||
with open('index.html') as file: | ||
return HTMLResponse(file.read()) | ||
|
||
|
||
@app.post('/api/command', response_model=Result) | ||
async def command(cmd: Command): | ||
original_cwd = os.getcwd() | ||
try: | ||
os.chdir(cmd.cwd) | ||
result = subprocess.run( | ||
cmd.args, | ||
capture_output=True, | ||
text=True, | ||
check=False, | ||
# shell=True, | ||
) | ||
stdout = result.stdout | ||
stderr = result.stderr | ||
returncode = result.returncode | ||
args = result.args | ||
except Exception as exc: # pylint: disable=broad-except | ||
stdout = '' | ||
stderr = str(exc) | ||
returncode = 1 | ||
args = cmd.args | ||
new_cwd = os.getcwd() | ||
os.chdir(original_cwd) | ||
return Result( | ||
stdout=stdout, | ||
stderr=stderr, | ||
returncode=returncode, | ||
args=args, | ||
cwd=new_cwd, | ||
) | ||
|
||
|
||
# TODO: output and command history using base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class Command(BaseModel): | ||
args: list[str] | ||
cwd: str = '.' | ||
|
||
|
||
class Result(BaseModel): | ||
stdout: str | ||
stderr: str | ||
returncode: int | ||
args: list[str] | ||
cwd: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Deta Terminal | ||
|
||
Access to a Deta Micro's underlying command shell. | ||
|
||
This app was created for debugging purposes, and just out of curiosity. | ||
|
||
## Installation | ||
|
||
Install your own instance on Deta Space by clicking the button below. | ||
|
||
[![Install on Space](https://deta.space/buttons/dark.svg)](https://deta.space/discovery/@lemonpi/terminal) | ||
|
||
## Usage | ||
|
||
Similar to how you would use a terminal app on your computer, you type commands and view the output. | ||
However, note that the Deta Micro runtime (essentially the AWS Lambda runtime) is very limited, so many commands and executables are not present. | ||
Basic commands like `ls`, `cat`, and `echo` work, but things like `apt` and `curl` are not available. | ||
|
||
## License | ||
|
||
[MIT License](license.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fastapi~=0.95.0 | ||
uvicorn~=0.22.0 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.