227 | | print 'direct cupspykota "PyKota" "Print Quota and Accounting Backend"' |
| 232 | # we will execute each existing backend in device enumeration mode |
| 233 | # and generate their PyKota accounting counterpart |
| 234 | (directory, myname) = os.path.split(sys.argv[0]) |
| 235 | for backend in [os.path.join(directory, b) for b in os.listdir(directory) if os.path.isfile(os.path.join(directory, b)) and (b != myname)] : |
| 236 | answer = os.popen(backend, "r") |
| 237 | try : |
| 238 | devices = [line.strip() for line in answer.readlines()] |
| 239 | except : |
| 240 | devices = [] |
| 241 | status = answer.close() |
| 242 | if status is None : |
| 243 | for d in devices : |
| 244 | fdevice = cStringIO.StringIO("%s" % d) |
| 245 | tokenizer = shlex.shlex(fdevice) |
| 246 | tokenizer.wordchars = tokenizer.wordchars + r".:,?!~/\_$*-+={}[]()#" |
| 247 | arguments = [] |
| 248 | while 1 : |
| 249 | token = tokenizer.get_token() |
| 250 | if token : |
| 251 | arguments.append(token) |
| 252 | else : |
| 253 | break |
| 254 | fdevice.close() |
| 255 | (devicetype, device, name, fullname) = arguments |
| 256 | if name.startswith('"') and name.endswith('"') : |
| 257 | name = name[1:-1] |
| 258 | if fullname.startswith('"') and fullname.endswith('"') : |
| 259 | fullname = fullname[1:-1] |
| 260 | print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname) |