generate-udev-rules.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # Licensed and redistributable under GPLv3
  3. # Written by David Henningsson <david.henningsson@canonical.com>
  4. # (C) 2010 Canonical Ltd
  5. ''' This file takes a "configuration" file as input and gives an
  6. udev rule file as output, meant for usage with the new (juju)
  7. firewire stack.
  8. Suggested name of the output file is 60-ffado.rules
  9. (after default.rules, before acl.rules)
  10. '''
  11. import sys
  12. import re
  13. out_header = "\
  14. # Do not edit this file, it will be automatically overwritten on upgrade.\n\
  15. # This list has been auto-generated from the \"configuration\" file in top of libffado's source tree.\n\
  16. SUBSYSTEM!=\"firewire\", GOTO=\"ffado_end\"\n"
  17. out_footer = 'LABEL="ffado_end"\n'
  18. out_row = 'ATTRS{vendor}=="%s", ATTRS{model}=="%s", GROUP="audio", ENV{ID_FFADO}="1" # %s, %s'
  19. i_pattern = re.compile("(\w+)\s*=\s*((\w+)|(\"(.*?)\"))\s*;");
  20. end_pattern = re.compile("[^#]*\}");
  21. start_pattern = re.compile("[^#]*\{");
  22. print out_header
  23. for line in sys.stdin.readlines():
  24. if start_pattern.search(line):
  25. d = dict()
  26. continue
  27. if end_pattern.search(line):
  28. # format vendor and model according to sysfs
  29. vendorid = "0x%06x" % int(d['vendorid'],0)
  30. modelid = "0x%06x" % int(d['modelid'],0)
  31. print out_row % (vendorid, modelid, d['vendorname'], d['modelname'])
  32. continue
  33. m = i_pattern.search(line)
  34. if m is not None:
  35. if m.group(3) is None:
  36. d[m.group(1)] = m.group(5)
  37. else:
  38. d[m.group(1)] = m.group(3)
  39. print out_footer