Subversion Repositories freemyipod

Rev

Rev 324 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 324 Rev 341
Line 175... Line 175...
175
    """
175
    """
176
        If you want to create a new commandline function you just need to
176
        If you want to create a new commandline function you just need to
177
        create a function with the name of it in this class and decorate
177
        create a function with the name of it in this class and decorate
178
        it with the decorator @command. If you don't want to call the desired
178
        it with the decorator @command. If you don't want to call the desired
179
        function (wrong arguments etc) just raise ArgumentError with or
179
        function (wrong arguments etc) just raise ArgumentError with or
180
        without an error message or raise ArgumentCountError
180
        without an error message.
181
    """
181
    """
182
    def __init__(self):
182
    def __init__(self):
183
        self.logger = Logger()
183
        self.logger = Logger()
184
        try:
184
        try:
185
            self.embios = libembios.Embios()
185
            self.embios = libembios.Embios()
Line 193... Line 193...
193
        # this is needed because the functions need access to their class.
193
        # this is needed because the functions need access to their class.
194
        args.insert(0, self)
194
        args.insert(0, self)
195
        if func in self.cmddict:
195
        if func in self.cmddict:
196
            try:
196
            try:
197
                self.cmddict[func](*args)
197
                self.cmddict[func](*args)
198
            except ArgumentError, e:
198
            except (ArgumentError, libembios.ArgumentError), e:
199
                usage(e, specific=func)
199
                usage(e, specific=func)
200
            except ArgumentError:
200
            except (ArgumentError, libembios.ArgumentError):
201
                usage("Syntax Error in function '" + func + "'", specific=func)
201
                usage("Syntax Error in function '" + func + "'", specific=func)
202
            except ArgumentTypeError, e:
202
            except ArgumentTypeError, e:
203
                usage(e, specific=func)
203
                usage(e, specific=func)
204
            except NotImplementedError:
204
            except NotImplementedError:
205
                self.logger.error("This function is not implemented yet!")
205
                self.logger.error("This function is not implemented yet!")
206
            except libembios.DeviceError, e:
206
            except libembios.DeviceError, e:
207
                self.logger.error(str(e))
207
                self.logger.error(str(e))
208
            except ValueError:
-
 
209
                usage(specific=func)
-
 
210
            except TypeError, e:
208
            except TypeError, e:
-
 
209
                # Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
211
                if str(e).split(" ", 1)[0] == func + "()":
210
                if str(e).split(" ", 1)[0] == func + "()":
212
                    self.logger.error(usage("Argument Error in '" + func + "': Wrong argument count", specific=func))
211
                    self.logger.error(usage("Argument Error in '" + func + "': Wrong argument count", specific=func))
213
                else:
212
                else:
214
                    raise
213
                    raise
215
            except libembios.usb.core.USBError:
214
            except libembios.usb.core.USBError:
216
                self.logger.error("Problem with USB connection.")
215
                self.logger.error("There is a problem with the USB connection.")
217
        else:
216
        else:
218
            usage("No such command")
217
            usage("No such command")
219
    
218
    
220
    @staticmethod
219
    @staticmethod
221
    def _bool(something):
220
    def _bool(something):