setup_common.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. try:
  2. # Python 2.x
  3. from ConfigParser import SafeConfigParser
  4. except ImportError:
  5. # Python 3.x
  6. from configparser import ConfigParser as SafeConfigParser
  7. def get_metadata_and_options():
  8. config = SafeConfigParser()
  9. config.read(['metadata.cfg', 'site.cfg'])
  10. metadata = dict(config.items('metadata'))
  11. options = dict(config.items('options'))
  12. metadata['py_modules'] = list(filter(None, metadata['py_modules'].split('\n')))
  13. metadata['classifiers'] = list(filter(None, metadata['classifiers'].split('\n')))
  14. return metadata, options
  15. def enabled(options, option):
  16. value = options[option]
  17. s = value.lower()
  18. if s in ('yes','true','1','y'):
  19. return True
  20. elif s in ('no', 'false', '0', 'n'):
  21. return False
  22. else:
  23. raise ValueError("Unknown value %s for option %s" % (value, option))
  24. def create_release_file(metadata):
  25. rel = open("MySQLdb/release.py",'w')
  26. rel.write("""
  27. __author__ = "%(author)s <%(author_email)s>"
  28. version_info = %(version_info)s
  29. __version__ = "%(version)s"
  30. """ % metadata)
  31. rel.close()