Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 line
1.9 KiB

  1. #!/usr/local/bin/python
  2. list_of_sites_filename = "PublicAccessSites.csv"
  3. other_files_to_copy_filename = "OtherFilesToCopy.csv"
  4. template_filename = "CGITemplate"
  5. python_location = "/usr/bin/python"
  6. cgi_dir = "../CGI/"
  7. import csv
  8. from os import chmod
  9. from shutil import copyfile
  10. list_of_sites_file = open(list_of_sites_filename)
  11. csv_reader = csv.DictReader(list_of_sites_file, quoting=csv.QUOTE_ALL, skipinitialspace=True)
  12. # create cgi files and write them in the cgi directory
  13. template_contents = open(template_filename).read()
  14. template = "#!" + python_location +"\n\n" + template_contents
  15. for site_dict in csv_reader:
  16. filename = cgi_dir + "%s.cgi" %site_dict["authority_short_name"]
  17. contents = template %site_dict
  18. this_file = open(filename, "w")
  19. print "Writing %s" %filename
  20. this_file.write(contents)
  21. this_file.close()
  22. chmod(filename, 0755)
  23. # copy across other files that are needed
  24. # these should probably come from a config file
  25. other_files_to_copy = open(other_files_to_copy_filename)
  26. other_files_csv_reader = csv.DictReader(other_files_to_copy, quoting=csv.QUOTE_ALL, skipinitialspace=True)
  27. for file_dict in other_files_csv_reader:
  28. print file_dict
  29. filename = file_dict["filename"]
  30. copyfile(filename, cgi_dir+filename)
  31. # the idea here is to have filename and permissions
  32. # in the csv file.
  33. # Until version 2.6 of python, there is no easy way
  34. # to convert a string to an octal, so I am using
  35. # integers to represent permissions...
  36. # see README for details.
  37. chmod(cgi_dir+filename, int(file_dict["permissions"]))
  38. # write a README to warn people not to svn add stuff to CGI directory
  39. readme_message = """
  40. WARNING - this directory is only for generated files
  41. and files which are automatically copied in.
  42. Anything manually added here will be svn deleted.
  43. """
  44. readme_file = open(cgi_dir+ "README", "w")
  45. readme_file.write(readme_message)
  46. readme_file.close()