mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-18 08:33:41 +00:00
Use new-style classes everywhere
This commit is contained in:
parent
a958798769
commit
ef493ae243
@ -10,12 +10,15 @@ import json
|
||||
import UserDict
|
||||
|
||||
import sqlite3
|
||||
|
||||
|
||||
class DefaultArg:
|
||||
class DefaultArg(object):
|
||||
pass
|
||||
|
||||
class Solutions:
|
||||
|
||||
class Solutions(object):
|
||||
Sqlite3 = 0
|
||||
|
||||
|
||||
class FileDict(UserDict.DictMixin):
|
||||
"A dictionary that stores its data persistantly in a file"
|
||||
@ -134,7 +137,7 @@ class FileDict(UserDict.DictMixin):
|
||||
def batch(self):
|
||||
return self._Batch(self)
|
||||
|
||||
class _Batch:
|
||||
class _Batch(object):
|
||||
def __init__(self, d):
|
||||
self.__d = d
|
||||
|
||||
|
||||
@ -6,7 +6,8 @@ cherrypy.log.error_file = cfg.status_log_file
|
||||
cherrypy.log.access_file = cfg.access_log_file
|
||||
cherrypy.log.screen = False
|
||||
|
||||
class Logger():
|
||||
|
||||
class Logger(object):
|
||||
"""By convention, log levels are DEBUG, INFO, WARNING, ERROR and CRITICAL."""
|
||||
def log(self, msg, level="DEBUG"):
|
||||
try:
|
||||
|
||||
2
menu.py
2
menu.py
@ -3,7 +3,7 @@ import cherrypy
|
||||
import cfg
|
||||
|
||||
|
||||
class Menu():
|
||||
class Menu(object):
|
||||
"""One menu item."""
|
||||
def __init__(self, label="", icon="", url="#", order=50):
|
||||
"""label is the text that is displayed on the menu.
|
||||
|
||||
2
model.py
2
model.py
@ -3,6 +3,8 @@ class User(dict):
|
||||
is a bcrypt hash of the password), salt, groups, and an email address.
|
||||
They can be blank or None, but the keys must exist. """
|
||||
def __init__(self, dict=None):
|
||||
super(User, self).__init__()
|
||||
|
||||
for key in ['username', 'name', 'passphrase', 'salt', 'email']:
|
||||
self[key] = ''
|
||||
for key in ['groups']:
|
||||
|
||||
@ -6,8 +6,9 @@ import util
|
||||
|
||||
|
||||
class Apps(PagePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Apps, self).__init__()
|
||||
|
||||
self.register_page("apps")
|
||||
self.menu = cfg.main_menu.add_item("Apps", "icon-download-alt", "/apps", 80)
|
||||
self.menu.add_item("Chat", "icon-comment", "/../jwchat", 30)
|
||||
|
||||
@ -91,9 +91,8 @@ and must not be greater than 63 characters in length.'),
|
||||
|
||||
class Configuration(PagePlugin):
|
||||
"""System configuration page"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
del args # Unused
|
||||
del kwargs # Unused
|
||||
def __init__(self):
|
||||
super(Configuration, self).__init__()
|
||||
|
||||
self.register_page('sys.config')
|
||||
|
||||
|
||||
@ -28,10 +28,11 @@ import cfg
|
||||
import util
|
||||
|
||||
|
||||
class diagnostics(PagePlugin):
|
||||
class Diagnostics(PagePlugin):
|
||||
order = 30
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Diagnostics, self).__init__()
|
||||
|
||||
self.register_page("sys.diagnostics")
|
||||
cfg.html_root.sys.menu.add_item("Diagnostics", "icon-screenshot", "/sys/diagnostics", 30)
|
||||
|
||||
@ -41,10 +42,11 @@ class diagnostics(PagePlugin):
|
||||
return util.render_template(template='diagnostics',
|
||||
title=_('System Diagnostics'))
|
||||
|
||||
class test(PagePlugin):
|
||||
class Test(PagePlugin):
|
||||
order = 31
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Test, self).__init__()
|
||||
|
||||
self.register_page("sys.diagnostics.test")
|
||||
|
||||
@cherrypy.expose
|
||||
|
||||
@ -22,8 +22,9 @@ class Experts(PagePlugin):
|
||||
"""Expert forms page"""
|
||||
order = 60
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Experts, self).__init__()
|
||||
|
||||
self.register_page('sys.expert')
|
||||
|
||||
cfg.html_root.sys.menu.add_item(_('Expert Mode'), 'icon-cog',
|
||||
|
||||
@ -34,8 +34,8 @@ class Firewall(PagePlugin):
|
||||
"""Firewall menu entry and introduction page"""
|
||||
order = 40
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Firewall, self).__init__()
|
||||
|
||||
self.register_page('sys.firewall')
|
||||
cfg.html_root.sys.menu.add_item(_('Firewall'), 'icon-flag',
|
||||
|
||||
@ -69,8 +69,8 @@ FreedomBox!'))
|
||||
class FirstBoot(PagePlugin):
|
||||
"""First boot wizard"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(FirstBoot, self).__init__()
|
||||
|
||||
# this is the url this page will hang off of (/firstboot)
|
||||
self.register_page('firstboot')
|
||||
|
||||
@ -8,15 +8,17 @@ import util
|
||||
|
||||
class Help(PagePlugin):
|
||||
order = 20 # order of running init in PagePlugins
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
|
||||
def __init__(self):
|
||||
super(Help, self).__init__()
|
||||
|
||||
self.register_page("help")
|
||||
self.menu = cfg.main_menu.add_item(_("Documentation"), "icon-book", "/help", 101)
|
||||
self.menu.add_item(_("Where to Get Help"), "icon-search", "/help/index", 5)
|
||||
self.menu.add_item(_("Developer's Manual"), "icon-info-sign", "/help/view/plinth", 10)
|
||||
self.menu.add_item(_("FAQ"), "icon-question-sign", "/help/view/faq", 20)
|
||||
self.menu.add_item(_("%s Wiki" % cfg.box_name), "icon-pencil", "http://wiki.debian.org/FreedomBox", 30)
|
||||
self.menu.add_item(_("About"), "icon-star", "/help/about", 100)
|
||||
self.menu.add_item(_("About"), "icon-star", "/help/about", 100)
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
@ -31,8 +33,9 @@ class Help(PagePlugin):
|
||||
|
||||
|
||||
class View(PagePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(View, self).__init__()
|
||||
|
||||
self.register_page("help.view")
|
||||
|
||||
@cherrypy.expose
|
||||
|
||||
@ -36,8 +36,8 @@ class LoginForm(forms.Form): # pylint: disable-msg=W0232
|
||||
class AuthController(PagePlugin):
|
||||
"""Login and logout pages"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(AuthController, self).__init__()
|
||||
|
||||
self.register_page('auth')
|
||||
|
||||
|
||||
@ -4,8 +4,11 @@ from model import User
|
||||
from plugin_mount import UserStoreModule
|
||||
from withsqlite.withsqlite import sqlite_db
|
||||
|
||||
|
||||
class UserStore(UserStoreModule, sqlite_db):
|
||||
def __init__(self):
|
||||
super(UserStore, self).__init__()
|
||||
|
||||
self.db_file = cfg.user_db
|
||||
sqlite_db.__init__(self, self.db_file, autocommit=True, check_same_thread=False)
|
||||
self.__enter__()
|
||||
|
||||
@ -22,8 +22,9 @@ class OwnCloud(PagePlugin):
|
||||
"""ownCloud configuration page"""
|
||||
order = 90
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(OwnCloud, self).__init__()
|
||||
|
||||
self.register_page('apps.owncloud')
|
||||
|
||||
cfg.html_root.apps.menu.add_item('Owncloud', 'icon-picture',
|
||||
|
||||
@ -48,8 +48,9 @@ class Packages(PagePlugin):
|
||||
"""Package page"""
|
||||
order = 20
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Packages, self).__init__()
|
||||
|
||||
self.register_page('sys.packages')
|
||||
|
||||
cfg.html_root.sys.menu.add_item('Package Manager', 'icon-gift',
|
||||
|
||||
@ -35,8 +35,8 @@ class PageKite(PagePlugin):
|
||||
"""PageKite menu entry and introduction page"""
|
||||
order = 60
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(PageKite, self).__init__()
|
||||
|
||||
self.register_page("apps.pagekite")
|
||||
cfg.html_root.apps.menu.add_item(
|
||||
@ -109,8 +109,8 @@ class Configure(PagePlugin): # pylint: disable-msg=C0103
|
||||
"""Main configuration form"""
|
||||
order = 65
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Configure, self).__init__()
|
||||
|
||||
self.register_page("apps.pagekite.configure")
|
||||
|
||||
|
||||
@ -23,14 +23,15 @@ santiago_port = 52854
|
||||
# return True
|
||||
|
||||
class Santiago(PagePlugin):
|
||||
order = 90 # order of running init in PagePlugins
|
||||
def __init__(self, *args, **kwargs):
|
||||
order = 90 # order of running init in PagePlugins
|
||||
def __init__(self):
|
||||
super(Santiago, self).__init__()
|
||||
|
||||
self.register_page("santiago")
|
||||
self.santiago_address = self.get_santiago_address() #TODO: multiple santiago ports
|
||||
#set a listener on the santiago address
|
||||
|
||||
def get_santiago_address(self):
|
||||
def get_santiago_address(self):
|
||||
if 'santiago' in cfg.users['admin'] and 'address' in cfg.users['admin']['santiago']:
|
||||
return cfg.users['admin']['santiago']['address']
|
||||
else:
|
||||
@ -54,11 +55,11 @@ class Santiago(PagePlugin):
|
||||
print "Need to add these two lines to /etc/torrc:\n%s" % hidden_service_config
|
||||
return ""
|
||||
|
||||
def check_for_hidden_service(self):
|
||||
def check_for_hidden_service(self):
|
||||
pass
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self, *args, **kw):
|
||||
@cherrypy.expose
|
||||
def index(self, *args, **kw):
|
||||
|
||||
"""
|
||||
A request is a dict with some required keys:
|
||||
@ -111,12 +112,13 @@ class Santiago(PagePlugin):
|
||||
|
||||
## Plinth page to config santiago
|
||||
class santiago(PagePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
self.menu = cfg.html_root.privacy.menu.add_item("Santiago", "icon-leaf", "/privacy/santiago", 10)
|
||||
self.register_page("privacy.santiago")
|
||||
def __init__(self):
|
||||
super(Santiago, self).__init__(self)
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
def index(self):
|
||||
return "Santiago's config goes here."
|
||||
self.menu = cfg.html_root.privacy.menu.add_item("Santiago", "icon-leaf", "/privacy/santiago", 10)
|
||||
self.register_page("privacy.santiago")
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
def index(self):
|
||||
return "Santiago's config goes here."
|
||||
|
||||
@ -4,16 +4,16 @@ from plugin_mount import PagePlugin
|
||||
import cfg
|
||||
import util
|
||||
|
||||
sys_dir = "modules/installed/sys"
|
||||
|
||||
|
||||
class Sys(PagePlugin):
|
||||
order = 10
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
|
||||
def __init__(self):
|
||||
super(Sys, self).__init__()
|
||||
|
||||
self.register_page("sys")
|
||||
self.menu = cfg.main_menu.add_item(_("System"), "icon-cog", "/sys", 100)
|
||||
self.menu.add_item(_("Users and Groups"), "icon-user", "/sys/users", 15)
|
||||
self.menu.add_item(_("Users and Groups"), "icon-user", "/sys/users", 15)
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
|
||||
@ -28,10 +28,12 @@ import cfg
|
||||
import util
|
||||
|
||||
|
||||
class tor(PagePlugin):
|
||||
class Tor(PagePlugin):
|
||||
order = 60 # order of running init in PagePlugins
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
|
||||
def __init__(self):
|
||||
super(Tor, self).__init__()
|
||||
|
||||
self.register_page("apps.tor")
|
||||
cfg.html_root.apps.menu.add_item("Tor", "icon-eye-close", "/apps/tor",
|
||||
30)
|
||||
|
||||
@ -11,8 +11,10 @@ import util
|
||||
|
||||
class Users(PagePlugin):
|
||||
order = 20 # order of running init in PagePlugins
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
|
||||
def __init__(self):
|
||||
super(Users, self).__init__()
|
||||
|
||||
self.register_page("sys.users")
|
||||
|
||||
@staticmethod
|
||||
@ -52,8 +54,8 @@ class UserAdd(PagePlugin):
|
||||
"""Add user page"""
|
||||
order = 30
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(UserAdd, self).__init__()
|
||||
|
||||
self.register_page('sys.users.add')
|
||||
|
||||
@ -112,8 +114,8 @@ class UserEdit(PagePlugin):
|
||||
"""User edit page"""
|
||||
order = 35
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(UserEdit, self).__init__()
|
||||
|
||||
self.register_page('sys.users.edit')
|
||||
|
||||
|
||||
@ -20,11 +20,12 @@ class XMPP(PagePlugin):
|
||||
"""XMPP Page"""
|
||||
order = 60
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(XMPP, self).__init__()
|
||||
|
||||
self.register_page('apps.xmpp')
|
||||
cfg.html_root.apps.menu.add_item('XMPP', 'icon-comment',
|
||||
'/apps/xmpp', 40)
|
||||
'/apps/xmpp', 40)
|
||||
|
||||
self.client_service = service.Service(
|
||||
'xmpp-client', _('Chat Server - client connections'),
|
||||
@ -66,9 +67,10 @@ class Configure(PagePlugin):
|
||||
"""Configuration page"""
|
||||
order = 65
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
self.register_page("apps.xmpp.configure")
|
||||
def __init__(self):
|
||||
super(Configure, self).__init__()
|
||||
|
||||
self.register_page('apps.xmpp.configure')
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
@ -148,8 +150,9 @@ class Register(PagePlugin):
|
||||
"""User registration page"""
|
||||
order = 65
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
def __init__(self):
|
||||
super(Register, self).__init__()
|
||||
|
||||
self.register_page('apps.xmpp.register')
|
||||
|
||||
@cherrypy.expose
|
||||
|
||||
@ -18,10 +18,14 @@ class PluginMount(type):
|
||||
def get_plugins(cls, *args, **kwargs):
|
||||
return cls.init_plugins(*args, **kwargs)
|
||||
|
||||
class MultiplePluginViolation:
|
||||
|
||||
class MultiplePluginViolation(Exception):
|
||||
"""Multiple plugins found for a type where only one is expected"""
|
||||
pass
|
||||
|
||||
|
||||
class PluginMountSingular(PluginMount):
|
||||
"""Plugin mounter that allows only one plugin of this meta type"""
|
||||
def __init__(cls, name, bases, attrs):
|
||||
if not hasattr(cls, 'plugins'):
|
||||
cls.plugins = []
|
||||
@ -29,7 +33,7 @@ class PluginMountSingular(PluginMount):
|
||||
if len(cls.plugins) > 0:
|
||||
raise MultiplePluginViolation
|
||||
cls.plugins.append(cls)
|
||||
|
||||
|
||||
|
||||
def _setattr_deep(obj, path, value):
|
||||
"""If path is 'x.y.z' or ['x', 'y', 'z'] then perform obj.x.y.z = value"""
|
||||
@ -42,7 +46,7 @@ def _setattr_deep(obj, path, value):
|
||||
setattr(obj, path[-1], value)
|
||||
|
||||
|
||||
class PagePlugin:
|
||||
class PagePlugin(object):
|
||||
"""
|
||||
Mount point for page plugins. Page plugins provide display pages
|
||||
in the interface (one menu item, for example).
|
||||
@ -53,18 +57,20 @@ class PagePlugin:
|
||||
order = 50
|
||||
|
||||
__metaclass__ = PluginMount
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
def __init__(self):
|
||||
"""If cfg.html_root is none, then this is the html_root."""
|
||||
if not cfg.html_root:
|
||||
cfg.log('Setting html root to %s' % self.__class__.__name__)
|
||||
cfg.html_root = self
|
||||
|
||||
|
||||
def register_page(self, url):
|
||||
"""Add a page to the page tree structure"""
|
||||
cfg.log.info("Registering page: %s" % url)
|
||||
_setattr_deep(cfg.html_root, url, self)
|
||||
|
||||
|
||||
class UserStoreModule:
|
||||
class UserStoreModule(object):
|
||||
"""
|
||||
Mount Point for plugins that will manage the user backend storage,
|
||||
where we keep a hash for each user.
|
||||
@ -79,5 +85,5 @@ class UserStoreModule:
|
||||
compatibility with third party software. A future version of
|
||||
Plinth is likely to require LDAP.
|
||||
"""
|
||||
__metaclass__ = PluginMountSingular # singular because we can only use one user store at a time
|
||||
|
||||
# Singular because we can only use one user store at a time
|
||||
__metaclass__ = PluginMountSingular
|
||||
|
||||
@ -5,7 +5,6 @@ from actions import superuser_run, run
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
class TestPrivileged(unittest.TestCase):
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- mode: python; mode: auto-fill; fill-column: 80 -*-
|
||||
|
||||
import user_store, auth
|
||||
import auth
|
||||
from logger import Logger
|
||||
import cfg
|
||||
import unittest
|
||||
import cherrypy
|
||||
import plugin_mount
|
||||
import os
|
||||
from model import User
|
||||
cfg.log = Logger()
|
||||
|
||||
cherrypy.log.access_file = None
|
||||
|
||||
|
||||
class Auth(unittest.TestCase):
|
||||
"""Test check_credentials function of auth to confirm it works as expected"""
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- mode: python; mode: auto-fill; fill-column: 80 -*-
|
||||
|
||||
import user_store
|
||||
from logger import Logger
|
||||
import cfg
|
||||
import unittest
|
||||
@ -13,6 +12,7 @@ cfg.log = Logger()
|
||||
|
||||
cherrypy.log.access_file = None
|
||||
|
||||
|
||||
class UserStore(unittest.TestCase):
|
||||
"""Test each function of user_store to confirm they work as expected"""
|
||||
|
||||
@ -83,4 +83,4 @@ class UserStore(unittest.TestCase):
|
||||
return user
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user