From 1f32624e8bb33926d7d836ddf3b71772a2efb88e Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 7 Mar 2012 10:14:47 +0000 Subject: [PATCH 1/4] use a try / except to check if argparse is a needed dependency --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9b299085..6c3a72a1 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,10 @@ import platform VERSION = "3.0" # find a better way to do so. requires = ['feedgenerator', 'jinja2', 'pygments', 'docutils', 'pytz'] -if sys.version_info < (2,7): + +try: + import argparse +except ImportError: requires.append('argparse') scripts = ['bin/pelican', 'tools/pelican-themes', 'tools/pelican-import', 'tools/pelican-quickstart'] From 8009324a3be63e4c04e7d5dea0a50cb3a04bc68a Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 7 Mar 2012 10:33:46 +0000 Subject: [PATCH 2/4] restructure the whole way scripts are created, using setuptools magic to take care of creating .exe wrappers for windows. To make this work needed to - rename modules with a "-" in it (not a valid name) - add an __init__.py to the tools directory - create an entry point dictionary which stores the right associations --- setup.py | 17 ++++++------- tools/__init__.py | 0 tools/pelican-import.bat | 1 - tools/pelican-quickstart.bat | 1 - tools/pelican-themes.bat | 1 - tools/{pelican-import => pelican_import.py} | 24 +++++++++---------- ...lican-quickstart => pelican_quickstart.py} | 0 tools/{pelican-themes => pelican_themes.py} | 0 8 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 tools/__init__.py delete mode 100755 tools/pelican-import.bat delete mode 100755 tools/pelican-quickstart.bat delete mode 100755 tools/pelican-themes.bat rename tools/{pelican-import => pelican_import.py} (98%) rename tools/{pelican-quickstart => pelican_quickstart.py} (100%) rename tools/{pelican-themes => pelican_themes.py} (100%) diff --git a/setup.py b/setup.py index 6c3a72a1..6556193d 100755 --- a/setup.py +++ b/setup.py @@ -12,13 +12,14 @@ try: except ImportError: requires.append('argparse') -scripts = ['bin/pelican', 'tools/pelican-themes', 'tools/pelican-import', 'tools/pelican-quickstart'] - -if sys.platform.startswith('win'): - scripts += [ - 'bin/pelican.bat', 'tools/pelican-themes.bat', - 'tools/pelican-import.bat', 'tools/pelican-quickstart.bat' - ] +entry_points = { + 'console_scripts': [ + 'pelican = pelican:main', + 'pelican-import = tools.pelican_import:main', + 'pelican-quickstart = tools.pelican_quickstart:main', + 'pelican-themes = tools.pelican_themes:main' + ] +} setup( name = "pelican", @@ -31,7 +32,7 @@ setup( packages = ['pelican'], include_package_data = True, install_requires = requires, - scripts = scripts, + entry_points = entry_points, classifiers = ['Development Status :: 5 - Production/Stable', 'Environment :: Console', 'License :: OSI Approved :: GNU Affero General Public License v3', diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tools/pelican-import.bat b/tools/pelican-import.bat deleted file mode 100755 index 674e1fd7..00000000 --- a/tools/pelican-import.bat +++ /dev/null @@ -1 +0,0 @@ -@python "%~dpn0" %* diff --git a/tools/pelican-quickstart.bat b/tools/pelican-quickstart.bat deleted file mode 100755 index 674e1fd7..00000000 --- a/tools/pelican-quickstart.bat +++ /dev/null @@ -1 +0,0 @@ -@python "%~dpn0" %* diff --git a/tools/pelican-themes.bat b/tools/pelican-themes.bat deleted file mode 100755 index 674e1fd7..00000000 --- a/tools/pelican-themes.bat +++ /dev/null @@ -1 +0,0 @@ -@python "%~dpn0" %* diff --git a/tools/pelican-import b/tools/pelican_import.py similarity index 98% rename from tools/pelican-import rename to tools/pelican_import.py index 3a931afd..261bff4c 100755 --- a/tools/pelican-import +++ b/tools/pelican_import.py @@ -231,18 +231,7 @@ def fields2pelican(fields, out_markup, output_path, dircat=False): fs.write(header + content) -def main(input_type, input, out_markup, output_path, dircat=False): - if input_type == 'wordpress': - fields = wp2fields(input) - elif input_type == 'dotclear': - fields = dc2fields(input) - elif input_type == 'feed': - fields = feed2fields(input) - - fields2pelican(fields, out_markup, output_path, dircat=dircat) - - -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser( description="Transform feed, Wordpress or Dotclear files to rst files." "Be sure to have pandoc installed") @@ -280,4 +269,13 @@ if __name__ == '__main__': error("Couldn't create the output folder: " + args.output) exit() - main(input_type, args.input, args.markup, args.output, dircat=args.dircat) + input_type, input, out_markup, output_path, dircat=False = input_type, args.input, args.markup, args.output, args.dircat + + if input_type == 'wordpress': + fields = wp2fields(input) + elif input_type == 'dotclear': + fields = dc2fields(input) + elif input_type == 'feed': + fields = feed2fields(input) + + fields2pelican(fields, out_markup, output_path, dircat=dircat) diff --git a/tools/pelican-quickstart b/tools/pelican_quickstart.py similarity index 100% rename from tools/pelican-quickstart rename to tools/pelican_quickstart.py diff --git a/tools/pelican-themes b/tools/pelican_themes.py similarity index 100% rename from tools/pelican-themes rename to tools/pelican_themes.py From 7c78f232b4b10a31607815469fb7cf276a807468 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 7 Mar 2012 10:34:14 +0000 Subject: [PATCH 3/4] remove unused imports --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 6556193d..910499de 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ #!/usr/bin/env python from setuptools import setup -import sys -import platform VERSION = "3.0" # find a better way to do so. From 8f7b08a01cd5a8ff679946996d35f285380ab93d Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 7 Mar 2012 10:38:08 +0000 Subject: [PATCH 4/4] remove now useless if __name__ == '__main__' checks and clean up the old pelican script in bin --- bin/pelican | 3 --- bin/pelican.bat | 1 - pelican/__init__.py | 4 ---- tools/pelican_import.py | 1 + tools/pelican_quickstart.py | 3 --- tools/pelican_themes.py | 3 --- 6 files changed, 1 insertion(+), 14 deletions(-) delete mode 100755 bin/pelican delete mode 100755 bin/pelican.bat diff --git a/bin/pelican b/bin/pelican deleted file mode 100755 index 3fe2ee57..00000000 --- a/bin/pelican +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env python -from pelican import main -main() diff --git a/bin/pelican.bat b/bin/pelican.bat deleted file mode 100755 index 674e1fd7..00000000 --- a/bin/pelican.bat +++ /dev/null @@ -1 +0,0 @@ -@python "%~dpn0" %* diff --git a/pelican/__init__.py b/pelican/__init__.py index 710c9ff1..a0b5704c 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -158,7 +158,3 @@ def main(): raise else: sys.exit(getattr(e, 'exitcode', 1)) - - -if __name__ == '__main__': - main() diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 261bff4c..e7f8e051 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -269,6 +269,7 @@ def main(): error("Couldn't create the output folder: " + args.output) exit() + # TODO: refactor this long assignment input_type, input, out_markup, output_path, dircat=False = input_type, args.input, args.markup, args.output, args.dircat if input_type == 'wordpress': diff --git a/tools/pelican_quickstart.py b/tools/pelican_quickstart.py index 4048c2bf..56c22f10 100755 --- a/tools/pelican_quickstart.py +++ b/tools/pelican_quickstart.py @@ -270,6 +270,3 @@ Please answer the following questions so this script can generate the files need print('Error: {0}'.format(e)) print('Done. Your new project is available at %s' % CONF['basedir']) - -if __name__ == '__main__': - main() diff --git a/tools/pelican_themes.py b/tools/pelican_themes.py index 78df4a48..3d35bb5d 100755 --- a/tools/pelican_themes.py +++ b/tools/pelican_themes.py @@ -212,6 +212,3 @@ def clean(v=False): c+=1 print("\nRemoved {0} broken links".format(c)) - -if __name__ == '__main__': - main()