Automatically exported from code.google.com/p/planningalerts
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

generateCGIScripts.py 1.9 KiB

hace 17 años
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/local/bin/python
  2. list_of_sites_filename = "SitesToGenerate.csv"
  3. other_files_to_copy_filename = "OtherFilesToCopy.csv"
  4. template_filename = "CGITemplate"
  5. python_location = "/usr/local/bin/python"
  6. cgi_dir = "../cgi-bin/"
  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()