Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

[fea] LWP is python module #79

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
*.pyc
__pycache__
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit tests / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/

/dist
/buid
/env
/.idea
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include lwp/templates *
recursive-include lwp/static *
recursive-include resources *
91 changes: 91 additions & 0 deletions bin/lwp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python
# encoding: utf-8

# LXC Python Library
# for compatibility with LXC 0.8 and 0.9
# on Ubuntu 12.04/12.10/13.04

# Author: Elie Deloumeau
# Contact: [email protected]

# The MIT License (MIT)
# Copyright (c) 2013 Elie Deloumeau

# 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.

import argparse
import logging
from arconfig import GenConfigAction, LoadConfigAction
from uuid import uuid1
import os

parser = argparse.ArgumentParser("lwp")
parser.add_argument("--config", action=LoadConfigAction)
parser.add_argument("--gen-config", action=GenConfigAction)
parser.add_argument("--debug", default=False, action="store_true", help="Debugging output")

group = parser.add_argument_group("database")
group.add_argument("-D", "--db-file", dest="db",
default="/var/lib/lxc/lwp.db",
help="Database file [default: /var/lib/lxc/lwp.db]")

group = parser.add_argument_group("main")
group.add_argument("-l", "--address", default="0.0.0.0", help="Listen HTTP address [default: 0.0.0.0]", dest="address")
group.add_argument("-p", "--port", default=5000, help="Listen HTTP port [default: 5000]", type=int, dest="port")
group.add_argument("--session-timeout", default=600, type=int, dest="session_timeout")
group.add_argument("-S", "--secret", default=str(uuid1()), dest="secret")

if __name__ == '__main__':
options = parser.parse_args()
logging.basicConfig(
format=u'[%(asctime)s] %(filename)s:%(lineno)d %(levelname)-6s %(message)s',
level=logging.INFO if options.debug else logging.DEBUG
)


from lwp.app import app


def main(host='0.0.0.0', port=5000):
log = logging.getLogger("lwp")
if not os.path.exists(app.options.directory):
log.fatal("LXC Directory doesn't exists")
return 128
try:
import eventlet
from eventlet import wsgi
log.info("Starting through eventlet")
wsgi.server(eventlet.listen((host, port)), app)
except ImportError:
log.info("Starting through default WSGI engine")
app.run(host=host, port=port)

return 0


if __name__ == '__main__':
with app.app_context() as c:
app.options = options
app.options.directory = '/var/lib/lxc'
app.config['SECRET_KEY'] = app.options.secret

exit(main(
host=app.options.address,
port=app.options.port
))
13 changes: 0 additions & 13 deletions lwp.conf

This file was deleted.

Loading