From: <cod...@go...> - 2009-12-21 01:14:25
|
Revision: 6477 Author: sparks.m Date: Sun Dec 20 17:03:57 2009 Log: Moved test code to after the fold. http://code.google.com/p/kamaelia/source/detail?r=6477 Modified: /branches/private_MPS_AlsaAudio/Kamaelia/Kamaelia/Device/Alsa/Record.py ======================================= --- /branches/private_MPS_AlsaAudio/Kamaelia/Kamaelia/Device/Alsa/Record.py Sun Dec 20 17:00:32 2009 +++ /branches/private_MPS_AlsaAudio/Kamaelia/Kamaelia/Device/Alsa/Record.py Sun Dec 20 17:03:57 2009 @@ -25,51 +25,52 @@ if l: self.send(data, "outbox") -def parseargs(argv, longopts, longflags): - args = {} - for k, key in longopts: - try: - i = argv.index("--"+key) - F = longopts[k,key].__class__(argv[i+1]) - args[key] = F - del argv[i+1] - del argv[i] - except ValueError: + + +if __name__ == "__main__": + from Kamaelia.File.Writing import SimpleFileWriter + from Kamaelia.Chassis.Pipeline import Pipeline + + import sys + + def parseargs(argv, longopts, longflags): + args = {} + for k, key in longopts: try: - i = argv.index("-"+k) + i = argv.index("--"+key) F = longopts[k,key].__class__(argv[i+1]) args[key] = F del argv[i+1] del argv[i] except ValueError: - if longopts[k,key] == None: - print "missing argument: --"+key, "-"+k - sys.exit(0) - args[key] = longopts[k,key] - - for f,flag in longflags: - try: - i = argv.index("--"+flag) - args[flag] = True - del argv[i] - except ValueError: + try: + i = argv.index("-"+k) + F = longopts[k,key].__class__(argv[i+1]) + args[key] = F + del argv[i+1] + del argv[i] + except ValueError: + if longopts[k,key] == None: + print "missing argument: --"+key, "-"+k + sys.exit(0) + args[key] = longopts[k,key] + + for f,flag in longflags: try: - i = argv.index("-"+f) + i = argv.index("--"+flag) args[flag] = True del argv[i] except ValueError: - args[flag] = False - - rest = [a for a in argv if len(argv)>0 and a[0] != "-"] - args["__anon__"] = rest - return args - - -if __name__ == "__main__": - from Kamaelia.File.Writing import SimpleFileWriter - from Kamaelia.Chassis.Pipeline import Pipeline - - import sys + try: + i = argv.index("-"+f) + args[flag] = True + del argv[i] + except ValueError: + args[flag] = False + + rest = [a for a in argv if len(argv)>0 and a[0] != "-"] + args["__anon__"] = rest + return args args = parseargs( sys.argv[1:], { ("f", "file" ): "audio.raw", |