mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
Indentation updates
- No spaces at the beginning and end of a single line comment. (python code does this) - Double space after a statement in a multi-line comment. (PEP-8) - Enforce 79 character limit. (PEP-8) - Empty line after a block ends make code more readable. - Empty line at the end of a multi line comment. (python code seems to do this)
This commit is contained in:
parent
4387c28495
commit
5e25a432c3
21
actions.py
21
actions.py
@ -32,7 +32,8 @@ Actions run commands with this contract (version 1.1):
|
||||
|
||||
C. Only one action can be called at a time.
|
||||
|
||||
This prevents us from appending multiple (unexpected) actions to the call.
|
||||
This prevents us from appending multiple (unexpected) actions to the
|
||||
call.
|
||||
|
||||
$ action="echo '$options'; echo 'oops'"
|
||||
$ options="hi"
|
||||
@ -47,12 +48,12 @@ Actions run commands with this contract (version 1.1):
|
||||
$ $action # oops, the file system is gone!
|
||||
|
||||
Arguments that fail this validation won't, but probably should, raise a
|
||||
ValueError. They don't because sanitizing this case is significantly
|
||||
ValueError. They don't because sanitizing this case is significantly
|
||||
easier than detecting if it occurs.
|
||||
|
||||
The options list is coerced into a space-separated string before being
|
||||
shell-escaped. Option lists including shell escape characters may need to
|
||||
be unescaped on the receiving end.
|
||||
shell-escaped. Option lists including shell escape characters may need
|
||||
to be unescaped on the receiving end.
|
||||
|
||||
E. Actions must exist in the actions directory.
|
||||
|
||||
@ -86,26 +87,31 @@ LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def run(action, options=None, async=False):
|
||||
"""Safely run a specific action as the current user.
|
||||
|
||||
See actions._run for more information.
|
||||
|
||||
"""
|
||||
return _run(action, options, async, False)
|
||||
|
||||
|
||||
def superuser_run(action, options=None, async=False):
|
||||
"""Safely run a specific action as root.
|
||||
|
||||
See actions._run for more information.
|
||||
|
||||
"""
|
||||
return _run(action, options, async, True)
|
||||
|
||||
|
||||
def _run(action, options=None, async=False, run_as_root=False):
|
||||
"""Safely run a specific action as a normal user or root.
|
||||
actions are pulled from the actions directory.
|
||||
|
||||
Actions are pulled from the actions directory.
|
||||
- options are added to the action command.
|
||||
- async: run asynchronously or wait for the command to complete.
|
||||
- run_as_root: execute the command through sudo.
|
||||
"""
|
||||
|
||||
"""
|
||||
if options is None:
|
||||
options = []
|
||||
|
||||
@ -124,7 +130,8 @@ def _run(action, options=None, async=False, run_as_root=False):
|
||||
|
||||
cmd = [cmd]
|
||||
|
||||
# contract: 3C, 3D: don't allow users to insert escape characters in options
|
||||
# contract: 3C, 3D: don't allow users to insert escape characters in
|
||||
# options
|
||||
if options:
|
||||
if not hasattr(options, "__iter__"):
|
||||
options = [options]
|
||||
|
||||
@ -15,13 +15,16 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
""" Plinth project specific errors """
|
||||
"""
|
||||
Project specific errors
|
||||
"""
|
||||
|
||||
|
||||
class PlinthError(Exception):
|
||||
"""Base class for all Plinth specific errors."""
|
||||
pass
|
||||
|
||||
|
||||
class ActionError(PlinthError):
|
||||
""" Use this error for exceptions when executing an action """
|
||||
"""Use this error for exceptions when executing an action."""
|
||||
pass
|
||||
|
||||
19
menu.py
19
menu.py
@ -19,8 +19,8 @@ class Menu(object):
|
||||
orders, but feel free to disregard that. If you need more
|
||||
granularity, don't bother renumbering things. Feel free to
|
||||
use fractional orders.
|
||||
"""
|
||||
|
||||
"""
|
||||
self.label = label
|
||||
self.icon = icon
|
||||
self.url = url
|
||||
@ -31,11 +31,12 @@ class Menu(object):
|
||||
self.items = []
|
||||
|
||||
def get(self, urlname, url_args=None, url_kwargs=None):
|
||||
"""Return a menu item with given URL name"""
|
||||
"""Return a menu item with given URL name."""
|
||||
url = reverse(urlname, args=url_args, kwargs=url_kwargs)
|
||||
for item in self.items:
|
||||
if item.url == url:
|
||||
return item
|
||||
|
||||
raise KeyError('Menu item not found')
|
||||
|
||||
def sort_items(self):
|
||||
@ -44,14 +45,18 @@ class Menu(object):
|
||||
|
||||
def add_urlname(self, label, icon, urlname, order=50, url_args=None,
|
||||
url_kwargs=None):
|
||||
""" Add a named URL to the menu (via add_item)
|
||||
url_args and url_kwargs will be passed on to url reverse """
|
||||
"""Add a named URL to the menu (via add_item).
|
||||
|
||||
url_args and url_kwargs will be passed on to Django reverse().
|
||||
|
||||
"""
|
||||
url = reverse(urlname, args=url_args, kwargs=url_kwargs)
|
||||
return self.add_item(label, icon, url, order)
|
||||
|
||||
def add_item(self, label, icon, url, order=50):
|
||||
"""This method creates a menu item with the parameters, adds
|
||||
that menu item to this menu, and returns the item.
|
||||
"""Create a new menu item with given parameters, add it to this menu and
|
||||
return it.
|
||||
|
||||
"""
|
||||
item = Menu(label=label, icon=icon, url=url, order=order)
|
||||
self.items.append(item)
|
||||
@ -59,7 +64,7 @@ class Menu(object):
|
||||
return item
|
||||
|
||||
def active_item(self, request):
|
||||
"""Return the first active item (e.g. submenu) that is found"""
|
||||
"""Return the first active item (e.g. submenu) that is found."""
|
||||
for item in self.items:
|
||||
if request.path.startswith(item.url):
|
||||
return item
|
||||
|
||||
@ -10,8 +10,8 @@ def init():
|
||||
"""Initialize the Help module"""
|
||||
menu = cfg.main_menu.add_urlname(_('Documentation'), 'icon-book',
|
||||
'help:index', 101)
|
||||
menu.add_urlname(_("Where to Get Help"), "icon-search",
|
||||
"help:index_explicit", 5)
|
||||
menu.add_urlname(_('Where to Get Help'), 'icon-search',
|
||||
'help:index_explicit', 5)
|
||||
menu.add_urlname(_('Developer\'s Manual'), 'icon-info-sign',
|
||||
'help:helppage', 10, url_args=('plinth',))
|
||||
menu.add_urlname(_('FAQ'), 'icon-question-sign', 'help:helppage', 20,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user