Skip to content

Commit

Permalink
package python client as PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
erankor committed Aug 5, 2013
1 parent c7a1320 commit 60d3a3e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
24 changes: 6 additions & 18 deletions generator/PythonClientGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,17 @@ function generate()
}
}

function getPluginClassName($pluginName)
{
return "Kaltura" . ucfirst($pluginName) . "ClientPlugin";
}

function writePlugin($pluginName, $enumNodes, $classNodes, $serviceNodes, $serviceNamesNodes)
{
if ($pluginName == '')
{
$pluginClassName = "KalturaCoreClient";
$outputFileName = "$pluginClassName.py";
$outputFileName = "KalturaClient/Plugins/Core.py";
}
else
{
$pluginClassName = $this->getPluginClassName($pluginName);
$outputFileName = "KalturaPlugins/$pluginClassName.py";
$pluginClassName = "Kaltura" . ucfirst($pluginName) . "ClientPlugin";
$outputFileName = "KalturaClient/Plugins/".ucfirst($pluginName).".py";
}

$this->startNewTextBlock();
Expand All @@ -73,23 +68,16 @@ function writePlugin($pluginName, $enumNodes, $classNodes, $serviceNodes, $servi

if ($pluginName != '')
{
$this->appendLine('import os.path');
$this->appendLine('import sys');
$this->appendLine('');
$this->appendLine("clientRoot = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))");
$this->appendLine("if not clientRoot in sys.path:");
$this->appendLine(" sys.path.append(clientRoot)");
$this->appendLine('');
$this->appendLine('from KalturaCoreClient import *');
$this->appendLine('from Core import *');

$xpath = new DOMXPath($this->_doc);
$dependencyNodes = $xpath->query("/xml/plugins/plugin[@name = '$pluginName']/dependency");
foreach($dependencyNodes as $dependencyNode)
$this->appendLine('from ' .
$this->getPluginClassName($dependencyNode->getAttribute("pluginName")) .
ucfirst($dependencyNode->getAttribute("pluginName")) .
' import *');
}
$this->appendLine('from KalturaClientBase import *');
$this->appendLine('from ..Base import *');
$this->appendLine('');

if ($pluginName == '')
Expand Down
48 changes: 25 additions & 23 deletions generator/sources/python/KalturaClient/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#
# @ignore
# ===================================================================================================
from KalturaCoreClient import *
from KalturaClientBase import *
from Plugins.Core import *
from Base import *
from xml.parsers.expat import ExpatError
from xml.dom import minidom
from threading import Timer
Expand All @@ -38,7 +38,6 @@
import urllib
import gzip
import time
import sys
import os

from poster.streaminghttp import register_openers
Expand All @@ -54,10 +53,6 @@
# Register the streaming http handlers with urllib2
register_openers()

pluginsFolder = os.path.normpath(os.path.join(os.path.dirname(__file__), 'KalturaPlugins'))
if not pluginsFolder in sys.path:
sys.path.append(pluginsFolder)

class MultiRequestSubResult:
def __init__(self, value):
self.value = value
Expand Down Expand Up @@ -104,22 +99,29 @@ def __init__(self, config):

self.loadPlugins()

def loadPlugins(self):
if not os.path.isdir(pluginsFolder):
return

pluginList = ['KalturaCoreClient']
for fileName in os.listdir(pluginsFolder):
(pluginClass, fileExt) = os.path.splitext(fileName)
if fileExt.lower() != '.py':
continue
pluginList.append(pluginClass)

for pluginClass in pluginList:
self.loadPlugin(pluginClass)

def loadPlugin(self, pluginClass):
pluginModule = __import__(pluginClass)
def loadPlugins(self):
pluginFiles = ['Core']
pluginsFolder = os.path.normpath(os.path.join(os.path.dirname(__file__), 'Plugins'))
if os.path.isdir(pluginsFolder):
for fileName in os.listdir(pluginsFolder):
(pluginFile, fileExt) = os.path.splitext(fileName)
if fileExt.lower() != '.py':
continue
pluginFiles.append(pluginFile)

for pluginFile in pluginFiles:
self.loadPlugin(pluginFile)

def loadPlugin(self, pluginFile):
moduleHierarchy = ['KalturaClient', 'Plugins', pluginFile]
pluginModule = __import__('.'.join(moduleHierarchy))
for curModule in moduleHierarchy[1:]:
pluginModule = getattr(pluginModule, curModule)

if pluginFile == 'Core':
pluginClass = 'KalturaCoreClient'
else:
pluginClass = 'Kaltura%sClientPlugin' % pluginFile
if not pluginClass in dir(pluginModule):
return

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
#
# @ignore
# ===================================================================================================
import sys
import os

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from KalturaClient import *
from KalturaMetadataClientPlugin import *
from KalturaClient.Plugins.Metadata import *
import logging
import urllib
import time
import sys
import re
import os

logging.basicConfig(level = logging.DEBUG,
format = '%(asctime)s %(levelname)s %(message)s',
Expand Down
2 changes: 1 addition & 1 deletion generator/sources/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name='KalturaClient',
version='1.0.0',
url='http://www.kaltura.com/api_v3/testme/client-libs.php',
packages=['KalturaClient', 'KalturaClient.KalturaPlugins'],
packages=['KalturaClient', 'KalturaClient.Plugins'],
license='AGPL',
description='A Python module for accessing the Kaltura API.',
long_description=open('README.txt').read(),
Expand Down

0 comments on commit 60d3a3e

Please sign in to comment.