makeSql.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # coding=utf8
  3. """
  4. Created on 2014年2月15日
  5. @author: liaoqiqi
  6. """
  7. myfile = open("url_resources.txt")
  8. lines = myfile.readlines()
  9. print "use disconf;"
  10. print 'delete from role_resource;'
  11. for line in lines:
  12. line = line.strip('\n')
  13. if not line:
  14. continue
  15. if line[0] == '#':
  16. continue
  17. data = line.split()
  18. if len(data) != 5 and len(data) != 3:
  19. # print "cannot process this: " + line
  20. continue
  21. url = data[0]
  22. desc = data[1]
  23. if len(data) == 3:
  24. role1_mask = data[2]
  25. role2_mask = role1_mask
  26. role3_mask = role1_mask
  27. else:
  28. role1_mask = data[2]
  29. role2_mask = data[3]
  30. role3_mask = data[4]
  31. URL_PREFIX = "/api"
  32. print "INSERT INTO `role_resource` (`role_id`, `url_pattern`, `url_description`, `method_mask`) VALUES"
  33. print "(1,'" + URL_PREFIX + url + "' , '" + desc + "' , '" + role1_mask + "'),"
  34. print "(2,'" + URL_PREFIX + url + "' , '" + desc + "' , '" + role2_mask + "'),"
  35. print "(3,'" + URL_PREFIX + url + "' , '" + desc + "' , '" + role3_mask + "');"