summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Styk <mastyk@redhat.com>2019-06-03 09:51:17 +0200
committerMartin Styk <mastyk@redhat.com>2019-06-03 10:41:24 +0200
commitb7a1f39893e3e59fd5ac03017cbfd597b17fc033 (patch)
tree864ce052934f565e0f5c26ec4f7c40f8a6977b92
parentb304df9dd86649f742e389687c32baa98893d9b5 (diff)
Remove TurboGears from Kickstart
Also codestyle is corrected Change-Id: I4ad73148f722eb7e65ca612e62dd26e1927c5e90 Signed-off-by: Martin Styk <mastyk@redhat.com>
-rw-r--r--Server/bkr/server/controllers.py867
-rw-r--r--Server/bkr/server/kickstart.py117
-rw-r--r--Server/bkr/server/util.py102
3 files changed, 598 insertions, 488 deletions
diff --git a/Server/bkr/server/controllers.py b/Server/bkr/server/controllers.py
index ac1febf..67f5105 100644
--- a/Server/bkr/server/controllers.py
+++ b/Server/bkr/server/controllers.py
@@ -1,138 +1,150 @@
-
# 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.
+import logging
+import re
+from decimal import Decimal
+
+import cherrypy
+import kid
import lxml.etree
-from turbogears.database import session
-from turbogears import expose, flash, widgets, validate, error_handler, validators, paginate, url
-from turbogears import redirect, config
+import pkg_resources
+import rdflib.graph
+import time
+from cherrypy import request, response
+from datetime import datetime
from flask import redirect as flask_redirect
+from sqlalchemy import or_
+from sqlalchemy.exc import InvalidRequestError
+from sqlalchemy.orm.exc import NoResultFound
+from turbogears import expose, flash, widgets, validate, error_handler, paginate, url
+from turbogears import redirect, config
+from turbogears.database import session
+
import bkr
-import bkr.server.stdvars
+import bkr.server.rdf
+import bkr.server.recipes
import bkr.server.search_utility as su
-from bkr.server.app import app
-from bkr.server.model import (TaskBase, Device, System,
- SystemActivity, Key, OSMajor, DistroTree, Arch, TaskPriority,
- Group, GroupActivity, RecipeSet, RecipeSetActivity, User, LabInfo,
- ReleaseAction, LabController, Hypervisor, KernelType,
- SystemType, Distro, Job, InstallOptions, ExcludeOSMajor,
- ExcludeOSVersion, OSVersion, Provision, ProvisionFamily,
- ProvisionFamilyUpdate, SystemStatus, Key_Value_Int, Key_Value_String,
- SystemAccessPolicy, SystemPermission, MachineRecipe, DistroTag, SystemPool)
-from bkr.server.keytypes import KeyTypes
+import bkr.server.stdvars
+from bkr.server import metrics, identity
from bkr.server.CSV_import_export import CSV
-from bkr.server.group import Groups
+from bkr.server.app import app
+from bkr.server.authentication import Auth
+from bkr.server.bexceptions import BX
+from bkr.server.bexceptions import DatabaseLookupError
+from bkr.server.cherrypy_util import PlainTextHTTPException
from bkr.server.configuration import Configuration
-from bkr.server.tag import Tags
-from bkr.server.osversion import OSVersions
-from bkr.server.distro_family import DistroFamily
-from bkr.server.labcontroller import LabControllers
-from bkr.server.user import Users
+from bkr.server.controller_utilities import Utility, \
+ restrict_http_method
from bkr.server.distro import Distros
+from bkr.server.distro_family import DistroFamily
from bkr.server.distrotrees import DistroTrees
-from bkr.server.reports import Reports
+from bkr.server.group import Groups
+from bkr.server.helpers import make_link
from bkr.server.job_matrix import JobMatrix
+from bkr.server.jobs import Jobs
+from bkr.server.keytypes import KeyTypes
+from bkr.server.labcontroller import LabControllers
+from bkr.server.model import (TaskBase, Device, System,
+ Key, OSMajor, DistroTree, Arch, TaskPriority,
+ RecipeSet, User, LabInfo,
+ LabController, Distro, ExcludeOSMajor,
+ ExcludeOSVersion, OSVersion, Provision, ProvisionFamily,
+ ProvisionFamilyUpdate, SystemStatus, Key_Value_Int, Key_Value_String,
+ DistroTag)
+from bkr.server.needpropertyxml import XmlHost
+from bkr.server.osversion import OSVersions
+from bkr.server.preferences import Preferences
+from bkr.server.recipes import Recipes
+from bkr.server.recipesets import RecipeSets
+from bkr.server.reports import Reports
from bkr.server.reserve_workflow import ReserveWorkflow
from bkr.server.retention_tags import RetentionTag as RetentionTagController
-from bkr.server.watchdog import Watchdogs
-from bkr.server.systems import SystemsController
from bkr.server.system_action import SystemAction as SystemActionController
+from bkr.server.systems import SystemsController
+from bkr.server.tag import Tags
+from bkr.server.task_actions import TaskActions
+from bkr.server.tasks import Tasks
+from bkr.server.user import Users
+from bkr.server.util import absolute_url
+from bkr.server.watchdog import Watchdogs
from bkr.server.widgets import TaskSearchForm, SearchBar, \
SystemInstallOptions, \
SystemKeys, SystemExclude, SystemDetails, \
LabInfoForm, myPaginateDataGrid
-from bkr.server.preferences import Preferences
-from bkr.server.authentication import Auth
from bkr.server.xmlrpccontroller import RPCRoot
-from bkr.server.jobs import Jobs
-from bkr.server.recipes import Recipes
-from bkr.server.recipesets import RecipeSets
-from bkr.server.tasks import Tasks
-from bkr.server.task_actions import TaskActions
-from bkr.server.kickstart import KickstartController
-from bkr.server.controller_utilities import Utility, \
- restrict_http_method
-from bkr.server.bexceptions import BeakerException, BX
-from cherrypy import request, response
-from cherrypy.lib.cptools import serve_file
-from bkr.server.cherrypy_util import PlainTextHTTPException
-from bkr.server.helpers import make_link
-from bkr.server import metrics, identity
-from bkr.server.needpropertyxml import XmlHost
-from bkr.server.util import absolute_url
-from decimal import Decimal
-import bkr.server.recipes
-import bkr.server.rdf
-import kid
-import cherrypy
-from itertools import chain
-import re
-import os
-import pkg_resources
-import rdflib.graph
-from sqlalchemy import and_, join, or_
-from sqlalchemy.orm.exc import NoResultFound
-from sqlalchemy.exc import InvalidRequestError
-import time
-from datetime import datetime
-from bkr.server.bexceptions import DatabaseLookupError
-import logging
log = logging.getLogger("bkr.server.controllers")
# This ridiculous hack gets us an HTML5 doctype in our Kid template output.
config.update({'kid.outputformat': kid.HTMLSerializer(doctype=('html',))})
+
class Arches:
@expose(format='json')
- def by_name(self,name):
+ def by_name(self, name):
name = name.lower()
search = Arch.list_by_name(name)
arches = [match.arch for match in search]
return dict(arches=arches)
+
class Devices:
@expose(template='bkr.server.templates.grid')
- @paginate('list',default_order='fqdn',limit=10)
+ @paginate('list', default_order='fqdn', limit=10)
def view(self, id):
device = session.query(Device).get(id)
systems = System.all(identity.current.user).join('devices').filter_by(id=id).distinct()
device_grid = myPaginateDataGrid(fields=[
- ('System', lambda x: make_link("/view/%s" % x.fqdn, x.fqdn)),
- ('Description', lambda x: device.description),
- ])
- return dict(title="",
- grid = device_grid,
+ ('System', lambda x: make_link("/view/%s" % x.fqdn, x.fqdn)),
+ ('Description', lambda x: device.description),
+ ])
+ return dict(title="",
+ grid=device_grid,
search_bar=None,
- list = systems)
+ list=systems)
@expose(template='bkr.server.templates.grid')
- @paginate('list',default_order='description',limit=50)
+ @paginate('list', default_order='description', limit=50)
def default(self, *args, **kw):
args = list(args)
if len(args) == 1:
devices = session.query(Device).join('device_class').filter_by(device_class=args[0])
-
+
if len(args) != 1:
devices = session.query(Device).join('device_class')
devices_grid = myPaginateDataGrid(fields=[
- widgets.PaginateDataGrid.Column(name='description', getter=lambda x: make_link("/devices/view/%s" % x.id, x.description), title='Description', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='device_class.device_class', getter=lambda x: x.device_class, title='Type', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='bus', getter=lambda x: x.bus, title='Bus', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='driver', getter=lambda x: x.driver, title='Driver', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='vendor_id', getter=lambda x: x.vendor_id, title='Vendor ID', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='device_id', getter=lambda x: x.device_id, title='Device ID', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='subsys_vendor_id', getter=lambda x: x.subsys_vendor_id, title='Subsys Vendor ID', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='subsys_device_id', getter=lambda x: x.subsys_device_id, title='Subsys Device ID', options=dict(sortable=True)),
- widgets.PaginateDataGrid.Column(name='fw_version', getter=lambda x: x.fw_version, title='Firmware Version', options=dict(sortable=True)),
- ])
+ widgets.PaginateDataGrid.Column(name='description',
+ getter=lambda x: make_link("/devices/view/%s" % x.id,
+ x.description),
+ title='Description', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='device_class.device_class',
+ getter=lambda x: x.device_class, title='Type',
+ options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='bus', getter=lambda x: x.bus, title='Bus',
+ options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='driver', getter=lambda x: x.driver,
+ title='Driver', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='vendor_id', getter=lambda x: x.vendor_id,
+ title='Vendor ID', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='device_id', getter=lambda x: x.device_id,
+ title='Device ID', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='subsys_vendor_id',
+ getter=lambda x: x.subsys_vendor_id,
+ title='Subsys Vendor ID', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='subsys_device_id',
+ getter=lambda x: x.subsys_device_id,
+ title='Subsys Device ID', options=dict(sortable=True)),
+ widgets.PaginateDataGrid.Column(name='fw_version', getter=lambda x: x.fw_version,
+ title='Firmware Version', options=dict(sortable=True)),
+ ])
return dict(title="Devices",
- grid = devices_grid,
+ grid=devices_grid,
search_bar=None,
- list = devices)
+ list=devices)
class Root(RPCRoot):
@@ -162,13 +174,12 @@ class Root(RPCRoot):
retentiontag = RetentionTagController()
system_action = SystemActionController()
systems = SystemsController()
- kickstart = KickstartController()
prefs = Preferences()
for entry_point in pkg_resources.iter_entry_points('bkr.controllers'):
controller = entry_point.load()
log.info('Attaching root extension controller %s as %s',
- controller, entry_point.name)
+ controller, entry_point.name)
locals()[entry_point.name] = controller
labinfo_form = LabInfoForm(name='labinfo')
@@ -178,71 +189,71 @@ class Root(RPCRoot):
system_installoptions = SystemInstallOptions(name='installoptions')
task_form = TaskSearchForm(name='tasks')
-
@expose(format='json')
- def get_keyvalue_search_options(self,**kw):
+ def get_keyvalue_search_options(self, **kw):
return_dict = {}
return_dict['keyvals'] = Key.get_all_keys()
return return_dict
@expose(format='json')
- def get_search_options_distros(self,table_field, *args, **kw):
+ def get_search_options_distros(self, table_field, *args, **kw):
return su.Distro.search.get_search_options(table_field, *args, **kw)
@expose(format='json')
- def get_search_options_recipe(self,table_field, *args, **kw):
+ def get_search_options_recipe(self, table_field, *args, **kw):
return su.Recipe.search.get_search_options(table_field, *args, **kw)
@expose(format='json')
- def get_search_options_job(self,table_field, *args, **kw):
+ def get_search_options_job(self, table_field, *args, **kw):
return su.Job.search.get_search_options(table_field, *args, **kw)
@expose(format='json')
- def get_operators_keyvalue(self,keyvalue_field,*args,**kw):
+ def get_operators_keyvalue(self, keyvalue_field, *args, **kw):
return su.Key.search.get_search_options(keyvalue_field, *args, **kw)
@expose(format='json')
- def get_search_options(self,table_field, *args, **kw):
+ def get_search_options(self, table_field, *args, **kw):
return_dict = {}
- search = su.System.search.search_on(table_field)
-
- #Determine what field type we are dealing with. If it is Boolean, convert our values to 0 for False
+ search = su.System.search.search_on(table_field)
+
+ # Determine what field type we are dealing with. If it is Boolean,
+ # convert our values to 0 for False
# and 1 for True
col_type = su.System.search.field_type(table_field)
-
+
if col_type.lower() == 'boolean':
- search['values'] = { 0:'False', 1:'True'}
-
- #Determine if we have search values. If we do, then we should only have the operators
+ search['values'] = {0: 'False', 1: 'True'}
+
+ # Determine if we have search values. If we do, then we should only have the operators
# 'is' and 'is not'.
if search['values']:
- search['operators'] = filter(lambda x: x == 'is' or x == 'is not', search['operators'])
+ search['operators'] = filter(lambda x: x == 'is' or x == 'is not', search['operators'])
search['operators'].sort()
- return_dict['search_by'] = search['operators']
- return_dict['search_vals'] = search['values']
+ return_dict['search_by'] = search['operators']
+ return_dict['search_vals'] = search['values']
return return_dict
@expose(format='json')
def get_fields(self, table_name):
- return dict( fields = System.get_fields(table_name))
-
+ return dict(fields=System.get_fields(table_name))
+
@expose(format='json')
def get_osversions(self, osmajor_id=None):
- osversions = [(0,u'All')]
+ osversions = [(0, u'All')]
try:
osmajor = OSMajor.by_id(osmajor_id)
osversions.extend([(osversion.id,
- osversion.osminor
- ) for osversion in osmajor.osversions])
+ osversion.osminor
+ ) for osversion in osmajor.osversions])
except InvalidRequestError:
pass
- return dict(osversions = osversions)
-
+ return dict(osversions=osversions)
+
@expose(format='json')
def get_installoptions(self, system_id=None, distro_tree_id=None):
try:
- system = System.by_id(system_id,identity.current.user)
+ system = System.by_id(system_id, identity.current.user)
except NoResultFound:
return dict(ks_meta=None)
try:
@@ -256,35 +267,38 @@ class Root(RPCRoot):
def change_priority_recipeset(self, priority, recipeset_id):
user = identity.current.user
if not user:
- return {'success' : None, 'msg' : 'Must be logged in' }
+ return {'success': None, 'msg': 'Must be logged in'}
try:
recipeset = RecipeSet.by_id(recipeset_id)
except NoResultFound as e:
- log.error('No rows returned for recipeset_id %s in change_priority_recipeset:%s' % (recipeset_id,e))
- return { 'success' : None, 'msg' : 'RecipeSet is not valid' }
+ log.error('No rows returned for recipeset_id %s in change_priority_recipeset:%s' % (
+ recipeset_id, e))
+ return {'success': None, 'msg': 'RecipeSet is not valid'}
- try:
+ try:
priority = TaskPriority.from_string(priority)
except ValueError:
log.exception('Invalid priority')
- return { 'success' : None, 'msg' : 'Priority not found', 'current_priority' : recipeset.priority.value }
+ return {'success': None, 'msg': 'Priority not found',
+ 'current_priority': recipeset.priority.value}
if priority not in recipeset.allowed_priorities(user):
- return {'success' : None, 'msg' : 'Insufficient privileges for that priority', 'current_priority' : recipeset.priority.value }
+ return {'success': None, 'msg': 'Insufficient privileges for that priority',
+ 'current_priority': recipeset.priority.value}
old_priority = recipeset.priority.value if recipeset.priority else None
recipeset.priority = priority
recipeset.record_activity(user=identity.current.user, service=u'WEBUI',
field=u'Priority', action=u'Changed', old=old_priority,
new=priority.value)
- return {'success' : True }
+ return {'success': True}
@expose(template='bkr.server.templates.grid')
@expose(template='bkr.server.templates.systems_feed', format='xml', as_format='atom',
content_type='application/atom+xml', accept_format='application/atom+xml')
@paginate('list', default_order='fqdn', limit=20, max_limit=None)
- def index(self, *args, **kw):
+ def index(self, *args, **kw):
return self._systems(systems=System.all(identity.current.user).
filter(System.status != SystemStatus.removed),
title=u'Systems', *args, **kw)
@@ -295,35 +309,35 @@ class Root(RPCRoot):
@identity.require(identity.not_anonymous())
@paginate('list', default_order='fqdn', limit=20, max_limit=None)
def available(self, *args, **kw):
- query = System.all(identity.current.user)\
- .filter(System.can_reserve(identity.current.user))\
- .filter(System.status.in_([SystemStatus.automated, SystemStatus.manual]))
+ query = System.all(identity.current.user) \
+ .filter(System.can_reserve(identity.current.user)) \
+ .filter(System.status.in_([SystemStatus.automated, SystemStatus.manual]))
return self._systems(systems=query,
- title=u'Available Systems', *args, **kw)
+ title=u'Available Systems', *args, **kw)
@expose(template='bkr.server.templates.grid')
@expose(template='bkr.server.templates.systems_feed', format='xml', as_format='atom',
content_type='application/atom+xml', accept_format='application/atom+xml')
@identity.require(identity.not_anonymous())
@paginate('list', default_order='fqdn', limit=20, max_limit=None)
- def free(self, *args, **kw):
- query = System.all(identity.current.user)\
- .filter(System.can_reserve(identity.current.user))\
- .filter(System.status.in_([SystemStatus.automated, SystemStatus.manual]))\
- .filter(System.is_free(identity.current.user))
+ def free(self, *args, **kw):
+ query = System.all(identity.current.user) \
+ .filter(System.can_reserve(identity.current.user)) \
+ .filter(System.status.in_([SystemStatus.automated, SystemStatus.manual])) \
+ .filter(System.is_free(identity.current.user))
return self._systems(systems=query,
- title=u'Free Systems', *args, **kw)
+ title=u'Free Systems', *args, **kw)
@expose(template='bkr.server.templates.grid')
@expose(template='bkr.server.templates.systems_feed', format='xml', as_format='atom',
content_type='application/atom+xml', accept_format='application/atom+xml')
@paginate('list', default_order='fqdn', limit=20, max_limit=None)
- def removed(self, *args, **kw):
- query = System.all(identity.current.user)\
- .filter(System.status == SystemStatus.removed)
- return self._systems(systems=query,
- title=u'Removed Systems', exclude_status=True,
- *args, **kw)
+ def removed(self, *args, **kw):
+ query = System.all(identity.current.user) \
+ .filter(System.status == SystemStatus.removed)
+ return self._systems(systems=query,
+ title=u'Removed Systems', exclude_status=True,
+ *args, **kw)
@expose(template='bkr.server.templates.grid')
@expose(template='bkr.server.templates.systems_feed', format='xml', as_format='atom',
@@ -331,16 +345,15 @@ class Root(RPCRoot):
@identity.require(identity.not_anonymous())
@paginate('list', default_order='fqdn', limit=20, max_limit=None)
def mine(self, *args, **kw):
- systems = System.mine(identity.current.user).\
- filter(System.status != SystemStatus.removed)
+ systems = System.mine(identity.current.user). \
+ filter(System.status != SystemStatus.removed)
return self._systems(systems=systems,
title=u'My Systems', *args, **kw)
-
- @expose(template='bkr.server.templates.grid')
+ @expose(template='bkr.server.templates.grid')
@identity.require(identity.not_anonymous())
- @paginate('list',default_order='fqdn', limit=20)
- def reserve_system(self, *args,**kw):
+ @paginate('list', default_order='fqdn', limit=20)
+ def reserve_system(self, *args, **kw):
if kw.get('distro_tree_id'):
try:
distro_tree = DistroTree.by_id(kw['distro_tree_id'])
@@ -349,20 +362,21 @@ class Root(RPCRoot):
redirect(url('/reserveworkflow/', **kw))
else:
distro_tree = None
- query = System.all(identity.current.user)\
- .filter(System.can_reserve(identity.current.user))\
- .filter(or_(
- System.status == SystemStatus.automated,
- System.status == SystemStatus.manual))
+ query = System.all(identity.current.user) \
+ .filter(System.can_reserve(identity.current.user)) \
+ .filter(or_(
+ System.status == SystemStatus.automated,
+ System.status == SystemStatus.manual))
if distro_tree:
- query = query\
- .filter(System.compatible_with_distro_tree(arch=distro_tree.arch,
- osmajor=distro_tree.distro.osversion.osmajor.osmajor,
- osminor=distro_tree.distro.osversion.osminor))\
- .filter(System.in_lab_with_distro_tree(distro_tree))
+ query = query \
+ .filter(System.compatible_with_distro_tree(arch=distro_tree.arch,
+ osmajor=distro_tree.distro.osversion.osmajor.osmajor,
+ osminor=distro_tree.distro.osversion.osminor)) \
+ .filter(System.in_lab_with_distro_tree(distro_tree))
warn = None
if query.count() < 1:
warn = u'No Systems compatible with %s' % distro_tree
+
def reserve_link(x):
href = url('/reserveworkflow/', system=x.fqdn, **kw)
if x.is_free(identity.current.user):
@@ -373,57 +387,58 @@ class Root(RPCRoot):
a.attrib['class'] = 'btn'
a.text = label
return a
+
direct_column = Utility.direct_column(title='Action', getter=reserve_link)
return_dict = self._systems(systems=query,
- title=u'Reserve Systems', direct_columns=[(8, direct_column)],
- *args, **kw)
+ title=u'Reserve Systems', direct_columns=[(8, direct_column)],
+ *args, **kw)
return_dict['warn_msg'] = warn
return_dict['tg_template'] = "bkr.server.templates.reserve_grid"
return_dict['action'] = '/reserve_system'
return return_dict
- def _history_search(self,activity,**kw):
+ def _history_search(self, activity, **kw):
history_search = su.History.search(activity)
for search in kw['historysearch']:
- col = search['table']
- history_search.append_results(search['value'],col,search['operation'],**kw)
+ col = search['table']
+ history_search.append_results(search['value'], col, search['operation'], **kw)
return history_search.return_results()
- def _system_search(self,kw,sys_search,use_custom_columns = False):
- for search in kw['systemsearch']:
- #clsinfo = System.get_dict()[search['table']] #Need to change this
+ def _system_search(self, kw, sys_search, use_custom_columns=False):
+ for search in kw['systemsearch']:
+ # clsinfo = System.get_dict()[search['table']] #Need to change this
class_field_list = search['table'].split('/')
cls_ref = su.System.search.translate_name_to_class(class_field_list[0])
- col = class_field_list[1]
+ col = class_field_list[1]
value = search.get('value', '')
if class_field_list[0] != 'Key':
sys_search.append_results(cls_ref, value, col, search['operation'])
else:
- sys_search.append_results(cls_ref, value, col, search['operation'], keyvalue=search['keyvalue'])
+ sys_search.append_results(cls_ref, value, col, search['operation'],
+ keyvalue=search['keyvalue'])
return sys_search.return_results()
-
- def histories(self,activity,**kw):
-
- return_dict = {}
+ def histories(self, activity, **kw):
+
+ return_dict = {}
if 'simplesearch' in kw:
simplesearch = kw['simplesearch']
- kw['historysearch'] = [{'table' : 'Field Name',
- 'operation' : 'contains',
- 'value' : kw['simplesearch']}]
-
+ kw['historysearch'] = [{'table': 'Field Name',
+ 'operation': 'contains',
+ 'value': kw['simplesearch']}]
+
else:
simplesearch = None
- return_dict.update({'simplesearch':simplesearch})
+ return_dict.update({'simplesearch': simplesearch})
if kw.get("historysearch"):
- searchvalue = kw['historysearch']
- activities_found = self._history_search(activity,**kw)
- return_dict.update({'activities_found':activities_found})
- return_dict.update({'searchvalue':searchvalue})
+ searchvalue = kw['historysearch']
+ activities_found = self._history_search(activity, **kw)
+ return_dict.update({'activities_found': activities_found})
+ return_dict.update({'searchvalue': searchvalue})
return return_dict
-
+
def _systems(self, systems, title, *args, **kw):
extra_hiddens = {}
@@ -435,67 +450,71 @@ class Root(RPCRoot):
exclude_fields = []
# Added for group.get_systems()
- if kw.has_key('group_id'):
- extra_hiddens={'group_id':kw['group_id']}
+ if 'group_id' in kw:
+ extra_hiddens = {'group_id': kw['group_id']}
# https://bugzilla.redhat.com/show_bug.cgi?id=1154887
- if kw.has_key('distro_tree_id'):
+ if 'distro_tree_id' in kw:
extra_hiddens['distro_tree_id'] = kw['distro_tree_id']
search_bar = SearchBar(name='systemsearch',
label=_(u'System Search'),
- enable_custom_columns = True,
- extra_selects = [ { 'name': 'keyvalue',
- 'column':'key/value',
- 'display':'none',
- 'pos' : 2,
- 'callback':url('/get_operators_keyvalue') }],
- table=su.System.search.create_complete_search_table(\
- [{su.System:{'exclude':exclude_fields}},
- {su.Cpu:{'all':[]}},
- {su.Device:{'all':[]}},
- {su.Disk:{'all':[]}},
- {su.Key:{'all':[]}}]),
+ enable_custom_columns=True,
+ extra_selects=[{'name': 'keyvalue',
+ 'column': 'key/value',
+ 'display': 'none',
+ 'pos': 2,
+ 'callback': url('/get_operators_keyvalue')}],
+ table=su.System.search.create_complete_search_table( \
+ [{su.System: {'exclude': exclude_fields}},
+ {su.Cpu: {'all': []}},
+ {su.Device: {'all': []}},
+ {su.Disk: {'all': []}},
+ {su.Key: {'all': []}}]),
search_controller=url("/get_search_options"),
- date_picker = ['system/added', 'system/lastinventoried', 'system/reserved'],
- table_search_controllers = {'key/value':url('/get_keyvalue_search_options')},)
+ date_picker=['system/added', 'system/lastinventoried',
+ 'system/reserved'],
+ table_search_controllers={
+ 'key/value': url('/get_keyvalue_search_options')}, )
if 'quick_search' in kw:
- table,op,value = kw['quick_search'].split('-')
- kw['systemsearch'] = [{'table' : table,
- 'operation' : op,
- 'keyvalue': None,
- 'value' : value}]
+ table, op, value = kw['quick_search'].split('-')
+ kw['systemsearch'] = [{'table': table,
+ 'operation': op,
+ 'keyvalue': None,
+ 'value': value}]
simplesearch = kw['simplesearch']
elif 'simplesearch' in kw:
simplesearch = kw['simplesearch']
- kw['systemsearch'] = [{'table' : 'System/Name',
- 'operation' : 'contains',
- 'keyvalue' : None,
- 'value' : kw['simplesearch']}]
+ kw['systemsearch'] = [{'table': 'System/Name',
+ 'operation': 'contains',
+ 'keyvalue': None,
+ 'value': kw['simplesearch']}]
else:
simplesearch = None
# Short cut search by type
if 'type' in kw:
- kw['systemsearch'] = [{'table' : 'System/Type',
- 'operation' : 'is',
- 'value' : kw['type']}]
- #when we do a short cut type search, result column args are not passed
- #we need to recreate them here from our cookies
- if 'column_values' in request.simple_cookie:
+ kw['systemsearch'] = [{'table': 'System/Type',
+ 'operation': 'is',
+ 'value': kw['type']}]
+ # when we do a short cut type search, result column args are not passed
+ # we need to recreate them here from our cookies
+ if 'column_values' in request.simple_cookie:
text = request.simple_cookie['column_values'].value
vals_to_set = text.split(',')
for elem in vals_to_set:
- kw['systemsearch_column_%s' % elem] = elem
+ kw['systemsearch_column_%s' % elem] = elem
default_result_columns = kw.get('default_result_columns',
- ('System/Name', 'System/Status', 'System/Vendor',
- 'System/Model','System/Arch', 'System/User', 'System/Type', 'System/LoanedTo'))
+ ('System/Name', 'System/Status', 'System/Vendor',
+ 'System/Model', 'System/Arch', 'System/User',
+ 'System/Type', 'System/LoanedTo'))
if kw.get('xmlsearch'):
try:
- systems = XmlHost.from_string('<and>%s</and>' % kw['xmlsearch']).apply_filter(systems)
- except ValueError,e:
+ systems = XmlHost.from_string('<and>%s</and>' % kw['xmlsearch']).apply_filter(
+ systems)
+ except ValueError, e:
raise PlainTextHTTPException(status=400, message=str(e))
if kw.get("systemsearch"):
@@ -503,60 +522,60 @@ class Root(RPCRoot):
sys_search = su.System.search(systems)
columns = []
for elem in kw:
- if re.match('systemsearch_column_',elem):
+ if re.match('systemsearch_column_', elem):
columns.append(kw[elem])
- if columns.__len__() == 0: #If nothing is selected, let's give them the default
+ if columns.__len__() == 0: # If nothing is selected, let's give them the default
for elem in default_result_columns:
- key = 'systemsearch_column_',elem
+ key = 'systemsearch_column_', elem
kw[key] = elem
columns.append(elem)
use_custom_columns = False
for column in columns:
- table,col = column.split('/')
+ table, col = column.split('/')
if sys_search.translate_name_to_class(table) is not su.System:
use_custom_columns = True
break
sys_search.add_columns_desc(columns)
- systems = self._system_search(kw,sys_search)
+ systems = self._system_search(kw, sys_search)
system_columns_desc = sys_search.get_column_descriptions()
my_fields = Utility.custom_systems_grid(system_columns_desc, use_custom_columns)
else:
columns = None
searchvalue = None
my_fields = Utility.custom_systems_grid(default_result_columns)
- if 'direct_columns' in kw: #Let's add our direct columns here
- for index,col in kw['direct_columns']:
+ if 'direct_columns' in kw: # Let's add our direct columns here
+ for index, col in kw['direct_columns']:
my_fields.insert(index - 1, col)
add_script = None
if not identity.current.anonymous:
add_script = 'new SystemAddModal();'
display_grid = myPaginateDataGrid(fields=my_fields,
- add_script=add_script)
+ add_script=add_script)
col_data = Utility.result_columns(columns)
return dict(title=title,
- grid = display_grid,
- list = systems,
- searchvalue = searchvalue,
- options = {'simplesearch' : simplesearch,
- 'columns':col_data,
- 'result_columns' : default_result_columns,
- 'col_defaults' : col_data['default'],
- 'col_options' : col_data['options'],
- 'extra_hiddens' : extra_hiddens
- },
- action = '',
- search_bar = search_bar,
+ grid=display_grid,
+ list=systems,
+ searchvalue=searchvalue,
+ options={'simplesearch': simplesearch,
+ 'columns': col_data,
+ 'result_columns': default_result_columns,
+ 'col_defaults': col_data['default'],
+ 'col_options': col_data['options'],
+ 'extra_hiddens': extra_hiddens
+ },
+ action='',
+ search_bar=search_bar,
atom_url='?tg_format=atom&list_tgp_order=-date_modified&'
- + cherrypy.request.query_string,
+ + cherrypy.request.query_string,
)
@expose(format='json')
def by_fqdn(self, input):
input = input.lower()
- search = System.list_by_fqdn(input,identity.current.user).all()
- matches = [match.fqdn for match in search]
- return dict(matches = matches)
+ search = System.list_by_fqdn(input, identity.current.user).all()
+ matches = [match.fqdn for match in search]
+ return dict(matches=matches)
@expose()
@identity.require(identity.not_anonymous())
@@ -565,14 +584,14 @@ class Root(RPCRoot):
removed = None
if system_id and key_value_id and key_type:
try:
- system = System.by_id(system_id,identity.current.user)
+ system = System.by_id(system_id, identity.current.user)
except NoResultFound:
- flash(_(u"Invalid Permision"))
+ flash(_(u"Invalid Permission"))
redirect("/")
else:
flash(_(u"system_id, key_value_id and key_type must be provided"))
redirect("/")
-
+
if system.can_edit(identity.current.user):
if key_type == 'int':
key_values = system.key_values_int
@@ -586,33 +605,33 @@ class Root(RPCRoot):
system.key_values_string.remove(key_value)
removed = key_value
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Removed', field=u'Key/Value',
- old=u"%s/%s" % (removed.key.key_name, removed.key_value),
- new=u"")
+ action=u'Removed', field=u'Key/Value',
+ old=u"%s/%s" % (removed.key.key_name, removed.key_value),
+ new=u"")
if removed:
system.date_modified = datetime.utcnow()
- flash(_(u"removed %s/%s" % (removed.key.key_name,removed.key_value)))
+ flash(_(u"removed %s/%s" % (removed.key.key_name, removed.key_value)))
else:
flash(_(u"Key_Value_Id not Found"))
redirect("./view/%s" % system.fqdn)
@expose(template="bkr.server.templates.system")
def _view_system_as_html(self, fqdn=None, **kw):
- if fqdn:
+ if fqdn:
try:
- system = System.by_fqdn(fqdn,identity.current.user)
+ system = System.by_fqdn(fqdn, identity.current.user)
except DatabaseLookupError:
- flash( _(u"Unable to find %s" % fqdn) )
+ flash(_(u"Unable to find %s" % fqdn))
redirect("/")
elif kw.get('id'):
try:
- system = System.by_id(kw['id'],identity.current.user)
+ system = System.by_id(kw['id'], identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to find system with id of %s" % kw['id']) )
+ flash(_(u"Unable to find system with id of %s" % kw['id']))
redirect("/")
else:
- flash( _(u"No given system to view") )
+ flash(_(u"No given system to view"))
redirect("/")
our_user = identity.current.user
if our_user:
@@ -629,19 +648,20 @@ class Root(RPCRoot):
distro_picker_options = {
'tag': [tag.tag for tag in DistroTag.used()],
'osmajor': [osmajor.osmajor for osmajor in
- OSMajor.ordered_by_osmajor(OSMajor.in_lab(system.lab_controller))],
+ OSMajor.ordered_by_osmajor(OSMajor.in_lab(system.lab_controller))],
}
if readonly:
- attrs = dict(readonly = 'True')
+ attrs = dict(readonly='True')
else:
attrs = dict()
options = {}
options['readonly'] = readonly
options['reprovision_distro_tree_id'] = [(dt.id, unicode(dt)) for dt in
- system.distro_trees().order_by(Distro.name,
- DistroTree.variant, DistroTree.arch_id)]
- #Excluded Family options
+ system.distro_trees().order_by(Distro.name,
+ DistroTree.variant,
+ DistroTree.arch_id)]
+ # Excluded Family options
options['excluded_families'] = []
for arch in system.arch:
options['excluded_families'].append((arch.arch,
@@ -654,42 +674,45 @@ class Root(RPCRoot):
# do not return the widget here, the JS will not be loaded,
# return it as an arg in return()
widgets = dict(
- details = self.system_details,
- exclude = self.system_exclude,
- keys = self.system_keys,
- )
+ details=self.system_details,
+ exclude=self.system_exclude,
+ keys=self.system_keys,
+ )
# Lab Info is deprecated, only show it if the system has existing data
widgets['labinfo'] = self.labinfo_form if system.labinfo else None
return dict(
- title = title,
- readonly = readonly,
- value = system,
- options = options,
- task_widget = self.task_form,
- install_widget = self.system_installoptions,
- widgets = widgets,
- widgets_action = dict( labinfo = url('/save_labinfo'),
- exclude = url('/save_exclude'),
- keys = url('/save_keys'),
- install = url('/save_install'),
- tasks = '/tasks/do_search',
- ),
- widgets_options = dict(labinfo = options,
- exclude = options,
- keys = dict(readonly = readonly,
- key_values_int = system.key_values_int,
- key_values_string = system.key_values_string),
- install = dict(readonly = readonly,
- provisions = system.provisions,
- prov_arch = [(arch.id, arch.arch) for arch in system.arch]),
- tasks = dict(system_id = system.id,
- arch = [(0, 'All')] + [(arch.id, arch.arch) for arch in system.arch],
- hidden = dict(system = 1)),
- distro_picker=distro_picker_options,
- ),
+ title=title,
+ readonly=readonly,
+ value=system,
+ options=options,
+ task_widget=self.task_form,
+ install_widget=self.system_installoptions,
+ widgets=widgets,
+ widgets_action=dict(labinfo=url('/save_labinfo'),
+ exclude=url('/save_exclude'),
+ keys=url('/save_keys'),
+ install=url('/save_install'),
+ tasks='/tasks/do_search',
+ ),
+ widgets_options=dict(labinfo=options,
+ exclude=options,
+ keys=dict(readonly=readonly,
+ key_values_int=system.key_values_int,
+ key_values_string=system.key_values_string),
+ install=dict(readonly=readonly,
+ provisions=system.provisions,
+ prov_arch=[(arch.id, arch.arch) for arch in
+ system.arch]),
+ tasks=dict(system_id=system.id,
+ arch=[(0, 'All')] + [(arch.id, arch.arch) for arch in
+ system.arch],
+ hidden=dict(system=1)),
+ distro_picker=distro_picker_options,
+ ),
)
- _view_system_as_html.exposed = False # exposed indirectly by view()
+
+ _view_system_as_html.exposed = False # exposed indirectly by view()
def _view_system_as_rdf(self, fqdn, **kwargs):
try:
@@ -709,7 +732,7 @@ class Root(RPCRoot):
@cherrypy.expose
def view(self, fqdn=None, **kwargs):
if isinstance(fqdn, str):
- fqdn = fqdn.decode('utf8') # for virtual paths like /view/asdf.example.com
+ fqdn = fqdn.decode('utf8') # for virtual paths like /view/asdf.example.com
# XXX content negotiation too?
tg_format = kwargs.get('tg_format', 'html')
if tg_format in ('rdfxml', 'turtle'):
@@ -723,9 +746,9 @@ class Root(RPCRoot):
@validate(form=labinfo_form)
def save_labinfo(self, **kw):
try:
- system = System.by_id(kw['id'],identity.current.user)
+ system = System.by_id(kw['id'], identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to save Lab Info for %s" % kw['id']) )
+ flash(_(u"Unable to save Lab Info for %s" % kw['id']))
redirect("/")
if system.labinfo:
labinfo = system.labinfo
@@ -742,39 +765,39 @@ class Root(RPCRoot):
new_value = kw[field]
if new_value != orig_value:
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Changed', field=field,
- old=u'%s' % orig_value, new=kw[field])
+ action=u'Changed', field=field,
+ old=u'%s' % orig_value, new=kw[field])
setattr(labinfo, field, kw[field])
system.labinfo = labinfo
system.date_modified = datetime.utcnow()
- flash( _(u"Saved Lab Info") )
+ flash(_(u"Saved Lab Info"))
redirect("/view/%s" % system.fqdn)
@expose()
@identity.require(identity.not_anonymous())
def save_keys(self, id, **kw):
try:
- system = System.by_id(id,identity.current.user)
+ system = System.by_id(id, identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to Add Key for %s" % id) )
+ flash(_(u"Unable to Add Key for %s" % id))
redirect("/")
# Add a Key/Value Pair
if kw.get('key_name') and kw.get('key_value'):
try:
key = Key.by_name(kw['key_name'])
except InvalidRequestError:
- #FIXME allow user to create new keys
+ # FIXME allow user to create new keys
flash(_(u"Invalid key %s" % kw['key_name']))
redirect("/view/%s" % system.fqdn)
if key.numeric:
- key_value = Key_Value_Int(key,kw['key_value'])
+ key_value = Key_Value_Int(key, kw['key_value'])
system.key_values_int.append(key_value)
else:
- key_value = Key_Value_String(key,kw['key_value'])
+ key_value = Key_Value_String(key, kw['key_value'])
system.key_values_string.append(key_value)
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Added', field=u'Key/Value', old=u"",
- new=u"%s/%s" % (kw['key_name'],kw['key_value']))
+ action=u'Added', field=u'Key/Value', old=u"",
+ new=u"%s/%s" % (kw['key_name'], kw['key_value']))
system.date_modified = datetime.utcnow()
redirect("/view/%s" % system.fqdn)
@@ -782,54 +805,61 @@ class Root(RPCRoot):
@identity.require(identity.not_anonymous())
def save_exclude(self, id, **kw):
try:
- system = System.by_id(id,identity.current.user)
+ system = System.by_id(id, identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to save Exclude flags for %s" % id) )
+ flash(_(u"Unable to save Exclude flags for %s" % id))
redirect("/")
for arch in system.arch:
- # Update Excluded Families
- if kw.get('excluded_families') and \
- kw['excluded_families'].has_key(arch.arch):
+ # Update Excluded Families
+ if kw.get('excluded_families') and arch.arch in kw['excluded_families']:
if isinstance(kw['excluded_families'][arch.arch], list):
excluded_osmajor = [int(i) for i in kw['excluded_families'][arch.arch]]
else:
excluded_osmajor = [int(kw['excluded_families'][arch.arch])]
for new_families in excluded_osmajor:
- if new_families not in [osmajor.osmajor.id for osmajor in system.excluded_osmajor_byarch(arch)]:
- new_excluded_osmajor = ExcludeOSMajor(osmajor=OSMajor.by_id(new_families),arch=arch)
+ if new_families not in [osmajor.osmajor.id for osmajor in
+ system.excluded_osmajor_byarch(arch)]:
+ new_excluded_osmajor = ExcludeOSMajor(osmajor=OSMajor.by_id(new_families),
+ arch=arch)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Added', field=u'Excluded_families',
- old=u"", new=u"%s/%s" % (new_excluded_osmajor.osmajor, arch))
+ service=u'WEBUI', action=u'Added',
+ field=u'Excluded_families',
+ old=u"",
+ new=u"%s/%s" % (new_excluded_osmajor.osmajor, arch))
system.excluded_osmajor.append(new_excluded_osmajor)
else:
excluded_osmajor = []
for old_families in system.excluded_osmajor_byarch(arch):
if old_families.osmajor.id not in excluded_osmajor:
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Removed', field=u'Excluded_families',
- old=u"%s/%s" % (old_families.osmajor, arch), new=u"")
+ action=u'Removed', field=u'Excluded_families',
+ old=u"%s/%s" % (old_families.osmajor, arch), new=u"")
session.delete(old_families)
- if kw.get('excluded_families_subsection') and \
- kw['excluded_families_subsection'].has_key(arch.arch):
+ if (kw.get('excluded_families_subsection') and
+ arch.arch in kw['excluded_families_subsection']):
if isinstance(kw['excluded_families_subsection'][arch.arch], list):
- excluded_osversion = [int(i) for i in kw['excluded_families_subsection'][arch.arch]]
+ excluded_osversion = [int(i) for i in
+ kw['excluded_families_subsection'][arch.arch]]
else:
excluded_osversion = [int(kw['excluded_families_subsection'][arch.arch])]
for new_osversion in excluded_osversion:
- if new_osversion not in [osversion.osversion.id for osversion in system.excluded_osversion_byarch(arch)]:
- new_excluded_osversion = ExcludeOSVersion(osversion=OSVersion.by_id(new_osversion),arch=arch)
+ if new_osversion not in [osversion.osversion.id for osversion in
+ system.excluded_osversion_byarch(arch)]:
+ new_excluded_osversion = ExcludeOSVersion(
+ osversion=OSVersion.by_id(new_osversion), arch=arch)
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Added', field=u'Excluded_families',
- old=u"", new=u"%s/%s" % (new_excluded_osversion.osversion, arch))
+ action=u'Added', field=u'Excluded_families',
+ old=u"", new=u"%s/%s" % (
+ new_excluded_osversion.osversion, arch))
system.excluded_osversion.append(new_excluded_osversion)
else:
excluded_osversion = []
for old_osversion in system.excluded_osversion_byarch(arch):
if old_osversion.osversion.id not in excluded_osversion:
system.record_activity(user=identity.current.user, service=u'WEBUI',
- action=u'Removed', field=u'Excluded_families',
- old=u"%s/%s" % (old_osversion.osversion, arch), new=u"")
+ action=u'Removed', field=u'Excluded_families',
+ old=u"%s/%s" % (old_osversion.osversion, arch), new=u"")
session.delete(old_osversion)
redirect("/view/%s" % system.fqdn)
@@ -840,64 +870,69 @@ class Root(RPCRoot):
try:
system = System.by_id(system_id, identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to remove Install Option for %s" % system_id) )
+ flash(_(u"Unable to remove Install Option for %s" % system_id))
redirect("/")
try:
arch = Arch.by_id(arch_id)
except InvalidRequestError:
- flash( _(u"Unable to lookup arch for %s" % arch_id) )
+ flash(_(u"Unable to lookup arch for %s" % arch_id))
redirect("/")
-
+
if kw.get('osversion_id'):
# remove osversion option
osversion = OSVersion.by_id(int(kw['osversion_id']))
- prov = system.provisions[arch].provision_families[osversion.osmajor]\
- .provision_family_updates[osversion]
+ prov = system.provisions[arch].provision_families[osversion.osmajor] \
+ .provision_family_updates[osversion]
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:ks_meta:%s/%s' % (arch, osversion),
- old=prov.ks_meta, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:ks_meta:%s/%s' % (arch, osversion),
+ old=prov.ks_meta, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options:%s/%s' % (arch, osversion),
- old=prov.kernel_options, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options:%s/%s' % (arch, osversion),
+ old=prov.kernel_options, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options_post:%s/%s' % (arch, osversion),
- old=prov.kernel_options_post, new=None)
- del system.provisions[arch].provision_families[osversion.osmajor].provision_family_updates[osversion]
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options_post:%s/%s' % (
+ arch, osversion),
+ old=prov.kernel_options_post, new=None)
+ del \
+ system.provisions[arch].provision_families[
+ osversion.osmajor].provision_family_updates[
+ osversion]
elif kw.get('osmajor_id'):
# remove osmajor option
osmajor = OSMajor.by_id(int(kw['osmajor_id']))
prov = system.provisions[arch].provision_families[osmajor]
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:ks_meta:%s/%s' % (arch, osmajor),
- old=prov.ks_meta, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:ks_meta:%s/%s' % (arch, osmajor),
+ old=prov.ks_meta, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options:%s/%s' % (arch, osmajor),
- old=prov.kernel_options, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options:%s/%s' % (arch, osmajor),
+ old=prov.kernel_options, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options_post:%s/%s' % (arch, osmajor),
- old=prov.kernel_options_post, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options_post:%s/%s' % (
+ arch, osmajor),
+ old=prov.kernel_options_post, new=None)
del system.provisions[arch].provision_families[osmajor]
else:
# remove arch option
prov = system.provisions[arch]
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:ks_meta:%s' % arch,
- old=prov.ks_meta, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:ks_meta:%s' % arch,
+ old=prov.ks_meta, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options:%s' % arch,
- old=prov.kernel_options, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options:%s' % arch,
+ old=prov.kernel_options, new=None)
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=u'Removed',
- field=u'InstallOption:kernel_options_post:%s' % arch,
- old=prov.kernel_options_post, new=None)
+ service=u'WEBUI', action=u'Removed',
+ field=u'InstallOption:kernel_options_post:%s' % arch,
+ old=prov.kernel_options_post, new=None)
del system.provisions[arch]
system.date_modified = datetime.utcnow()
redirect("/view/%s" % system.fqdn)
@@ -906,91 +941,103 @@ class Root(RPCRoot):
@identity.require(identity.not_anonymous())
def save_install(self, id, **kw):
try:
- system = System.by_id(id,identity.current.user)
+ system = System.by_id(id, identity.current.user)
except InvalidRequestError:
- flash( _(u"Unable to save Install Options for %s" % id) )
+ flash(_(u"Unable to save Install Options for %s" % id))
redirect("/")
# Add an install option
if kw.get('prov_ksmeta') or kw.get('prov_koptions') or \
- kw.get('prov_koptionspost'):
+ kw.get('prov_koptionspost'):
arch = Arch.by_id(int(kw['prov_arch']))
if int(kw['prov_osversion']) != 0:
osversion = OSVersion.by_id(int(kw['prov_osversion']))
- if system.provisions.has_key(arch):
- if system.provisions[arch].provision_families.has_key(osversion.osmajor):
- if system.provisions[arch].provision_families[osversion.osmajor].provision_family_updates.has_key(osversion):
- provision = system.provisions[arch].provision_families[osversion.osmajor].provision_family_updates[osversion]
+ if arch in system.provisions:
+ if osversion.osmajor in system.provisions[arch].provision_families:
+ if osversion in system.provisions[arch].provision_families[
+ osversion.osmajor].provision_family_updates:
+ provision = system.provisions[arch].provision_families[
+ osversion.osmajor].provision_family_updates[osversion]
action = u"Changed"
else:
provision = ProvisionFamilyUpdate()
action = u"Added"
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:ks_meta:%s/%s' % (arch, osversion),
- old=provision.ks_meta, new=kw['prov_ksmeta'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:ks_meta:%s/%s'
+ % (arch, osversion),
+ old=provision.ks_meta, new=kw['prov_ksmeta'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options:%s/%s' % (arch, osversion),
- old=provision.kernel_options, new=kw['prov_koptions'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options:%s/%s'
+ % (arch, osversion),
+ old=provision.kernel_options,
+ new=kw['prov_koptions'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options_post:%s/%s' % (arch, osversion),
- old=provision.kernel_options_post, new=kw['prov_koptionspost'])
- provision.ks_meta=kw['prov_ksmeta']
- provision.kernel_options=kw['prov_koptions']
- provision.kernel_options_post=kw['prov_koptionspost']
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options_post:%s/%s'
+ % (arch, osversion),
+ old=provision.kernel_options_post,
+ new=kw['prov_koptionspost'])
+ provision.ks_meta = kw['prov_ksmeta']
+ provision.kernel_options = kw['prov_koptions']
+ provision.kernel_options_post = kw['prov_koptionspost']
provision.osversion = osversion
- system.provisions[arch].provision_families[osversion.osmajor].provision_family_updates[osversion] = provision
-
+ system.provisions[arch].provision_families[
+ osversion.osmajor].provision_family_updates[osversion] = provision
+
elif int(kw['prov_osmajor']) != 0:
osmajor = OSMajor.by_id(int(kw['prov_osmajor']))
- if system.provisions.has_key(arch):
- if system.provisions[arch].provision_families.has_key(osmajor):
+ if arch in system.provisions:
+ if osmajor in system.provisions[arch].provision_families:
provision = system.provisions[arch].provision_families[osmajor]
action = u"Changed"
else:
provision = ProvisionFamily()
action = u"Added"
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:ks_meta:%s/%s' % (arch, osmajor),
- old=provision.ks_meta, new=kw['prov_ksmeta'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:ks_meta:%s/%s' % (arch, osmajor),
+ old=provision.ks_meta, new=kw['prov_ksmeta'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options:%s/%s' % (arch, osmajor),
- old=provision.kernel_options, new=kw['prov_koptions'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options:%s/%s' % (
+ arch, osmajor),
+ old=provision.kernel_options, new=kw['prov_koptions'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options_post:%s/%s' % (arch, osmajor),
- old=provision.kernel_options_post, new=kw['prov_koptionspost'])
- provision.ks_meta=kw['prov_ksmeta']
- provision.kernel_options=kw['prov_koptions']
- provision.kernel_options_post=kw['prov_koptionspost']
- provision.osmajor=osmajor
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options_post:%s/%s' % (
+ arch, osmajor),
+ old=provision.kernel_options_post,
+ new=kw['prov_koptionspost'])
+ provision.ks_meta = kw['prov_ksmeta']
+ provision.kernel_options = kw['prov_koptions']
+ provision.kernel_options_post = kw['prov_koptionspost']
+ provision.osmajor = osmajor
system.provisions[arch].provision_families[osmajor] = provision
else:
- if system.provisions.has_key(arch):
+ if arch in system.provisions:
provision = system.provisions[arch]
action = "Changed"
else:
provision = Provision()
action = "Added"
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:ks_meta:%s' % arch,
- old=provision.ks_meta, new=kw['prov_ksmeta'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:ks_meta:%s' % arch,
+ old=provision.ks_meta, new=kw['prov_ksmeta'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options:%s' % arch,
- old=provision.kernel_options, new=kw['prov_koptions'])
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options:%s' % arch,
+ old=provision.kernel_options, new=kw['prov_koptions'])
system.record_activity(user=identity.current.user,
- service=u'WEBUI', action=action,
- field=u'InstallOption:kernel_options_post:%s' % arch,
- old=provision.kernel_options_post, new=kw['prov_koptionspost'])
- provision.ks_meta=kw['prov_ksmeta']
- provision.kernel_options=kw['prov_koptions']
- provision.kernel_options_post=kw['prov_koptionspost']
- provision.arch=arch
+ service=u'WEBUI', action=action,
+ field=u'InstallOption:kernel_options_post:%s' % arch,
+ old=provision.kernel_options_post,
+ new=kw['prov_koptionspost'])
+ provision.ks_meta = kw['prov_ksmeta']
+ provision.kernel_options = kw['prov_koptions']
+ provision.kernel_options_post = kw['prov_koptionspost']
+ provision.arch = arch
system.provisions[arch] = provision
system.date_modified = datetime.utcnow()
redirect("/view/%s" % system.fqdn)
@@ -1003,9 +1050,9 @@ class Root(RPCRoot):
@cherrypy.expose
def legacypush(self, fqdn=None, inventory=None):
if not fqdn:
- return (0,"You must supply a FQDN")
+ return 0, "You must supply a FQDN"
if not inventory:
- return (0,"No inventory data provided")
+ return 0, "No inventory data provided"
try:
system = System.query.filter(System.fqdn == fqdn.decode('ascii')).one()
@@ -1022,22 +1069,22 @@ class Root(RPCRoot):
redirect(url('/'))
xml_text = lxml.etree.tostring(task.to_xml(), pretty_print=pretty, encoding='utf8')
- if to_screen: #used for testing contents of XML
+ if to_screen: # used for testing contents of XML
cherrypy.response.headers['Content-Disposition'] = ''
cherrypy.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
else:
- cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=%s.xml' % taskid
+ cherrypy.response.headers[
+ 'Content-Disposition'] = 'attachment; filename=%s.xml' % taskid
cherrypy.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
return xml_text
-
@cherrypy.expose
def push(self, fqdn=None, inventory=None):
if not fqdn:
- return (0,"You must supply a FQDN")
+ return 0, "You must supply a FQDN"
if not inventory:
- return (0,"No inventory data provided")
+ return 0, "No inventory data provided"
try:
system = System.query.filter(System.fqdn == fqdn.decode('ascii')).one()
except InvalidRequestError:
@@ -1053,7 +1100,7 @@ class Root(RPCRoot):
def login(self, forward_url=None, **kwargs):
if not forward_url:
forward_url = url('/')
- # If the container is doing authentication for us, we might have
+ # If the container is doing authentication for us, we might have
# already been authenticated through REMOTE_USER.
if not identity.current.anonymous:
raise cherrypy.HTTPRedirect(forward_url)
@@ -1082,18 +1129,26 @@ class Root(RPCRoot):
def robots_txt(self):
return "User-agent: *\nDisallow: /\n"
+
@app.route('/favicon.ico', methods=['GET'])
def favicon_ico():
return flask_redirect(absolute_url('/assets/favicon.ico'))
+
_startup_time = None
+
+
def startup_time_start():
global _startup_time
_startup_time = time.time()
+
+
def startup_time_end():
duration = time.time() - _startup_time
log.info('Server startup in %s seconds' % duration)
metrics.measure('durations.cherrypy_startup', duration)
metrics.increment('counters.cherrypy_startup')
+
+
cherrypy.server.on_start_server_list.insert(0, startup_time_start)
cherrypy.server.on_start_server_list.append(startup_time_end)
diff --git a/Server/bkr/server/kickstart.py b/Server/bkr/server/kickstart.py
index 5282551..ad4af4e 100644
--- a/Server/bkr/server/kickstart.py
+++ b/Server/bkr/server/kickstart.py
@@ -1,28 +1,30 @@
-
# 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.
-import string
+import logging
+import pipes # For pipes.quote, since it isn't available in shlex until 3.3
import re
+import string
import urlparse
-import logging
+
+import jinja2.ext
+import jinja2.nodes
+import jinja2.sandbox
import netaddr
-import pipes # For pipes.quote, since it isn't available in shlex until 3.3
+from flask import redirect, abort
from sqlalchemy.orm.exc import NoResultFound
-from turbogears import config, redirect
-from turbogears.controllers import expose
-import cherrypy
-import jinja2.sandbox, jinja2.ext, jinja2.nodes
-from bkr.server.model import session, RenderedKickstart, OSMajor, OSVersion
-from bkr.server.util import absolute_url
+
+from bkr.server.app import app
+from bkr.server.model import session, RenderedKickstart
from bkr.server.model.distrolibrary import split_osmajor_name_version
+from bkr.server.util import absolute_url
log = logging.getLogger(__name__)
-class SnippetExtension(jinja2.ext.Extension):
+class SnippetExtension(jinja2.ext.Extension):
"""
An extension which defines a block-level snippet statement::
@@ -42,19 +44,21 @@ class SnippetExtension(jinja2.ext.Extension):
snippet_name = parser.parse_expression()
node = jinja2.nodes.Output([
jinja2.nodes.Call(jinja2.nodes.Name('snippet', 'load'),
- [snippet_name], [], None, None),
+ [snippet_name], [], None, None),
])
node.set_lineno(lineno)
return node
+
template_env = jinja2.sandbox.SandboxedEnvironment(
- cache_size=0, # https://bugzilla.redhat.com/show_bug.cgi?id=862235
- loader=jinja2.ChoiceLoader([
- jinja2.FileSystemLoader('/etc/beaker'),
- jinja2.PackageLoader('bkr.server', ''),
- ]),
- trim_blocks=True,
- extensions=[SnippetExtension])
+ cache_size=0, # https://bugzilla.redhat.com/show_bug.cgi?id=862235
+ loader=jinja2.ChoiceLoader([
+ jinja2.FileSystemLoader('/etc/beaker'),
+ jinja2.PackageLoader('bkr.server', ''),
+ ]),
+ trim_blocks=True,
+ extensions=[SnippetExtension])
+
def add_to_template_searchpath(dir):
"""Adds a new searchpath to our template_env var
@@ -63,6 +67,7 @@ def add_to_template_searchpath(dir):
searchpath
"""
global template_env
+
def _add_template(loaders, dir):
for loader in loaders:
# Let's squeeze a new FS path in
@@ -73,6 +78,7 @@ def add_to_template_searchpath(dir):
_add_template(loader.loaders, dir)
else:
continue
+
_add_template([template_env.loader], dir)
@@ -85,19 +91,22 @@ class TemplateRenderingEnvironment(object):
or snippet from wreaking too much havoc. User-supplied templates are not
allowed to access our model objects at all so they are not a concern.
"""
+
def __enter__(self):
# Can't do this without a CherryPy request :-(
- #self.saved_identity = identity.current
- #identity.set_current_identity(None)
+ # self.saved_identity = identity.current
+ # identity.set_current_identity(None)
session.begin_nested()
+
def __exit__(self, exc_type, exc_val, exc_tb):
session.rollback()
- #identity.set_current_identity(self.saved_identity)
+ # identity.set_current_identity(self.saved_identity)
+
-# For user-supplied templates we only expose these "fake" objects which wrap
-# real model objects, providing only safe documented attributes. Otherwise
-# users could invoke arbitrary methods on the model objects which we don't
-# want. Server templates (controlled by the admin) on the other hand have
+# For user-supplied templates we only expose these "fake" objects which wrap
+# real model objects, providing only safe documented attributes. Otherwise
+# users could invoke arbitrary methods on the model objects which we don't
+# want. Server templates (controlled by the admin) on the other hand have
# access to the real model objects because it is more powerful.
class RestrictedOSMajor(object):
def __init__(self, osmajor, name=None, number=None):
@@ -105,6 +114,8 @@ class RestrictedOSMajor(object):
name, number = split_osmajor_name_version(osmajor)
self.name = unicode(name)
self.number = unicode(number)
+
+
class RestrictedOSVersion(object):
def __init__(self, osmajor, osminor):
self.osmajor = RestrictedOSMajor(osmajor)
@@ -112,13 +123,19 @@ class RestrictedOSVersion(object):
self.osminor = None
else:
self.osminor = unicode(osminor)
+
+
class RestrictedDistro(object):
def __init__(self, osmajor, osminor, name):
self.osversion = RestrictedOSVersion(osmajor, osminor)
self.name = unicode(name)
+
+
class RestrictedArch(object):
def __init__(self, arch):
self.arch = unicode(arch)
+
+
class RestrictedDistroTree(object):
def __init__(self, osmajor, osminor, name, variant, arch, tree_url, distro_tree=None):
self.distro = RestrictedDistro(osmajor, osminor, name)
@@ -138,15 +155,19 @@ class RestrictedDistroTree(object):
else:
return self.tree_url
+
class RestrictedLabController(object):
def __init__(self, lab_controller):
self.fqdn = unicode(lab_controller.fqdn)
+
+
class RestrictedRecipe(object):
def __init__(self, recipe):
self.id = recipe.id
self.whiteboard = recipe.whiteboard
self.role = recipe.role
+
# Some custom Jinja template filters and tests,
# for added convenience when writing kickstart/snippet templates
# http://jinja.pocoo.org/docs/api/#custom-filters
@@ -155,6 +176,7 @@ class RestrictedRecipe(object):
def dictsplit(s, delim=',', pairsep=':'):
return dict(pair.split(pairsep, 1) for pair in s.split(delim))
+
template_env.filters.update({
'split': string.split,
'dictsplit': dictsplit,
@@ -163,26 +185,32 @@ template_env.filters.update({
'shell_quoted': pipes.quote,
})
+
def is_arch(distro_tree, *arch_names):
return distro_tree.arch.arch in arch_names
+
def is_osmajor(distro, *osmajor_names):
return distro.osversion.osmajor.osmajor in osmajor_names
+
def is_osversion(distro, *osversion_names):
return (u'%s.%s' % (distro.osversion.osmajor.osmajor, distro.osversion.osminor)
in osversion_names)
+
template_env.tests.update({
'arch': is_arch,
'osmajor': is_osmajor,
'osversion': is_osversion,
})
+
@jinja2.contextfunction
def var(context, name):
return context.resolve(name)
+
template_env.globals.update({
're': re,
'netaddr': netaddr,
@@ -192,6 +220,7 @@ template_env.globals.update({
'absolute_url': absolute_url,
})
+
def kickstart_template(osmajor):
candidates = [
'kickstarts/%s' % osmajor,
@@ -206,8 +235,9 @@ def kickstart_template(osmajor):
raise ValueError('No kickstart template found for %s, tried: %s'
% (osmajor, ', '.join(candidates)))
+
def generate_kickstart(install_options, distro_tree, system, user,
- recipe=None, ks_appends=None, kickstart=None, installation=None):
+ recipe=None, ks_appends=None, kickstart=None, installation=None):
if recipe:
lab_controller = recipe.recipeset.lab_controller
elif system:
@@ -231,7 +261,8 @@ def generate_kickstart(install_options, distro_tree, system, user,
'job_whiteboard': job_whiteboard,
'distro_tree': RestrictedDistroTree(installation.osmajor, installation.osminor,
installation.distro_name, installation.variant,
- installation.arch.arch, installation.tree_url, distro_tree),
+ installation.arch.arch, installation.tree_url,
+ distro_tree),
'distro': RestrictedDistro(installation.osmajor, installation.osminor,
installation.distro_name),
'lab_controller': RestrictedLabController(lab_controller),
@@ -248,7 +279,7 @@ def generate_kickstart(install_options, distro_tree, system, user,
'lab_controller': lab_controller,
'user': user,
'recipe': recipe,
- 'config': config,
+ 'config': app.config,
})
if distro_tree:
context.update({
@@ -267,8 +298,7 @@ def generate_kickstart(install_options, distro_tree, system, user,
snippet_locations = []
if system:
- snippet_locations.append(
- 'snippets/per_system/%%s/%s' % system.fqdn)
+ snippet_locations.append('snippets/per_system/%%s/%s' % system.fqdn)
snippet_locations.extend([
'snippets/per_lab/%%s/%s' % lab_controller.fqdn,
'snippets/per_osversion/%%s/%s.%s' % (installation.osmajor, installation.osminor),
@@ -292,13 +322,14 @@ def generate_kickstart(install_options, distro_tree, system, user,
return retval
else:
return u'# no snippet data for %s\n' % name
+
restricted_context['snippet'] = snippet
context['snippet'] = snippet
with TemplateRenderingEnvironment():
if kickstart:
template = template_env.from_string(
- "{% snippet 'install_method' %}\n" + kickstart)
+ "{% snippet 'install_method' %}\n" + kickstart)
result = template.render(restricted_context)
else:
template = kickstart_template(installation.osmajor)
@@ -306,21 +337,17 @@ def generate_kickstart(install_options, distro_tree, system, user,
rendered_kickstart = RenderedKickstart(kickstart=result)
session.add(rendered_kickstart)
- session.flush() # so that it has an id
+ session.flush() # so that it has an id
return rendered_kickstart
-class KickstartController(object):
+@app.route('/kickstart/<id>', methods=['GET'])
+def get_kickstart(id):
"""
- TurboGears controller for serving up generated kickstarts.
+ Flask endpoint for serving up generated kickstarts.
"""
-
- @expose(content_type='text/plain; charset=UTF-8')
- def default(self, id):
- try:
- kickstart = RenderedKickstart.by_id(id)
- except NoResultFound:
- raise cherrypy.NotFound(id)
- if kickstart.url:
- redirect(kickstart.url)
- return kickstart.kickstart.encode('utf8')
+ try:
+ kickstart = RenderedKickstart.by_id(id)
+ except NoResultFound:
+ abort(404)
+ return redirect(kickstart.url) if kickstart.url else kickstart.kickstart.encode('utf8')
diff --git a/Server/bkr/server/util.py b/Server/bkr/server/util.py
index 68ca60c..6eb46a5 100644
--- a/Server/bkr/server/util.py
+++ b/Server/bkr/server/util.py
@@ -1,4 +1,3 @@
-
# 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
@@ -8,26 +7,30 @@
Random functions that don't fit elsewhere
"""
-import os
-import sys
+import contextlib
import logging
+import os
+import re
import socket
import subprocess
-import lxml.etree
+import sys
from collections import namedtuple
+
+import lxml.etree
+import turbogears
from sqlalchemy import create_engine
from sqlalchemy.orm.exc import NoResultFound
-import turbogears
from turbogears import config, url
from turbogears.database import get_engine
-import re
-import contextlib
+
+from bkr.server.app import app
from bkr.server.bexceptions import DatabaseLookupError
log = logging.getLogger(__name__)
_config_loaded = None
+
def load_config_or_exit(configfile=None):
try:
load_config(configfile=configfile)
@@ -36,8 +39,11 @@ def load_config_or_exit(configfile=None):
'Hint: run this command as root\n' % e)
sys.exit(1)
+
def load_config(configfile=None):
- """ Loads Beaker's configuration and configures logging. """
+ """
+ Loads Beaker's configuration and configures logging.
+ """
setupdir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
curdir = os.getcwd()
if configfile and os.path.exists(configfile):
@@ -65,62 +71,71 @@ def load_config(configfile=None):
return
elif _config_loaded is not None and configfile != _config_loaded:
raise RuntimeError('Config has already been loaded from %s' % \
- _config_loaded)
+ _config_loaded)
- # In general, we want all messages from application code, but no debugging
+ # In general, we want all messages from application code, but no debugging
# messages from the libraries we are using.
logging.getLogger().setLevel(logging.INFO)
logging.getLogger('bkr').setLevel(logging.DEBUG)
# We don't need access logs from TurboGears, we have the Apache logs.
logging.getLogger('turbogears.access').setLevel(logging.WARN)
- # Note that the actual level of log output is controlled by the handlers,
- # not the loggers (for example command line tools will typically log to
- # stderr at WARNING level). The main entry point for the program should
+ # Note that the actual level of log output is controlled by the handlers,
+ # not the loggers (for example command line tools will typically log to
+ # stderr at WARNING level). The main entry point for the program should
# call bkr.log.log_to_{syslog,stream} to set up a handler.
- # We do not want TurboGears to touch the logging config, so let's
- # double-check the user hasn't left an old [logging] section in their
+ # We do not want TurboGears to touch the logging config, so let's
+ # double-check the user hasn't left an old [logging] section in their
# config file.
from configobj import ConfigObj
configdata = ConfigObj(configfile, unrepr=True)
- if configdata.has_key('logging'):
+ if 'logging' in configdata:
raise RuntimeError('TurboGears logging configuration is not supported, '
- 'remove [logging] section from config file %s' % configfile)
+ 'remove [logging] section from config file %s' % configfile)
+ if not 'global' in configdata:
+ raise RuntimeError('Config file is missing section [global]')
+ # Read our beaker config and store it to Flask config
+ app.config.update(configdata['global'])
+ # Keep this until we completely remove TurboGears
turbogears.update_config(configfile=configfile, modulename="bkr.server.config")
_config_loaded = configfile
+
def to_unicode(obj, encoding='utf-8'):
+ # TODO: Not needed for Python 3
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding, 'replace')
return obj
+
def strip_webpath(url):
webpath = (config.get('server.webpath') or '').rstrip('/')
if webpath and url.startswith(webpath):
return url[len(webpath):]
return url
+
# TG1.1 has this: http://docs.turbogears.org/1.1/URLs#turbogears-absolute-url
-def absolute_url(tgpath, tgparams=None, scheme=None,
+def absolute_url(tgpath, tgparams=None, scheme=None,
labdomain=False, webpath=True, **kw):
"""
- Like turbogears.url, but makes the URL absolute (with scheme, hostname,
- and port from the tg.url_scheme and tg.url_domain configuration
+ Like turbogears.url, but makes the URL absolute (with scheme, hostname,
+ and port from the tg.url_scheme and tg.url_domain configuration
directives).
If labdomain is True we serve an alternate tg.proxy_domain if defined
in server.cfg. This is to support multi-home systems which have
different external vs internal names.
"""
- if labdomain and config.get('tg.lab_domain'):
- host_port = config.get('tg.lab_domain')
- elif config.get('tg.url_domain'):
- host_port = config.get('tg.url_domain')
- elif config.get('servername'): # deprecated
- host_port = config.get('servername')
+ if labdomain and app.config.get('tg.lab_domain'):
+ host_port = app.config.get('tg.lab_domain')
+ elif app.config.get('tg.url_domain'):
+ host_port = app.config.get('tg.url_domain')
+ elif app.config.get('servername'): # deprecated
+ host_port = app.config.get('servername')
else:
- # System hostname is cheap to look up (no DNS calls) but there is no
+ # System hostname is cheap to look up (no DNS calls) but there is no
# requirement that it be fully qualified.
kernel_hostname = socket.gethostname()
if '.' in kernel_hostname:
@@ -134,17 +149,20 @@ def absolute_url(tgpath, tgparams=None, scheme=None,
if not webpath:
theurl = strip_webpath(theurl)
assert theurl.startswith('/')
- scheme = scheme or config.get('tg.url_scheme', 'http')
+ scheme = scheme or app.config.get('tg.url_scheme', 'http')
return '%s://%s%s' % (scheme, host_port, theurl)
+
_reports_engine = None
+
+
def get_reports_engine():
global _reports_engine
- if config.get('reports_engine.dburi'):
+ if app.config.get('reports_engine.dburi'):
if not _reports_engine:
# same logic as in turbogears.database.get_engine
engine_args = dict()
- for k, v in config.config.configMap['global'].iteritems():
+ for k, v in app.config.iteritems():
if k.startswith('reports_engine.'):
engine_args[k[len('reports_engine.'):]] = v
dburi = engine_args.pop('dburi')
@@ -155,12 +173,14 @@ def get_reports_engine():
log.debug('Using default engine for reports_engine')
return get_engine()
+
# Based on a similar decorator from kobo.decorators
def log_traceback(logger):
"""
A decorator which will log uncaught exceptions to the given logger, before
re-raising them.
"""
+
def decorator(func):
def decorated(*args, **kwargs):
try:
@@ -168,12 +188,15 @@ def log_traceback(logger):
except:
logger.exception('Uncaught exception in %s', func.__name__)
raise
+
decorated.__name__ = func.__name__
decorated.__doc__ = func.__doc__
decorated.__dict__.update(func.__dict__)
return decorated
+
return decorator
+
def run_createrepo(cwd=None, update=False):
createrepo_command = config.get('beaker.createrepo_command', 'createrepo_c')
args = [createrepo_command, '-q', '--no-database', '--checksum', 'sha']
@@ -182,14 +205,14 @@ def run_createrepo(cwd=None, update=False):
args.append('.')
log.debug('Running createrepo as %r in %s', args, cwd)
p = subprocess.Popen(args, cwd=cwd, stderr=subprocess.PIPE,
- stdout=subprocess.PIPE)
+ stdout=subprocess.PIPE)
out, err = p.communicate()
# Perhaps a bit fragile, but maybe better than checking version?
if p.returncode != 0 and 'no such option: --no-database' in err:
args.remove('--no-database')
log.debug('Re-trying createrepo as %r in %s', args, cwd)
p = subprocess.Popen(args, cwd=cwd, stderr=subprocess.PIPE,
- stdout=subprocess.PIPE)
+ stdout=subprocess.PIPE)
out, err = p.communicate()
RepoCreate = namedtuple("RepoCreate", "command returncode out err")
return RepoCreate(createrepo_command, p.returncode, out, err)
@@ -198,26 +221,31 @@ def run_createrepo(cwd=None, update=False):
# Validate FQDN for a system
# http://stackoverflow.com/questions/1418423/_/1420225#1420225
VALID_FQDN_REGEX = (r"^(?=.{1,255}$)[0-9A-Za-z]"
- r"(?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z]"
- r"(?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?)*\.?$")
+ r"(?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z]"
+ r"(?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?)*\.?$")
# do this at the global scope to avoid compiling it on every call
regex_compiled = re.compile(VALID_FQDN_REGEX)
+
+
def is_valid_fqdn(fqdn):
return regex_compiled.search(fqdn)
@contextlib.contextmanager
def convert_db_lookup_error(msg):
- """Context manager to handle SQLA's NoResultFound and report
- a custom error message
+ """
+ Context manager to handle SQLA's NoResultFound and report
+ a custom error message
"""
try:
yield
except NoResultFound:
raise DatabaseLookupError(msg)
+
def parse_untrusted_xml(s):
- """Parses untrusted XML as a string and raises a ValueError if system entities
+ """
+ Parses untrusted XML as a string and raises a ValueError if system entities
are found.
See: http://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint
"""