Commits

clach04 committed 3084009

Added (dirty) html generator to setup.py. Fails gracefully if docutils not available.

  • Participants
  • Parent commits 24abc9b

Comments (0)

Files changed (1)

poachplatelib/package.py

         for dummy in range(3 - len(version_tuple)):
             version_tuple = (0,) + version_tuple
         self.version_tuple = version_tuple
+        
+        self.generate_html_readme = True  # FIXME TODO this should be command line option
 
         self.email = cascade_value(opt=opt, opt_name='email', 
                                     cfg=cfg, cfg_section='properties', cfg_name='email',
             script = """scripts=['bin/%(file)s'],""" % {'file': self.scriptname}
         else:
             script = ''
+        
+        dirty_html_readme = '''
+try:
+    from docutils.core import publish_cmdline
+except ImportError:
+    publish_cmdline = None
+
+filename_txt = 'README'
+dest_html = os.path.splitext(filename_txt)[0] + '.html'
+
+# Only delete html file if text file is newer
+# TODO check if -a flag is issued
+if os.path.exists(dest_html) and os.path.getmtime(dest_html) < os.path.getmtime(filename_txt):
+    os.unlink(dest_html)
+
+readme_css_filename = None
+#readme_css_filename = 'style.css'  # FIXME implement
+if not os.path.exists(dest_html) and publish_cmdline:
+    print 'creating %s' % dest_html
+    publish_cmdline_argv = ['--initial-header-level=2']
+    if readme_css_filename:
+        publish_cmdline_argv.append('--stylesheet-path=%s' % readme_css_filename)
+    publish_cmdline_argv += [filename_txt, dest_html]
+    publish_cmdline(writer_name='html', argv=publish_cmdline_argv)
+
+
+if len(sys.argv) <= 1:
+    print """
+Suggested setup.py parameters:
+
+    * build
+    * install
+    * sdist  --formats=zip
+    * sdist  # NOTE requires tar/gzip commands
+
+"""
+
+'''
+        if not self.generate_html_readme:
+            dirty_html_readme = ''
 
         create_file(fout('setup.py'), '''%(script_copyright)s
+import os
+import sys
 try:
     from setuptools import setup, find_packages
 except ImportError:
     from distutils.core import setup
     find_packages = None
 
+%(rst2html_text)s
+
 from %(libname)s import meta
 
 setup(name='%(name)s',
 ''' % {'name': self.name,
        'script': script,
        'libname': self.libname,
-       'script_copyright': script_copyright})
+       'script_copyright': script_copyright,
+       'rst2html_text': dirty_html_readme})
 
 
 def main(prog_args):