From 60d3a3ea0480fbc4b5db8ce41e1e566dbeee001b Mon Sep 17 00:00:00 2001 From: "eran.kornblau" Date: Mon, 5 Aug 2013 15:18:04 +0300 Subject: [PATCH] package python client as PyPI --- generator/PythonClientGenerator.php | 24 +++------- .../sources/python/KalturaClient/Client.py | 48 ++++++++++--------- .../python/KalturaClient/Plugins/__init__.py | 0 .../KalturaClient/TestCode/PythonTester.py | 9 ++-- generator/sources/python/setup.py | 2 +- 5 files changed, 35 insertions(+), 48 deletions(-) create mode 100644 generator/sources/python/KalturaClient/Plugins/__init__.py diff --git a/generator/PythonClientGenerator.php b/generator/PythonClientGenerator.php index dfe5741bbc3..49d82cb8a00 100644 --- a/generator/PythonClientGenerator.php +++ b/generator/PythonClientGenerator.php @@ -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(); @@ -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 == '') diff --git a/generator/sources/python/KalturaClient/Client.py b/generator/sources/python/KalturaClient/Client.py index f6314175b46..6e0e2784907 100644 --- a/generator/sources/python/KalturaClient/Client.py +++ b/generator/sources/python/KalturaClient/Client.py @@ -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 @@ -38,7 +38,6 @@ import urllib import gzip import time -import sys import os from poster.streaminghttp import register_openers @@ -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 @@ -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 diff --git a/generator/sources/python/KalturaClient/Plugins/__init__.py b/generator/sources/python/KalturaClient/Plugins/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/generator/sources/python/KalturaClient/TestCode/PythonTester.py b/generator/sources/python/KalturaClient/TestCode/PythonTester.py index 55a30d2e4cb..a5cb912cd7d 100644 --- a/generator/sources/python/KalturaClient/TestCode/PythonTester.py +++ b/generator/sources/python/KalturaClient/TestCode/PythonTester.py @@ -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', diff --git a/generator/sources/python/setup.py b/generator/sources/python/setup.py index 1ea0f76b743..038115437e2 100644 --- a/generator/sources/python/setup.py +++ b/generator/sources/python/setup.py @@ -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(),