Browse Source

Add missing main()

Previously, "console_scripts" in "setup.py" was pointing to a
non-existent main().
Steven Myint 11 years ago
parent
commit
3aa7040b22
1 changed files with 8 additions and 6 deletions
  1. 8
    6
      src/cdiff.py

+ 8
- 6
src/cdiff.py View File

471
                 yield line
471
                 yield line
472
 
472
 
473
 
473
 
474
-def markup_to_pager(stream):
474
+def markup_to_pager(stream, opts):
475
     markup = DiffMarkup(stream)
475
     markup = DiffMarkup(stream)
476
     color_diff = markup.markup(side_by_side=opts.side_by_side,
476
     color_diff = markup.markup(side_by_side=opts.side_by_side,
477
             width=opts.width)
477
             width=opts.width)
510
         return line
510
         return line
511
 
511
 
512
 
512
 
513
-if __name__ == '__main__':
513
+def main():
514
     import optparse
514
     import optparse
515
 
515
 
516
     supported_vcs = [check[0] for check, _ in REVISION_CONTROL]
516
     supported_vcs = [check[0] for check, _ in REVISION_CONTROL]
541
             sys.stderr.write(('*** Not in a supported workspace, supported '
541
             sys.stderr.write(('*** Not in a supported workspace, supported '
542
                               'are: %s\n\n') % ', '.join(supported_vcs))
542
                               'are: %s\n\n') % ', '.join(supported_vcs))
543
             parser.print_help()
543
             parser.print_help()
544
-            sys.exit(1)
544
+            return 1
545
     else:
545
     else:
546
         diff_hdl = sys.stdin
546
         diff_hdl = sys.stdin
547
 
547
 
550
 
550
 
551
     # Don't let empty diff pass thru
551
     # Don't let empty diff pass thru
552
     if not stream:
552
     if not stream:
553
-        sys.exit(0)
553
+        return 0
554
 
554
 
555
     if diff_hdl is not sys.stdin:
555
     if diff_hdl is not sys.stdin:
556
         diff_hdl.close()
556
         diff_hdl.close()
557
 
557
 
558
     if sys.stdout.isatty():
558
     if sys.stdout.isatty():
559
         try:
559
         try:
560
-            markup_to_pager(stream)
560
+            markup_to_pager(stream, opts)
561
         except IOError:
561
         except IOError:
562
             e = sys.exc_info()[1]
562
             e = sys.exc_info()[1]
563
             if e.errno == errno.EPIPE:
563
             if e.errno == errno.EPIPE:
566
         # pipe out stream untouched to make sure it is still a patch
566
         # pipe out stream untouched to make sure it is still a patch
567
         sys.stdout.write(''.join(stream))
567
         sys.stdout.write(''.join(stream))
568
 
568
 
569
-    sys.exit(0)
569
+
570
+if __name__ == '__main__':
571
+    sys.exit(main())
570
 
572
 
571
 # vim:set et sts=4 sw=4 tw=80:
573
 # vim:set et sts=4 sw=4 tw=80: