Commits

Owen Nelson committed 66f6935

adding better error reporting (refs #3)

  • Participants
  • Parent commits 6f65394

Comments (0)

Files changed (1)

File mdown/management/commands/pygments_styles.py

 from django.core.management.base import BaseCommand, CommandError
 
-from pygments.styles import get_all_styles
-from pygments.formatters import HtmlFormatter
+try:
+    from pygments.styles import get_all_styles
+    from pygments.formatters import HtmlFormatter
+except ImportError:
+    raise CommandError('Unable to load pygments. Please install pygments to '
+                       'use this command.')
 
 class Command(BaseCommand):
 
 Available color schemes:
 """ + '\n'.join(["  %s" % name for name in get_all_styles()])
         else:
-            assert(scheme in list(get_all_styles()))
+            try:
+                assert(scheme in list(get_all_styles()))
+            except AssertionError:
+                raise CommandError('Invalid scheme name "% s"\n' % scheme +
+                                   'Please use one of the available color'
+                                   ' schemes on your system:\n' +
+                                   '\n'.join(["  %s" % name for name in \
+                                              get_all_styles()]))
             print HtmlFormatter(style=scheme).get_style_defs('.codehilite')