I fixed some additional chnages to make formatting more standardized

This commit is contained in:
gallowj
2021-04-22 18:58:15 -05:00
parent ec8dd9ff88
commit a7054844ec
8 changed files with 90 additions and 88 deletions
@@ -36,7 +36,7 @@ _LOGGER.info('local_host: {}'.format(_LOCAL_HOST))
# -------------------------------------------------------------------------
def start_wing_to_maya(local_host=_LOCAL_HOST,
comman_port=6000,
command_port=6000,
logger=_LOGGER,
*args, **kwargs):
"""
@@ -58,7 +58,7 @@ def start_wing_to_maya(local_host=_LOCAL_HOST,
except NameError:
port = None
port_name = str('{0}:{1}'.format(local_host, comman_port))
port_name = str('{0}:{1}'.format(local_host, command_port))
# should only be getting the port passed in
_LOGGER.info('Attempting to open port:: {0}'.format(port_name))
@@ -145,10 +145,10 @@ def start_wing_to_maya_menu():
port = object() # init a dummy object
# default name ... name is first arg, or a kwarg
portName, kwargs = setSynthArgKwarg(port, arg_pos_index=0, argTag='portName',
inArgs=args, inKwargs=kwargs,
defaultValue="127.0.0.1:6000")
portName, kwargs = set_synth_arg_kwarg(port, arg_pos_index=0, arg_tag='portName',
in_args=args, in_kwargs=kwargs,
default_value="127.0.0.1:6000")
port = start_wing_to_maya(local_host=_LOCAL_HOST, comman_port=6000)
port = start_wing_to_maya(local_host=_LOCAL_HOST, command_port=6000)
return
# -------------------------------------------------------------------------
@@ -23,8 +23,8 @@ __author__ = 'HogJonny'
# -------------------------------------------------------------------------
def find_arg(arg_pos_index=None, argTag=None, removeKwarg=None,
inArgs=None, inKwargs=None, defaultValue=None):
def find_arg(arg_pos_index=None, arg_tag=None, remove_kwarg=None,
in_args=None, in_kwargs=None, default_value=None):
"""
# finds and returns an arg...
# if a positional index is given argPosIndex=0, it checks args first
@@ -41,31 +41,33 @@ def find_arg(arg_pos_index=None, argTag=None, removeKwarg=None,
#
# foundArg, args, kwargs = find_arg(0, 'name',)
"""
found_arg = None
if arg_pos_index != None:
if not isinstance(arg_pos_index, int):
raise TypeError('argPosIndex: accepts a index integer!\r'
'got: {0}'.format(arg_pos_index))
# positional args ... check the position
if len(inArgs) > 0:
if len(in_args) > 0:
try:
foundArg = inArgs[arg_pos_index]
found_arg = in_args[arg_pos_index]
except:
pass
# check kwargs ... a set kwarg will ALWAYS take precident over
# positional arg!!!
try:
foundArg
except:
foundArg = inKwargs.get(argTag, defaultValue) # defaults to None
if in_kwargs:
found_arg = in_kwargs.get(arg_tag, default_value) # defaults to None
if removeKwarg:
if argTag in inKwargs:
del inKwargs[argTag]
if remove_kwarg:
if in_kwargs:
if arg_tag in in_kwargs:
del in_kwargs[arg_tag]
# if we didn't find the arg/kwarg, the defualt return will be None
return foundArg, inKwargs
return found_arg, in_kwargs
# -------------------------------------------------------------------------
@@ -86,14 +88,14 @@ if __name__ == "__main__":
class TestNode(Foo):
def __init__(self, *args, **kwargs):
super().__init__()
self._name, kwargs = find_arg(argTag='foo', removeKwarg=True,
inArgs=args, inKwargs=kwargs)
self._name, kwargs = find_arg(arg_pos_index=0, argTag='name',
removeKwarg=True,
inArgs=args, inKwargs=kwargs) # <-- first positional OR kwarg
self._parent, kwargs = find_arg(arg_pos_index=1, argTag='parent',
removeKwarg=True,
inArgs=args, inKwargs=kwargs) # <-- second positional OR kwarg
self._name, kwargs = find_arg(arg_tag='foo', remove_kwarg=True,
in_args=args, in_kwargs=kwargs)
self._name, kwargs = find_arg(arg_pos_index=0, arg_tag='name',
remove_kwarg=True,
in_args=args, in_kwargs=kwargs) # <-- first positional OR kwarg
self._parent, kwargs = find_arg(arg_pos_index=1, arg_tag='parent',
remove_kwarg=True,
in_args=args, in_kwargs=kwargs) # <-- second positional OR kwarg
self._kwargsDict = {}
@@ -117,7 +119,7 @@ if __name__ == "__main__":
testNode2 = TestNode(name='fooey', parent=testNode)
testNode3 = TestNode('kablooey', testNode2, goober='dufus')
testNode3 = TestNode('kablooey', testNode2, gomer='pile')
print ('testNode2, name: {0}, parent: {1}'.format(testNode2._name, testNode2._parent))
print (testNode3)
@@ -143,9 +143,9 @@ class Node(object):
# -- secret keyword -----------------------------------------------
self._temp_node = False
temp_node, kwargs = find_arg(arg_pos_index=None, argTag='temp_node',
removeKwarg=True, inArgs=args,
inKwargs=kwargs) # <-- kwarg only
temp_node, kwargs = find_arg(arg_pos_index=None, arg_tag='temp_node',
remove_kwarg=True, in_args=args,
in_kwargs=kwargs) # <-- kwarg only
self._temp_node = temp_node
if self._temp_node:
self._kwargs_dict['temp_node'] = self._temp_node
@@ -153,9 +153,9 @@ class Node(object):
# -- store message header -----------------------------------------
# setup the .message_header <-- kwarg only
message_header, kwargs = find_arg(arg_pos_index=None, argTag='message_header',
removeKwarg=True, inArgs=args, inKwargs=kwargs,
defaultValue=('{0}(), Message'
message_header, kwargs = find_arg(arg_pos_index=None, arg_tag='message_header',
remove_kwarg=True, in_args=args, in_kwargs=kwargs,
default_value=('{0}(), Message'
.format(self._node_type)))
self._message_header = message_header
# -----------------------------------------------------------------
@@ -124,22 +124,22 @@ class PathNode(Node):
# -- secret keyword -----------------------------------------------
self._temp_node = False
temp_node, kwargs = find_arg(arg_pos_index=None, argTag='temp_node',
removeKwarg=True, inArgs=args,
inKwargs=kwargs) # <-- kwarg only
temp_node, kwargs = find_arg(arg_pos_index=None, arg_tag='temp_node',
remove_kwarg=True, in_args=args,
in_kwargs=kwargs) # <-- kwarg only
self._temp_node = temp_node
if self._temp_node:
self.k_wargs_dict['temp_node'] = self._temp_node
# -- Node class args/kwargs ---------------------------------------
node_name, kwargs = find_arg(arg_pos_index=2, argTag='node_name',
removeKwarg=True, inArgs=args,
inKwargs=kwargs) # <-- third arg, kwarg
node_name, kwargs = find_arg(arg_pos_index=2, arg_tag='node_name',
remove_kwarg=True, in_args=args,
in_kwargs=kwargs) # <-- third arg, kwarg
parent_node, kwargs = find_arg(arg_pos_index=3, argTag='parent_node',
removeKwarg=True, inArgs=args,
inKwargs=kwargs) # <-- fourth arg, kwarg
parent_node, kwargs = find_arg(arg_pos_index=3, arg_tag='parent_node',
remove_kwarg=True, in_args=args,
in_kwargs=kwargs) # <-- fourth arg, kwarg
self._root_path = root_path
@@ -22,9 +22,9 @@ from synth import synthesize
# -------------------------------------------------------------------------
def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None,
inArgs=None, inKwargs=None, removeKwarg=True,
setAnyway=True):
def set_synth_arg_kwarg(inst, arg_pos_index=None, arg_tag=None, default_value=None,
in_args=None, in_kwargs=None, remove_kwarg=True,
set_anyway=True):
"""
Uses find_arg and sets a property on a object.
@@ -34,44 +34,44 @@ def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None,
If the arg/property doesn't exist we synthesize it
"""
foundArg = None
argValueDict = {}
found_arg = None
arg_value_dict = {}
# find the argument, or set to default value
foundArg, inKwargs = find_arg(argPosIndex, argTag, removeKwarg,
inArgs, inKwargs,
defaultValue)
found_arg, in_kwargs = find_arg(arg_pos_index, arg_tag, remove_kwarg,
in_args, in_kwargs,
default_value)
if foundArg:
argTag = foundArg
if found_arg:
arg_tag = found_arg
# single arg first
# make sure the object doesn't arealdy have this property
try:
hasattr(inst, argTag) # check if property exists
if setAnyway:
hasattr(inst, arg_tag) # check if property exists
if set_anyway:
try:
setattr(inst, argTag, defaultValue) # try to set
setattr(inst, arg_tag, default_value) # try to set
except Exception as e:
raise e
except:
pass
# make it a synthetic property
if argTag:
if arg_tag:
try:
argValue = synthesize(inst, argTag, defaultValue)
argValueDict[argTag] = argValue
arg_value = synthesize(inst, arg_tag, default_value)
arg_value_dict[arg_tag] = arg_value
except Exception as e:
raise e
# multiple and/or remaining kwards next
if inKwargs:
if len(inKwargs) > 0:
for k, v in inKwargs.items():
if in_kwargs:
if len(in_kwargs) > 0:
for k, v in in_kwargs.items():
try:
hasattr(inst, k) # check if property exists
if setAnyway:
if set_anyway:
try:
setattr(inst, k, v) # try to set
except Exception as e:
@@ -81,12 +81,12 @@ def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None,
if k:
try:
argValue = synthesize(inst, k, v)
argValueDict[k] = argValue
arg_value = synthesize(inst, k, v)
arg_value_dict[k] = arg_value
except Exception as e:
raise e
return argValueDict
return arg_value_dict
# --------------------------------------------------------------------------
@@ -98,28 +98,28 @@ if __name__ == '__main__':
from test_foo import Foo
# define a arg/property tag we know doesn't exist
synthArgTag = 'syntheticArg'
synth_arg_tag = 'synthetic_arg'
# create a test object
print('~ creating the test foo object...')
myFoo = Foo()
my_foo = Foo()
print('~ Starting - single synthetic arg test...')
# find and set existing, or create and set
argValueDict = setSynthArgKwarg(myFoo,
argTag=synthArgTag,
defaultValue='kablooey')
arg_value_dict = set_synth_arg_kwarg(my_foo,
arg_tag=synth_arg_tag,
default_value='kablooey')
# what was returned
print('~ single value returned...')
for k, v in argValueDict.items():
for k, v in arg_value_dict.items():
print("Arg '{0}':'{1}'".format(k, v))
# attempt to access the new synthetic property directly
print('~ direct property access test...')
try:
myFoo.syntheticArg
print('myFoo.{0}: {1}'.format(synthArgTag, myFoo.syntheticArg))
my_foo.synthetic_arg
print('myFoo.{0}: {1}'.format(synth_arg_tag, my_foo.synthetic_arg))
except Exception as e:
raise e
@@ -128,31 +128,31 @@ if __name__ == '__main__':
newKwargs = {'fooey': 'chop suey', 'success': True}
# find and set existing, or create and set
argValueDict = setSynthArgKwarg(myFoo,
inKwargs=newKwargs,
defaultValue='kablooey')
arg_value_dict = set_synth_arg_kwarg(my_foo,
in_kwargs=newKwargs,
default_value='kablooey')
# what was returned
print('~ multiple values returned...')
for k, v in argValueDict.items():
for k, v in arg_value_dict.items():
print("Arg '{0}':'{1}'".format(k, v))
print('~ multiple direct property access test...')
try:
myFoo.fooey
print('myFoo.{0}: {1}'.format('fooey', myFoo.fooey))
my_foo.fooey
print('myFoo.{0}: {1}'.format('fooey', my_foo.fooey))
except Exception as e:
raise e
try:
myFoo.success
print('myFoo.{0}: {1}'.format('success', myFoo.success))
my_foo.success
print('myFoo.{0}: {1}'.format('success', my_foo.success))
except Exception as e:
raise e
print('~ Starting - known failure test...')
try:
myFoo.knownBad
my_foo.knownBad
except Exception as e:
print(e)
print('Test failed as expected!!!')
@@ -25,13 +25,13 @@ class Foo(object):
This is a Class, it creates a Foo object... which does nothing really
"""
__propertyTag = 'fooProperty'
__property_tag = 'fooProperty'
# ------------------------------------------------------------------
def __init__(self, name='Foo', value='defaultValue', *args, **kwargs):
'''Class __init__'''
synthesize(self, 'name', name)
synthesize(self, Foo.__propertyTag, value)
synthesize(self, Foo.__property_tag, value)
synthesize(self, 'test', 'testValue')
@@ -667,7 +667,7 @@ if __name__ == '__main__':
try:
import azpy.test.entry_test
print('SUCCESS: import azpy.test.entry_test')
azpy.test.entry_test.main(verbose=True, connectDebugger=True)
azpy.test.entry_test.main(verbose=True, connect_debugger=True)
except ImportError as e:
print('ERROR: {0}'.format(e))
raise e
@@ -49,13 +49,13 @@ _LOGGER.debug('Starting:: {}.'.format({_MODULENAME}))
# -------------------------------------------------------------------------
def main(verbose=_G_DEBUG, connectDebugger=True):
def main(verbose=_G_DEBUG, connect_debugger=True):
_LOGGER.info('{}'.format('-' * 74))
_LOGGER.info('entry_test.main()')
_LOGGER.info('Root test import successful:')
_LOGGER.info('~ {}'.format(__file__))
if connectDebugger:
if connect_debugger:
status = connect_wing()
_LOGGER.info(status)
# -------------------------------------------------------------------------
@@ -138,4 +138,4 @@ def connect_wing():
# -------------------------------------------------------------------------
if __name__ == '__main__':
_G_DEBUG = True
main(verbose=_G_DEBUG, connectDebugger=_G_DEBUG)
main(verbose=_G_DEBUG, connect_debugger=_G_DEBUG)