Automatically exported from code.google.com/p/planningalerts
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

56 řádky
1.6 KiB

  1. #!/usr/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. chmod(cgi_dir+filename, int(file_dict["permissions"]))
  32. # write a README to warn people not to svn add stuff to CGI directory
  33. readme_message = """
  34. WARNING - this directory is only for generated files
  35. and files which are automatically copied in.
  36. Anything manually added here will be svn deleted.
  37. """
  38. readme_file = open(cgi_dir+ "README", "w")
  39. readme_file.write(readme_message)
  40. readme_file.close()