From 99bfda3b692d0898ca43f92e2735c937450d84e7 Mon Sep 17 00:00:00 2001 From: fonfon Date: Thu, 22 Jan 2015 14:51:49 +0000 Subject: [PATCH] removed default frontend stuff from actions it's all handled via get-frontend and set-frontend now. and there are now some doctests in actions/pagekite_util.py --- actions/pagekite | 40 +++++++++++--------------------- actions/pagekite_util.py | 21 +++++++++++------ plinth/modules/pagekite/forms.py | 6 +---- plinth/modules/pagekite/util.py | 11 +++------ plinth/modules/pagekite/views.py | 5 ++-- 5 files changed, 33 insertions(+), 50 deletions(-) diff --git a/actions/pagekite b/actions/pagekite index c913857c5..95312dd04 100755 --- a/actions/pagekite +++ b/actions/pagekite @@ -60,15 +60,6 @@ def parse_arguments(): subparsers.add_parser('enable', help='Enable PageKite service') subparsers.add_parser('disable', help='Disable PageKite service') - - # get/set using the default pagekite.net frontend - subparsers.add_parser('get-pagekitenet-frontend-status', - help='Get whether pagekite.net frontend is enabled') - subparsers.add_parser('enable-pagekitenet-frontend', - help='Enable using default pagekite.net frontend') - subparsers.add_parser('disable-pagekitenet-frontend', - help='Disable default pagekite.net frontend') - # Frontend subparsers.add_parser('get-frontend', help='Get pagekite frontend') set_frontend = subparsers.add_parser('set-frontend', @@ -130,23 +121,24 @@ def subcommand_disable(_): def subcommand_get_frontend(_): """Get pagekite frontend url""" - url = aug.get(PATHS['frontend']) - print url if url else "" + if aug.match(PATHS['defaults']): + print "pagekite.net" + else: + url = aug.get(PATHS['frontend']) + print url if url else "" def subcommand_set_frontend(arguments): - """Set pagekite frontend url and disable default pagekite.net frontend""" - aug.remove(PATHS['defaults']) - aug.set(PATHS['frontend'], arguments.url) - aug.save() + """Set pagekite frontend url, taking care of defaults and pagekite.net""" + if arguments.url in ('pagekite.net', 'defaults', 'default'): + enable_pagekitenet_frontend() + else: + aug.remove(PATHS['defaults']) + aug.set(PATHS['frontend'], arguments.url) + aug.save() -def subcommand_get_pagekitenet_frontend_status(_): - match = aug.match(PATHS['defaults']) - print "enabled" if match else "disabled" - - -def subcommand_enable_pagekitenet_frontend(_): +def enable_pagekitenet_frontend(): """Enable using default pageket.net frontend This disables any other frontends. @@ -157,12 +149,6 @@ def subcommand_enable_pagekitenet_frontend(_): print "enabled" -def subcommand_disable_pagekitenet_frontend(_): - aug.remove(PATHS['defaults']) - aug.save() - print "disabled" - - def pagekite_enable(): """Enable the pagekite daemon""" aug.remove(PATHS['abort_not_configured']) diff --git a/actions/pagekite_util.py b/actions/pagekite_util.py index 8e5ffca76..b3568d43a 100644 --- a/actions/pagekite_util.py +++ b/actions/pagekite_util.py @@ -18,13 +18,10 @@ # """ +Utilities for configuring PageKite. + The variables/functions defined here are used by both the action script and the plinth pagekite module. - -For example the functionality to convert pagekite service_on strings like - "http:@kitename:localhost:80:@kitestring" -into parameter dictionaries and the other way round. And functions that we want -to be covered by tests. """ # ATTENTION: This file has to be both python2 and python3 compatible @@ -37,7 +34,11 @@ SERVICE_PARAMS = ['protocol', 'kitename', 'backend_host', 'backend_port', def convert_to_service(service_string): - """ Convert a service string into a service parameter dictionary""" + """ Convert a service string into a service parameter dictionary + >>> convert_to_service('https/443:@kitename:localhost:443:@kitesecret') + {'kitename': '@kitename', 'backend_host': 'localhost', \ +'secret': '@kitesecret', 'protocol': 'https/443', 'backend_port': '443'} + """ # The actions.py uses shlex.quote() to escape/quote malicious user input. # That affects '*.@kitename', so the params string gets quoted. # If the string is escaped and contains '*.@kitename', look whether shlex @@ -75,7 +76,13 @@ def convert_to_service(service_string): def convert_service_to_string(service): - """ Convert service dict into a ":"-separated parameter string """ + """ Convert service dict into a ":"-separated parameter string + + >>> convert_service_to_string({'kitename': '@kitename', \ +'backend_host': 'localhost', 'secret': '@kitesecret', \ +'protocol': 'https/443', 'backend_port': '443'}) + 'https/443:@kitename:localhost:443:@kitesecret' + """ try: service_string = ":".join([str(service[param]) for param in SERVICE_PARAMS]) diff --git a/plinth/modules/pagekite/forms.py b/plinth/modules/pagekite/forms.py index 2cd7ad7e9..f2e936514 100644 --- a/plinth/modules/pagekite/forms.py +++ b/plinth/modules/pagekite/forms.py @@ -86,11 +86,7 @@ for your account if no secret is set on the kite')) messages.success(request, _('Kite details set')) if old['server'] != new['server']: - server = new['server'] - if server in ('defaults', 'default', 'pagekite.net'): - _run(['enable-pagekitenet-frontend']) - else: - _run(['set-frontend', server]) + _run(['set-frontend', new['server']]) messages.success(request, _('Pagekite server set')) if old != new: diff --git a/plinth/modules/pagekite/util.py b/plinth/modules/pagekite/util.py index 81280ad22..17575815d 100644 --- a/plinth/modules/pagekite/util.py +++ b/plinth/modules/pagekite/util.py @@ -84,14 +84,9 @@ def get_pagekite_config(): # PageKite kite details status.update(get_kite_details()) - # PageKite server: 'pagekite.net' if flag 'defaults' is set, - # the value of 'frontend' otherwise - use_pagekitenet_server = _run(['get-pagekitenet-frontend-status']) - if "enabled" in use_pagekitenet_server: - value = 'pagekite.net' - elif "disabled" in use_pagekitenet_server: - value = _run(['get-frontend']) - status['server'] = value.replace('\n', '') + # PageKite frontend server + server = _run(['get-frontend']) + status['server'] = server.replace('\n', '') return status diff --git a/plinth/modules/pagekite/views.py b/plinth/modules/pagekite/views.py index b79744996..319800c8c 100644 --- a/plinth/modules/pagekite/views.py +++ b/plinth/modules/pagekite/views.py @@ -16,7 +16,6 @@ # from gettext import gettext as _ -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse, reverse_lazy from django.http.response import HttpResponseRedirect from django.template.response import TemplateResponse @@ -39,7 +38,6 @@ subsubmenu = [{'url': reverse_lazy('pagekite:index'), 'text': _('Custom Services')}] -@login_required def index(request): """Serve introduction page""" return TemplateResponse(request, 'pagekite_introduction.html', @@ -59,7 +57,8 @@ class ContextMixin(object): context['subsubmenu'] = subsubmenu return context - @method_decorator(package.required('pagekite')) + @method_decorator(package.required('pagekite', 'augeas-tools', + 'python-augeas')) def dispatch(self, *args, **kwargs): return super(ContextMixin, self).dispatch(*args, **kwargs)