| Line 91... |
Line 91... |
| 91 |
"""
|
91 |
"""
|
| 92 |
Decorator for the class. Sets the self.cmddict of the class
|
92 |
Decorator for the class. Sets the self.cmddict of the class
|
| 93 |
to all functions decorated with @command
|
93 |
to all functions decorated with @command
|
| 94 |
"""
|
94 |
"""
|
| 95 |
cls.cmddict = {}
|
95 |
cls.cmddict = {}
|
| 96 |
for attr, value in cls.__dict__.iteritems():
|
96 |
for attr, value in cls.__dict__.items():
|
| 97 |
if getattr(value, 'func', False):
|
97 |
if getattr(value, 'func', False):
|
| 98 |
if getattr(value.func, '_command', False):
|
98 |
if getattr(value.func, '_command', False):
|
| 99 |
cls.cmddict[value.func.__name__] = value
|
99 |
cls.cmddict[value.func.__name__] = value
|
| 100 |
return cls
|
100 |
return cls
|
| 101 |
|
101 |
|
| Line 123... |
Line 123... |
| 123 |
# this is needed because the functions need access to their class.
|
123 |
# this is needed because the functions need access to their class.
|
| 124 |
args.insert(0, self)
|
124 |
args.insert(0, self)
|
| 125 |
if func in self.cmddict:
|
125 |
if func in self.cmddict:
|
| 126 |
try:
|
126 |
try:
|
| 127 |
self.cmddict[func](*args)
|
127 |
self.cmddict[func](*args)
|
| 128 |
except (ArgumentError, libemcore.ArgumentError), e:
|
128 |
except (ArgumentError, libemcore.ArgumentError) as e:
|
| 129 |
usage(e, specific=func)
|
129 |
usage(e, specific=func)
|
| 130 |
except (ArgumentError, libemcore.ArgumentError):
|
130 |
except (ArgumentError, libemcore.ArgumentError):
|
| 131 |
usage("Syntax Error in function '" + func + "'", specific=func)
|
131 |
usage("Syntax Error in function '" + func + "'", specific=func)
|
| 132 |
except ArgumentTypeError, e:
|
132 |
except ArgumentTypeError as e:
|
| 133 |
usage(e, specific=func)
|
133 |
usage(e, specific=func)
|
| 134 |
except NotImplementedError:
|
134 |
except NotImplementedError:
|
| 135 |
self.logger.error("This function is not implemented yet!\n")
|
135 |
self.logger.error("This function is not implemented yet!\n")
|
| 136 |
except libemcore.DeviceError, e:
|
136 |
except libemcore.DeviceError as e:
|
| 137 |
self.logger.error(str(e) + "\n")
|
137 |
self.logger.error(str(e) + "\n")
|
| 138 |
except TypeError, e:
|
138 |
except TypeError as e:
|
| 139 |
# Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
|
139 |
# Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
|
| 140 |
if str(e).split(" ", 1)[0] == func + "()":
|
140 |
if str(e).split(" ", 1)[0] == func + "()":
|
| 141 |
self.logger.error(usage("Argument Error in '%s': Wrong argument count" % func, specific=func))
|
141 |
self.logger.error(usage("Argument Error in '%s': Wrong argument count" % func, specific=func))
|
| 142 |
else:
|
142 |
else:
|
| 143 |
raise
|
143 |
raise
|