Permalink
Browse files

Drop dependency on Kobo. Fix #5

- copy XML-RPC related code from Kobo
- drop the dependency

Note: Kobo appears to be an old piece of code which isn't actively
maintained with latest Django versions and appears to include
bunch of random integrations from Red Hat's Release Engineering.
I've taken only the bare minimum code which is relevant to us
and copied it here so we can drop the dependency.
  • Loading branch information...
atodorov committed Jun 6, 2017
1 parent 80cc3cf commit 1d3b269a931e0dd43bf24436f94112b963078cc6
View
@@ -9,5 +9,3 @@ six
django-contrib-comments
django-preserialize
xmltodict
git+https://github.com/release-engineering/kobo.git@kobo-0.5.2#egg=kobo
View
@@ -206,8 +206,6 @@
'django.contrib.staticfiles',
'django_comments',
'kobo.django.xmlrpc',
'pagination',
'tinymce',
@@ -221,8 +219,7 @@
'tcms.testcases',
'tcms.testplans',
'tcms.testruns',
'tcms.xmlrpc.apps.AppConfig',
'tcms.xmlrpc',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
View
@@ -20,11 +20,7 @@
from tcms.management import views as management_views
from tcms.report import urls as report_urls
from tcms.search import advance_search
# XML RPC handler
from kobo.django.xmlrpc.views import XMLRPCHandlerFactory
xmlrpc_handler = XMLRPCHandlerFactory('TCMS_XML_RPC')
from tcms.xmlrpc import urls as xmlrpc_urls
urlpatterns = [
@@ -36,7 +32,7 @@
# Index and static zone
url(r'^$', core_views.index, name='core-views-index'),
url(r'^search/$', core_views.search, name='core-views-search'),
url(r'^xmlrpc/$', xmlrpc_handler),
url(r'^xmlrpc/$', include(xmlrpc_urls)),
# Ajax call responder
url(r'^ajax/update/$', ajax.update, name='ajax-update'),
@@ -1,27 +1,27 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
from kobo.django.xmlrpc.models import XmlRpcLog
from .models import XmlRpcLog
class NitrateXmlRpcLogAdmin(admin.ModelAdmin):
class XmlRpcLogAdmin(admin.ModelAdmin):
list_display = ('happened_on', 'user_username', 'method')
list_per_page = 50
list_filter = ('dt_inserted',)
user_cache = {}
def __init__(self, *args, **kwargs):
NitrateXmlRpcLogAdmin.user_cache.clear()
NitrateXmlRpcLogAdmin.user_cache = {}
XmlRpcLogAdmin.user_cache.clear()
XmlRpcLogAdmin.user_cache = {}
super(NitrateXmlRpcLogAdmin, self).__init__(*args, **kwargs)
super(XmlRpcLogAdmin, self).__init__(*args, **kwargs)
def user_username(self, obj):
username = NitrateXmlRpcLogAdmin.user_cache.get(obj.user_id)
username = XmlRpcLogAdmin.user_cache.get(obj.user_id)
if username is None:
username = obj.user.username
NitrateXmlRpcLogAdmin.user_cache[obj.user_id] = username
XmlRpcLogAdmin.user_cache[obj.user_id] = username
return username
user_username.short_description = 'username'
@@ -32,5 +32,4 @@ def happened_on(self, obj):
happened_on.short_description = 'Happened On'
admin.site.unregister(XmlRpcLog)
admin.site.register(XmlRpcLog, NitrateXmlRpcLogAdmin)
admin.site.register(XmlRpcLog, XmlRpcLogAdmin)
View

This file was deleted.

Oops, something went wrong.
@@ -3,9 +3,7 @@
import inspect
import logging
from functools import wraps
from django.conf import settings
from kobo.django.xmlrpc.models import XmlRpcLog
__all__ = ('log_call',)
@@ -21,13 +19,14 @@ def create_log(user, method, args):
args)
logger.debug(log_msg)
else:
from .models import XmlRpcLog
create_log = XmlRpcLog.objects.create
def log_call(*args, **kwargs):
'''Log XMLRPC-specific invocations
This is copied from kobo.django.xmlrpc.decorators to add custom abitlities,
This was copied from kobo.django.xmlrpc.decorators to add custom abitlities,
so that we don't have to wait upstream to make the changes.
Usage::
View
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-
# Based on http://code.djangoproject.com/wiki/XML-RPC
#
# Credits:
# Brendan W. McAdams
import sys
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
__all__ = (
'DjangoXMLRPCDispatcher',
)
class DjangoXMLRPCDispatcher(SimpleXMLRPCDispatcher):
def __init__(self, allow_none=True, encoding=None):
if sys.version_info[:2] == (2, 4):
# doesn't support extra args in python 2.4
SimpleXMLRPCDispatcher.__init__(self)
else:
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
self.allow_none = allow_none
self.encoding = encoding
self.register_multicall_functions()
def system_multicall(self, request, call_list):
for call in call_list:
# insert request to each param list
call['params'] = [request] + call['params']
return SimpleXMLRPCDispatcher.system_multicall(self, call_list)
def register_module(self, module_name, function_prefix):
"""register all the public functions in a module with prefix prepended"""
if type(module_name) is str:
module = __import__(module_name, {}, {}, [""])
else:
module = module_name
if hasattr(module, '__all__'):
fn_list = module.__all__
else:
fn_list = dir(module)
for fn in fn_list:
if fn.startswith("_"):
continue
function = getattr(module, fn)
if not callable(function):
continue
name = fn
if function_prefix:
name = "%s.%s" % (function_prefix, name)
name = name.replace("__", ".")
self.register_function(function, name)
def _marshaled_dispatch(self, request, dispatch_method=None):
"""Dispatches an XML-RPC method from marshalled (XML) data.
XML-RPC methods are dispatched from the marshalled (XML) data
using the _dispatch method and the result is returned as
marshalled data. For backwards compatibility, a dispatch
function can be provided as an argument (see comment in
SimpleXMLRPCRequestHandler.do_POST) but overriding the
existing method through subclassing is the prefered means
of changing method dispatch behavior.
"""
data = request.body
params, method = xmlrpclib.loads(data)
# add request to params
params = (request, ) + params
# generate response
try:
if dispatch_method is not None:
response = dispatch_method(method, params)
else:
response = self._dispatch(method, params)
# wrap response in a singleton tuple
response = (response,)
response = xmlrpclib.dumps(response, methodresponse=1, allow_none=self.allow_none, encoding=self.encoding)
except xmlrpclib.Fault, fault:
response = xmlrpclib.dumps(fault, allow_none=self.allow_none, encoding=self.encoding)
except:
response = xmlrpclib.dumps(
xmlrpclib.Fault(1, "%s: %s" % (sys.exc_type.__name__, sys.exc_value)),
allow_none=self.allow_none, encoding=self.encoding)
return response
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='XmlRpcLog',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('dt_inserted', models.DateTimeField(auto_now_add=True)),
('method', models.CharField(max_length=255)),
('args', models.TextField(blank=True)),
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
),
]
No changes.
View
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.conf import settings
class XmlRpcLog(models.Model):
dt_inserted = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
method = models.CharField(max_length=255)
args = models.TextField(blank=True)
def __unicode__(self):
return u"%s: %s" % (self.user, self.method)
View
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url
from tcms.xmlrpc.views import XMLRPCHandlerFactory
urlpatterns = [
url(r'^$', XMLRPCHandlerFactory('TCMS_XML_RPC')),
]
Oops, something went wrong.

0 comments on commit 1d3b269

Please sign in to comment.