all python assignment in one place

ready for type conversions to go in
This commit is contained in:
John Cupitt 2014-08-31 22:51:04 +01:00
parent 3b43bd76f3
commit 8a6a846452
2 changed files with 19 additions and 19 deletions

View File

@ -2,8 +2,8 @@
import sys import sys
#import logging import logging
#logging.basicConfig(level = logging.DEBUG) logging.basicConfig(level = logging.DEBUG)
from gi.repository import Vips from gi.repository import Vips
from vips8 import vips from vips8 import vips

View File

@ -40,6 +40,11 @@ class Argument:
self.priority = op.get_argument_priority(self.name) self.priority = op.get_argument_priority(self.name)
self.isset = op.argument_isset(self.name) self.isset = op.argument_isset(self.name)
def set_value(self, value):
logging.debug('assigning %s to %s' % (value, self.name))
logging.debug('%s needs a %s' % (self.name, self.prop.value_type))
self.op.props.__setattr__(self.name, value)
def _call_base(name, required, optional, self = None, option_string = None): def _call_base(name, required, optional, self = None, option_string = None):
logging.debug('_call_base name=%s, required=%s optional=%s' % logging.debug('_call_base name=%s, required=%s optional=%s' %
(name, required, optional)) (name, required, optional))
@ -54,7 +59,7 @@ def _call_base(name, required, optional, self = None, option_string = None):
raise Error('No such operator.') raise Error('No such operator.')
# set str options first so the user can't override things we set # set str options first so the user can't override things we set
# deliberately and beak stuff # deliberately and break stuff
if option_string: if option_string:
if op.set_from_string(option_string) != 0: if op.set_from_string(option_string) != 0:
raise Error('Bad arguments.') raise Error('Bad arguments.')
@ -70,13 +75,13 @@ def _call_base(name, required, optional, self = None, option_string = None):
x.flags & enm.REQUIRED and x.flags & enm.REQUIRED and
not x.isset] not x.isset]
# do we have a non-NULL self pointer? this is used to set the first # do we have a non-None self pointer? this is used to set the first
# compatible input arg # compatible input arg
if self != None: if self != None:
found = False found = False
for x in required_input: for x in required_input:
if GObject.type_is_a(self, x.prop.value_type): if GObject.type_is_a(self, x.prop.value_type):
op.props.__setattr__(x.name, self) x.set_value(self)
required_input.remove(x) required_input.remove(x)
found = True found = True
break break
@ -91,25 +96,20 @@ def _call_base(name, required, optional, self = None, option_string = None):
(name, len(required_input), len(required))) (name, len(required_input), len(required)))
for i in range(len(required_input)): for i in range(len(required_input)):
logging.debug('assigning %s to %s' % (required[i], required_input[i].set_value(required[i])
required_input[i].name))
logging.debug('%s needs a %s' % (required_input[i].name,
required_input[i].prop.value_type))
op.props.__setattr__(required_input[i].name, required[i])
# find all optional, unassigned input args ... just need the names # find all optional, unassigned input args ... make a hash from name to
optional_input = [x.name for x in args if x.flags & enm.INPUT and # Argument
optional_input = {x.name: x for x in args if x.flags & enm.INPUT and
not x.flags & enm.REQUIRED and not x.flags & enm.REQUIRED and
not x.isset] not x.isset}
for key in optional.keys():
if not key in optional_input:
raise Error('Unknown argument.',
'Operator %s has no argument %s' % (name, key))
# set optional input args # set optional input args
for key in optional.keys(): for key in optional.keys():
op.props.__setattr__(key, optional[key]) if not key in optional_input:
raise Error('Unknown argument.',
'Operator %s has no argument %s' % (name, key))
optional_input[key].set_value(optional[key])
# call # call
op2 = Vips.cache_operation_build(op) op2 = Vips.cache_operation_build(op)