Commit acbd78df authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

make static nodes using udev rules

parent 9a148fa2
Loading
Loading
Loading
Loading
+27 −1
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@
@author:     Andrey Filippov
@author:     Andrey Filippov
@copyright:  2016 Elphel, Inc.
@copyright:  2016 Elphel, Inc.
@license:    GPLv3.0+
@license:    GPLv3.0+
@contact:    andrey@elphel.coml
@contact:    andrey@elphel.com
@deffield    updated: Updated
@deffield    updated: Updated
'''
'''
from __future__ import division
from __future__ import division
@@ -34,7 +34,26 @@ __version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__email__ = "andrey@elphel.com"
__status__ = "Development"
__status__ = "Development"

def create_udev_rules_file(contents):
  c  = "# --- This is an auto-generated file, see "+sys.argv[0]+"\n"
  c += "ACTION!=\"add\", GOTO=\"static_nodes_end\"\n\n"
  c += contents
  c += "\nLABEL=\"static_nodes_end\""

  f = open('50-elphel-static-nodes.rules','w')
  f.write(c)
  f.close()

def get_udev_rule(mode, name, devtype, major, minor,comment):
  tmpstr  = comment.strip()+"\n"
  tmpstr += "ACTION==\"add\", RUN+=\"/bin/mknod -m "+mode+" /dev/"+name+" "+devtype+" "+major+" "+minor+"\"\n"
  return tmpstr

def process_header():
def process_header():

    rulestr = ""

    print("# --- This is an auto-generated file, see %s ---"%(sys.argv[0]))
    print("# --- This is an auto-generated file, see %s ---"%(sys.argv[0]))
    print("define mknodes =")
    print("define mknodes =")
    pat=re.compile(r'#define\s+(\w+)\s+\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*(\w*)\s*,\s*(\w*)\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"\s*\)(.*)')
    pat=re.compile(r'#define\s+(\w+)\s+\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*(\w*)\s*,\s*(\w*)\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"\s*\)(.*)')
@@ -52,7 +71,14 @@ def process_header():
                comment = " # "+comment
                comment = " # "+comment
            print("mknod -m %s $(TARGETDIR)/%-20s %s %3s %3s%s"%(
            print("mknod -m %s $(TARGETDIR)/%-20s %s %3s %3s%s"%(
                fs.group(6), fs.group(2), fs.group(7), fs.group(4), fs.group(5), comment))
                fs.group(6), fs.group(2), fs.group(7), fs.group(4), fs.group(5), comment))

            rulestr += get_udev_rule(fs.group(6), fs.group(2), fs.group(7), fs.group(4), fs.group(5), comment)

        line = f.readline()
        line = f.readline()

    if rulestr != "":
        create_udev_rules_file(rulestr)

    print("endef")
    print("endef")
if __name__ == "__main__":
if __name__ == "__main__":
    process_header()
    process_header()