From: Daniel Hokka Zakrisson Date: Sun, 17 Oct 2010 00:10:27 +0000 (-0400) Subject: Skip generating static list of API calls, just send them to the API. X-Git-Tag: plcapi-5.0-19~65 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=598e1e840b55262fd40c6d1700148e4f0b508065 Skip generating static list of API calls, just send them to the API. --- diff --git a/php/Makefile b/php/Makefile deleted file mode 100644 index fe8842a..0000000 --- a/php/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# -# (Re)builds PHP API. PHP classes must be defined in a single file. -# -# Mark Huang -# Copyright (C) 2006 The Trustees of Princeton University -# -# $Id$ -# $URL$ -# - -all: plc_api.php - -methods.php: methods.py ../PLC/__init__.py ../PLC/Methods/__init__.py - PYTHONPATH=.. python $< > $@ - # Indent all lines by a couple of spaces - sed -i -e "s/^/ /" $@ - -plc_api.php: header.php methods.php footer.php - # Set timestamp - sed -e "s/@DATE@/$$(date)/" header.php > $@ - cat methods.php footer.php >> $@ - -clean: - rm -f plc_api.php methods.php - -.PHONY: all clean diff --git a/php/footer.php b/php/footer.php deleted file mode 100644 index 6212304..0000000 --- a/php/footer.php +++ /dev/null @@ -1,9 +0,0 @@ -} - -global $adm; - -$adm = new PLCAPI(array('AuthMethod' => "capability", - 'Username' => PLC_API_MAINTENANCE_USER, - 'AuthString' => PLC_API_MAINTENANCE_PASSWORD)); - -?> diff --git a/php/methods.py b/php/methods.py deleted file mode 100755 index 621cc91..0000000 --- a/php/methods.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/python -# -# Generates the PLCAPI interface for the website PHP code. -# -# Mark Huang -# Copyright (C) 2005 The Trustess of Princeton University -# -# $Id$ -# $URL$ -# - -import os, sys -import time - -from PLC.API import PLCAPI -from PLC.Method import * -from PLC.Auth import Auth - -try: - set -except NameError: - from sets import Set - set = Set - -def php_cast(value): - """ - Casts Python values to PHP values. - """ - - if value is None: - return "NULL" - elif isinstance(value, (list, tuple, set)): - return "array(%s)" % ", ".join([php_cast(v) for v in value]) - elif isinstance(value, dict): - items = ["%s => %s" % (php_cast(k), php_cast(v)) for (k, v) in value.items()] - return "array(%s)" % ", ".join(items) - elif isinstance(value, (int, long, bool, float)): - return str(value) - else: - unicode_repr = repr(unicode(value)) - # Truncate the leading 'u' prefix - return unicode_repr[1:] - -# Class functions -api = PLCAPI(None) - -api.all_methods.sort() -for method in api.all_methods: - # Skip system. methods - if "system." in method: - continue - - function = api.callable(method) - - # Commented documentation - lines = ["// " + line.strip() for line in function.__doc__.strip().split("\n")] - print "\n".join(lines) - print - - # Function declaration - print "function " + function.name, - - # PHP function arguments - args = [] - (min_args, max_args, defaults) = function.args() - parameters = zip(max_args, function.accepts, defaults) - - for name, expected, default in parameters: - # Skip auth structures (added automatically) - if isinstance(expected, Auth) or \ - (isinstance(expected, Mixed) and \ - filter(lambda sub: isinstance(sub, Auth), expected)): - continue - - # Declare parameter - arg = "$" + name - - # Set optional parameters to their defaults - if name not in min_args: - arg += " = " + php_cast(default) - - args.append(arg) - - # Write function declaration - print "(" + ", ".join(args) + ")" - - # Begin function body - print "{" - - # API function arguments - i = 0 - for name, expected, default in parameters: - # Automatically added auth structures - if isinstance(expected, Auth) or \ - (isinstance(expected, Mixed) and \ - filter(lambda sub: isinstance(sub, Auth), expected)): - print " $args[] = $this->auth;" - continue - - print " ", - if name not in min_args: - print "if (func_num_args() > %d)" % i, - print "$args[] = $%s;" % name - - i += 1 - - # Call API function - print " return $this->call('%s', $args);" % method - - # End function body - print "}" - print diff --git a/php/header.php b/php/plc_api.php similarity index 95% rename from php/header.php rename to php/plc_api.php index 54f9b1e..cb7257a 100644 --- a/php/header.php +++ b/php/plc_api.php @@ -201,3 +201,17 @@ class PLCAPI // PLCAPI Methods // + function __call($name, $args) + { + array_unshift($args, $this->auth); + return $this->call($name, $args); + } +} + +global $adm; + +$adm = new PLCAPI(array('AuthMethod' => "capability", + 'Username' => PLC_API_MAINTENANCE_USER, + 'AuthString' => PLC_API_MAINTENANCE_PASSWORD)); + +?>