mirror of
https://github.com/RustyRaptor/Community.git
synced 2026-12-04 00:05:17 -07:00
Initial commit, some code restructuring
This commit is contained in:
1 parent
aa3a9a89af
commit
321b14b58b
9 files changed
+731
No files matched your search
+104
@@ -0,0 +1,104 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# 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/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# dotenv
|
||||
.env
|
||||
|
||||
# virtualenv
|
||||
.venv
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# Pycharm
|
||||
.idea/
|
||||
@@ -0,0 +1,26 @@
|
||||
[[source]]
|
||||
|
||||
url = "https://pypi.python.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
|
||||
[packages]
|
||||
|
||||
tinydb = "*"
|
||||
"glob2" = "*"
|
||||
six = "*"
|
||||
chardet = "*"
|
||||
click = "*"
|
||||
idna = "*"
|
||||
ipfsapi = "*"
|
||||
pillow = "*"
|
||||
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
|
||||
[requires]
|
||||
|
||||
python_version = "3.6"
|
||||
Generated
+136
@@ -0,0 +1,136 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "e81497d02551ac848dc7a9ce1f0970a816cbc7cfee88c4414ea7e640cb87dc5b"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.6"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.python.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296",
|
||||
"sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d"
|
||||
],
|
||||
"version": "==2018.1.18"
|
||||
},
|
||||
"chardet": {
|
||||
"hashes": [
|
||||
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
|
||||
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
|
||||
],
|
||||
"version": "==3.0.4"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
|
||||
"sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
|
||||
],
|
||||
"version": "==6.7"
|
||||
},
|
||||
"glob2": {
|
||||
"hashes": [
|
||||
"sha256:f5b0a686ff21f820c4d3f0c4edd216704cea59d79d00fa337e244a2f2ff83ed6"
|
||||
],
|
||||
"version": "==0.6"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f",
|
||||
"sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4"
|
||||
],
|
||||
"version": "==2.6"
|
||||
},
|
||||
"ipfsapi": {
|
||||
"hashes": [
|
||||
"sha256:9c0483057542e13ba19b27d19e7b9313899c72eb7cd4dac6a2b4564190b6d417",
|
||||
"sha256:e5748871dfa8afd4acdc7b12dd64c1a26276d702844fe16605dcf00d35bb3c60"
|
||||
],
|
||||
"version": "==0.4.2.post1"
|
||||
},
|
||||
"pillow": {
|
||||
"hashes": [
|
||||
"sha256:0013f590a8f260df60bcfd65db19d18efc04e7f046c3c82a40e2e2b3292a937c",
|
||||
"sha256:0b899ee80920bb533f26581af9b4660bc12aff4562555afe74e429101ebf3c94",
|
||||
"sha256:12f29d6c23424f704c66b5b68c02fe0b571504459605cfe36ab8158359b0e1bb",
|
||||
"sha256:135e9aa65150c53f7db85bf2bebb8a0e1a48ea850e80cf66e16dd04fa09d309c",
|
||||
"sha256:153ec6f18f7b61641e0e6e502acfaf4a06c9aba2ea11c0b4b3578ea9f13a4a4a",
|
||||
"sha256:17fe25efc785194d48c38fad85dce470013ba19d2fb66639e149f14bccf1327f",
|
||||
"sha256:1912b7230459fd53682dae32b83cbd8e5d642ba36d4be18566f00a9c063aa13d",
|
||||
"sha256:1a5b93084e01328a1cb1ecdad99d11d75e881e89a95f88d85b523646553b36c2",
|
||||
"sha256:25193f934d37d836a6b1f4c062ce574a96cbca7c6d9dc8ddfbbac7f9c54deaa4",
|
||||
"sha256:2c042352b430d678db50c78c5214e19638eff8b688941271da2de21fd298dfe5",
|
||||
"sha256:2e818dbe445e86fc6c266973fe540c35125c42eb2cf13a6095e9adaa89c0deb5",
|
||||
"sha256:2fcde9954c8882d1c7f93bb828caa34a4c5e3ee69dbc7895dc8652ad972b455a",
|
||||
"sha256:35f7d998b8e82fb3fb51ff88b30485eb81cd7dd56ec7e1a8deba23eb88532d44",
|
||||
"sha256:37cc0339abfa9e295c75d9a7f227d35cb44716feb95057f9449c4a9e9a17daf7",
|
||||
"sha256:43334f9581cd067945b8898cef9eb5714ee4883f8de0304c011f1dbdb1d4e2aa",
|
||||
"sha256:4bd4a71501b6d51db4abc07e1f43f5a6fed0a1a9583cca0b401d6af50284b0db",
|
||||
"sha256:57aa6198ba8acba1313c3b743e267d821a60cac77e6026caf0b55ca58d3d23be",
|
||||
"sha256:5b0d657460d9f3615876fec6306e97ca15a471f6169b622d76a47e270998acf1",
|
||||
"sha256:5cd36804f9f06a914a883fe682df5711d16d7b4f44d43189c5f013e7cd91e149",
|
||||
"sha256:6977cf073d83358b34f93abf5c1f1193b88675fe0e4441e0e28318bc3dcba7a0",
|
||||
"sha256:718ec7a122b28d64afc5fbc3a9b99bb0545ef511373cac06fe7624520e82cb20",
|
||||
"sha256:7dfbefdb3fb911ca9faed307bf309861e9995e36cca6b761c7ba6d9b77a9744a",
|
||||
"sha256:801cca8923508311bf5d6d0f7da5362552e8208ebd8ec0d7b9f2cd2ff5705734",
|
||||
"sha256:82b172e3264e62372c01b5b009b5b1a02fbb9276cbe5cc57ab00a6d6e5ed9a18",
|
||||
"sha256:82d1ff571489765df2816785d532e243bde213752156c227fca595723ec5ff42",
|
||||
"sha256:8580fc58074a16b749905b26cf8363f7b628dd167ba0130f5382cdc91c86b509",
|
||||
"sha256:931030d1d6282b7900e6b0a7ff9ecdb503b5e1e6781800dab2b71a9f39405bff",
|
||||
"sha256:9525cd680a6f9e80c6c0af03cf973e6505c59f60b4745f682cd1a449e54b31bb",
|
||||
"sha256:a224651a81e45ef4f1d0164e256c5f6b4abb49f2ae8f22ba2f3a9d0ff338e608",
|
||||
"sha256:a370d1c570f1d72e877099651e752332444b1c5009381f043c9da5fd47f3ebae",
|
||||
"sha256:b1d33c63a55d0d85df0ad02b2c16158fb4d8153afa7b908f1a67330fac694cd6",
|
||||
"sha256:b2240f298482f823576f397bb9f32ea913ad9456c526e141bc6f0a022b37a3e8",
|
||||
"sha256:b85f703c2ffe539313e39ce0676bed0f355cec45a16e58c9ab7417445843047c",
|
||||
"sha256:b9f63451084a718eccdeb1e382768c94647915653af4d6019f64560d9e98642b",
|
||||
"sha256:c793dfaa130847ccff958492b76ae8b9304e60b8a79a92962cb19e368276a22b",
|
||||
"sha256:d60c1625b108432ace8b1fa1a584017e5efa73f107d0f493c7f39c79bebf1d41",
|
||||
"sha256:dc4b018d5c9b636f7546583c5591b9ea00c328c3e5871992ef5b95bac353f097",
|
||||
"sha256:ddd16ab250b4fc97db1c47407e78c25216a75c29d29d10ad37e51b7a2ec7b2c3",
|
||||
"sha256:e126ff4fed71e78333840c07279e1617f63cfca76d63ad5b27d65a7277206a3d",
|
||||
"sha256:f8d49be8c282df8d2e1ab6ab53ab8abd859b1fa6fed384457ee85c9eff64ef97",
|
||||
"sha256:fcf64c91fd44485100a2965d23bb0e227d093e91f7e776c5ca3b32574766eb56"
|
||||
],
|
||||
"version": "==5.0.0"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b",
|
||||
"sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e"
|
||||
],
|
||||
"version": "==2.18.4"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
|
||||
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
|
||||
],
|
||||
"version": "==1.11.0"
|
||||
},
|
||||
"tinydb": {
|
||||
"hashes": [
|
||||
"sha256:1c746c7dc8125412d70ca157e86e9230afff4ce2c0bd609197a647d933007f43",
|
||||
"sha256:96bd60c51a34d7844b89197d7f19a855e249635a4e23dbcf5b892a10e301c032"
|
||||
],
|
||||
"version": "==3.8.0"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b",
|
||||
"sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"
|
||||
],
|
||||
"version": "==1.22"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
# PyKamina
|
||||

|
||||
A Kamina backend using python and IPFS
|
||||
|
||||
## What is Kamina?
|
||||
IPFS-based decentralized social networking platform
|
||||
|
||||
## What is this repo then?
|
||||
This is an implementation of Kamina(just the backend) written in Python using Flask
|
||||
|
||||
## Needed features before v1.0
|
||||
* Get the information of a single thread
|
||||
* Create a response
|
||||
* "Delete" a thread/response
|
||||
* Handle thread/response creation by a particular user
|
||||
|
||||
## How does this work
|
||||
This is the way I think Kamina should work (according to spaguettiman's initial idea). I'll try to explain myself as good as I can
|
||||
|
||||
#### The backend
|
||||
Kamina will be a web application that will communicate with a backend with GET/POST requests. So... the backend will be an api and the web application will use it.
|
||||
Also, the api should be available to anyone (except for certain parts of the page)
|
||||
|
||||
#### How will we store data
|
||||
Since this is ipfs-based, we will be using IPFS (lol).
|
||||
We will use .json files for each post/thread/reply and for the user info.
|
||||
One problem with ipfs is its inmutability, one can't really delete a file or something once we create it, a way to "circumvent" this issue is to use the files api ipfs has, it emulates a filesystem from which we can delete files and add them n' shit. The thing is that we really aren't deleting them, those files still exist, we can use this functionality as a history feature.
|
||||
|
||||
#### The users problem
|
||||
Since all files are public once we add them to the network [proof](https://ipfs.io/ipfs/QmTKwydPody1deWXxQo7TZEpuZhFFzDkWpcYyeFyB9WdAb)(some testing I was making), users information will be available to anyone that has the hash of that json file, that means they will have access to the password hash we create. **We need to fix this somehow if we want users functionality**
|
||||
|
||||
#### Further reading
|
||||
[IPFS's api python implementation's documentation](https://ipfs.io/ipns/QmZ86ow1byeyhNRJEatWxGPJKcnQKG7s51MtbHdxxUddTH/Software/Python/ipfsapi/)
|
||||
|
||||
## Installation
|
||||
|
||||
There are some prerequisites in order to start tinkering with the backend:
|
||||
* python (version 3)
|
||||
* pip (for python 3)
|
||||
* ipfs (see https://ipfs.io/docs/install/)
|
||||
* The frontend repository cloned (https://github.com/ImplyingProgramming/kamina-frontend)
|
||||
* If you know how to, use a virtualenv
|
||||
|
||||
1. Clone the repo and cd into the directory
|
||||
```sh
|
||||
git clone https://github.com/ImplyingProgramming/kamina-backend.git
|
||||
cd kamina-backend
|
||||
```
|
||||
|
||||
2. Install your python dependencies with:
|
||||
```
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
3. Open up a seperate terminal run the ipfs daemon. This can be done with:
|
||||
```
|
||||
ipfs daemon
|
||||
```
|
||||
4. Run the application with:
|
||||
```
|
||||
python3 app.py
|
||||
```
|
||||
5. Run the [frontend](https://github.com/ImplyingProgramming/kamina-frontend) repository. See the README there.
|
||||
|
||||
|
||||
## API Documentation
|
||||
Some parts of the backend require heavily on some features of the
|
||||
frontend(like id generation), and would make interacting with the backend
|
||||
through the terminal kinda impossible. Caveat emptor.
|
||||
|
||||
----
|
||||
### /api/make_thread
|
||||
Make a new thread, you might need to use first the upload_image call
|
||||
|
||||
__Arguments:__
|
||||
* thread_title: Thread's title
|
||||
* thread_content: Thread's body/content/text
|
||||
* post_id: a uuidv4 formatted string
|
||||
* thread_image_hashes (TODO - make this optional): A json object that contains
|
||||
the URL for an image and its thumbnail
|
||||
* thread_image_info: A json object containing the size, dimensions, and filename
|
||||
of the thread's image
|
||||
|
||||
__Returns:__
|
||||
The response_id of the newly created thread
|
||||
|
||||
----
|
||||
### /api/get_threads
|
||||
Get all threads
|
||||
|
||||
__Arguments:__
|
||||
* None (for now, probably)
|
||||
|
||||
__Returns:__
|
||||
A JSON-formatted list containing all the existing threads' details
|
||||
|
||||
----
|
||||
### /api/get_thread
|
||||
Gets a thread based on a provided thread\_id
|
||||
|
||||
__Arguments:__
|
||||
* post\_id: the uuid of an existing post
|
||||
|
||||
__Returns:__
|
||||
A JSON-formatted object containing the details of a thread
|
||||
|
||||
_or_
|
||||
|
||||
A JSON-formatted object containing an entry _err_, if there was an error in processing the request
|
||||
|
||||
----
|
||||
### /api/upload_image
|
||||
Upload an image to the IPFS node, and create a thumbnail of it
|
||||
|
||||
__Arguments:__
|
||||
* file (multipart/form-data): the file you want to upload
|
||||
* post_id: a uuid4 formatted string
|
||||
|
||||
__Returns:__
|
||||
A JSON-formatted list containing IPFS hashes of both the file and its thumbnail,
|
||||
and the information of the original image (size, dimensions, filename)
|
||||
|
||||
----
|
||||
In memory of Miguel Vesga
|
||||
@@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Kamina - The />p/ social network
|
||||
Copyright (C) 2018, The Kamina Project
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
"""
|
||||
|
||||
"""
|
||||
app.py - the command-line driver for Kamina.
|
||||
|
||||
This module parses command-line options, arguments, flags, and sub-commands.
|
||||
It also instantiates a logger, loads JSON configuration files, invokes the
|
||||
daemon process for a Kamina instance, and populates the attributes of the
|
||||
internal daemon class.
|
||||
"""
|
||||
import itertools, os, sys, json
|
||||
import threading, logging, logging.config
|
||||
import click
|
||||
import kamina
|
||||
|
||||
|
||||
#
|
||||
#load_config - open a JSON file, and parse their values into a dict
|
||||
#
|
||||
def load_config(filename="config.json") -> dict:
|
||||
config = {}
|
||||
|
||||
if os.path.exists(filename):
|
||||
with open(filename, "rt") as cfg:
|
||||
try:
|
||||
config = json.load(cfg)
|
||||
except:
|
||||
print("Config file format is invalid! Providing defaults...")
|
||||
else:
|
||||
print("No config file found!")
|
||||
|
||||
return config
|
||||
|
||||
#I have a low opinion of sigils, so function decorators have always looked
|
||||
#like pythonic cancer. Despite that, I've gotta admit the Click framework
|
||||
#makes writing these cli apps insanely easy, so... I'll roll with it.
|
||||
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
|
||||
@click.version_option(version=0.33, prog_name="kamina")
|
||||
@click.option("--verbose", default=False, is_flag=True, help="Print all log messages to console")
|
||||
@click.option("--debug", default=False, is_flag=True, help="Enable debugging")
|
||||
@click.option("--log","-l",default=None, type=click.Path(), help="Redirect logging location")
|
||||
@click.option("--config","-c",default="config.json", type=click.Path(exists=True), help="Specify alternate configuration file")
|
||||
@click.pass_context
|
||||
def main(ctx, verbose, debug, log, config) -> None:
|
||||
"""The Kamina service utility"""
|
||||
|
||||
logger = None
|
||||
handlers = []
|
||||
conf = {}
|
||||
|
||||
conf = load_config(config)
|
||||
if "logging" in conf:
|
||||
logging.config.dictConfig(conf["logging"])
|
||||
|
||||
#There might not have been any configuration loaded, so let's at least set
|
||||
#a baseline - these two values should at least be known.
|
||||
if not "debug" in conf:
|
||||
conf["debug"] = debug
|
||||
if not "verbose" in conf:
|
||||
conf["verbose"] = verbose
|
||||
|
||||
#Now override the config file defaults with any command line options
|
||||
if debug == True:
|
||||
conf["debug"] = True
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
#If you specified an alternate log location on the command-line, use that.
|
||||
#Otherwise, use syslog, so we at least have that, even if the config file
|
||||
#didn't specify any logging info.
|
||||
if log != None:
|
||||
handlers.append(logging.FileHandler(log))
|
||||
else:
|
||||
#Make sure we're not setting up two syslog handlers
|
||||
if not len(logger.handlers):
|
||||
handlers.append(logging.handlers.SysLogHandler(address="/dev/log"))
|
||||
|
||||
if verbose == True:
|
||||
conf["verbose"] = True
|
||||
handlers.append(logging.StreamHandler(sys.stdout))
|
||||
|
||||
for handle in handlers:
|
||||
logger.addHandler(handle)
|
||||
|
||||
#Now, propogate the context for our sub-commands
|
||||
ctx.obj["CONF"] = conf
|
||||
ctx.obj["LOG"] = logger
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def init(ctx) -> None:
|
||||
"""Setup a new Kamina instance"""
|
||||
|
||||
logger = None
|
||||
spinner = ""
|
||||
conf = {}
|
||||
|
||||
#Grab our context from main for logging and config info.
|
||||
logger = ctx.obj["LOG"]
|
||||
conf = ctx.obj["CONF"]
|
||||
spinner = itertools.cycle(['-', '/', '|', '\\'])
|
||||
|
||||
if logger == None or len(conf) == 0:
|
||||
print("init: no valid conf or logger passed. Exiting.")
|
||||
sys.exit(1)
|
||||
|
||||
logger.info("Setting up a new Kamina instance...")
|
||||
try:
|
||||
daemon = kamina.KaminaInstance(conf, logger)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
setup_thread = threading.Thread(target=daemon.Setup(), args=())
|
||||
setup_thread.start()
|
||||
#If we're running in production, give a nice fidget spinner
|
||||
if conf["verbose"] == False:
|
||||
sys.stdout.write("Setting up a new Kamina instance....")
|
||||
while daemon.running:
|
||||
sys.stdout.write(next(spinner))
|
||||
sys.stdout.write('\b')
|
||||
sys.stdout.flush()
|
||||
except Exception as e:
|
||||
sys.stdout.write("\bfailed!")
|
||||
sys.stdout.flush()
|
||||
|
||||
print(e)
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.stdout.write("\bdone!")
|
||||
sys.stdout.flush()
|
||||
sys.exit(0)
|
||||
|
||||
@main.command()
|
||||
def daemon() -> None:
|
||||
"""Run the Kamina service as a daemon"""
|
||||
|
||||
pass
|
||||
|
||||
@main.command(short_help="Manually create a post", help="Manually create a post identified by <postid>")
|
||||
@click.argument("postid", metavar="<postid>")
|
||||
def create(postid) -> None:
|
||||
pass
|
||||
|
||||
@main.command(short_help="Manually delete a post", help="Manually delete a post identified by <postid>")
|
||||
@click.argument("postid", metavar="<postid>")
|
||||
def delete(postid) -> None:
|
||||
click.echo("Delete called")
|
||||
|
||||
@main.command()
|
||||
def archive() -> None:
|
||||
"""Set all posts to expire"""
|
||||
|
||||
pass
|
||||
|
||||
@main.command(short_help="Reload system modules")
|
||||
@click.argument("module", default=None, required=False, nargs=1)
|
||||
def reload(module) -> None:
|
||||
"""Valid modules are [posts|media|net] or blank to reload all"""
|
||||
|
||||
pass
|
||||
|
||||
@main.command()
|
||||
@click.argument('topic', default=None, required=False, nargs=1)
|
||||
@click.pass_context
|
||||
def help(ctx, topic) -> None:
|
||||
"""Print this help message and exit"""
|
||||
|
||||
if topic is None:
|
||||
click.echo(ctx.parent.get_help())
|
||||
else:
|
||||
click.echo(main.commands[topic].get_help(ctx))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(obj={})
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"debug": false,
|
||||
"verbose": false,
|
||||
|
||||
"logging": {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": false,
|
||||
"formatters": {
|
||||
"simple": {
|
||||
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
}
|
||||
},
|
||||
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"level": "DEBUG",
|
||||
"formatter": "simple",
|
||||
"stream": "ext://sys.stdout"
|
||||
},
|
||||
|
||||
"file": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"level": "INFO",
|
||||
"formatter": "simple",
|
||||
"filename": "kamina.log",
|
||||
"maxBytes": 10485760,
|
||||
"backupCount": 20,
|
||||
"encoding": "utf8"
|
||||
},
|
||||
|
||||
"syslog": {
|
||||
"class": "logging.handlers.SysLogHandler",
|
||||
"level": "INFO",
|
||||
"formatter": "simple",
|
||||
"address": "/dev/log"
|
||||
}
|
||||
},
|
||||
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
"handlers": ["syslog"],
|
||||
"propagate": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from .daemon import KaminaInstance
|
||||
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Kamina - The />p/ social network
|
||||
Copyright (C) 2018, The Kamina Project
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
"""
|
||||
|
||||
"""
|
||||
kamina.daemon.py - Process and Thread handlers for backgrounded Kamina instances
|
||||
|
||||
Provides a python class for maintaining some consistent state across processes
|
||||
and threads.
|
||||
"""
|
||||
import sys, signal, time
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
class KaminaInstance:
|
||||
"""Class providing state for the Kamina daemon"""
|
||||
|
||||
#Not providing any defaults here, as an instance needs at least some conf
|
||||
#and a logger to speak out to.
|
||||
def __init__(self, conf, logger) -> None:
|
||||
self.running = False
|
||||
|
||||
#Like I said, we need at least some basic conf and a logger
|
||||
if not logger:
|
||||
print("KaminaInstance: not given a valid logger.")
|
||||
raise Exception
|
||||
else:
|
||||
self.logger = logger
|
||||
if (not "debug" in conf) or (not "verbose" in conf):
|
||||
print("KaminaInstance: not given valid conf.")
|
||||
raise Exception
|
||||
else:
|
||||
self.debug = conf["debug"]
|
||||
self.verbose = conf["verbose"]
|
||||
|
||||
def signal_handler(self, signum, frame):
|
||||
sys.stdout.write("\naborting on signal %s\n" % signum)
|
||||
sys.stdout.flush()
|
||||
|
||||
self.running = False
|
||||
raise Exception
|
||||
|
||||
def Setup(self) -> None:
|
||||
"""Called to initialize a new Kamina instance"""
|
||||
|
||||
self.running = True
|
||||
|
||||
#setup our signal handlers
|
||||
#I don't do this in __init__, because having the class initialized
|
||||
#doesn't mean we're invoking any methods. At least not yet.
|
||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
self.running = False
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.14, written by Peter Selinger 2001-2017
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M380 3818 c0 -12 376 -469 405 -493 7 -5 127 -146 266 -313 140 -167
|
||||
287 -341 327 -388 l72 -85 0 -308 0 -309 508 -293 c279 -161 527 -304 552
|
||||
-317 l45 -24 240 139 c132 77 378 220 548 317 l307 178 0 276 c0 317 -8 284
|
||||
104 412 86 98 449 528 502 594 22 28 65 78 95 111 93 101 409 484 409 495 0 5
|
||||
-3 10 -6 10 -10 0 -175 -85 -379 -195 -365 -197 -585 -316 -659 -356 -49 -27
|
||||
-92 -49 -97 -49 -4 0 -245 137 -536 305 -290 168 -534 303 -542 300 -8 -3
|
||||
-235 -133 -505 -289 -270 -156 -500 -288 -512 -294 -17 -9 -47 4 -193 84 -95
|
||||
52 -175 94 -177 94 -3 0 -21 11 -42 23 -20 13 -86 50 -147 82 -60 32 -123 66
|
||||
-140 75 -51 30 -434 230 -440 230 -3 0 -5 -6 -5 -12z m4108 -226 c-14 -15
|
||||
-232 -265 -484 -557 -687 -793 -777 -895 -787 -895 -5 0 -156 75 -334 166
|
||||
l-324 166 -317 -151 c-174 -84 -322 -150 -330 -149 -13 3 -1233 1390 -1227
|
||||
1396 3 4 345 -177 1175 -621 278 -148 546 -292 596 -318 50 -27 99 -49 109
|
||||
-49 15 0 550 289 1780 961 88 48 162 85 164 83 3 -2 -7 -17 -21 -32z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
Reference in new issue
Block a user