<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -36,8 +36,6 @@ def main():
 
 
 if __name__ == &quot;__main__&quot;:
-    parser = optparse.OptionParser(add_help_option=None) ; a = parser.add_option
-    parser.usage = &quot;&lt; &lt;file&gt;&quot;
-    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=io.opts_help, help=&quot;Display this message&quot;)
-    (opts, args) = parser.parse_args()
+    (parser, a) = io.init_opts(&quot;&lt; &lt;file&gt;&quot;)
+    (opts, args) = io.parse_args(parser)
     main()</diff>
      <filename>dumpstream.py</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
 import ftplib
 import httplib
 import mimetools
-import optparse
 import os
 import socket
 import sys
@@ -220,7 +219,6 @@ class Fetcher(object):
         if blocknum == 1:
             self.started = True
 
-        #step = 12
         step = 5
         if blocknum &gt; 0 and blocknum % step == 0:
             t = time.time()
@@ -327,11 +325,9 @@ class Fetcher(object):
 
 
 if __name__ == &quot;__main__&quot;:
-    parser = optparse.OptionParser(add_help_option=None) ; a = parser.add_option
-    parser.usage = &quot;&lt;url&gt; [&lt;file&gt;] [options]&quot;
+    (parser, a) = io.init_opts(&quot;&lt;url&gt; [&lt;file&gt;] [options]&quot;)
     a(&quot;--spidertest&quot;, action=&quot;store_true&quot;, help=&quot;Test spider with url&quot;)
-    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=io.opts_help, help=&quot;Display this message&quot;)
-    (opts, args) = parser.parse_args()
+    (opts, args) = io.parse_args(parser)
     try:
         urllib._urlopener = urllib.FancyURLopener()
         url = args[0]</diff>
      <filename>fetch.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@
 
 import gzip
 import cPickle as pickle    # cPickle is supposed to be faster
+import optparse
 import os
 import tempfile
 import sys
@@ -90,6 +91,16 @@ def opts_help(option, opt_str, value, parser):
         write_err(&quot;  %s %s\n&quot; % (argument.strip().ljust(25), o.help))
     sys.exit(2)
 
+def init_opts(usage):
+    parser = optparse.OptionParser(add_help_option=None)
+    parser.usage = usage
+    return parser, parser.add_option
+
+def parse_args(parser):
+    a = parser.add_option
+    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=opts_help, help=&quot;Display this message&quot;)
+    return parser.parse_args()
+
 
 
 if __name__ == &quot;__main__&quot;:</diff>
      <filename>io.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 
 import itertools
-import optparse
 import re
 import urllib
 
@@ -137,12 +136,10 @@ def colorize_shell(str):
 
 
 if __name__ == &quot;__main__&quot;:
-    parser = optparse.OptionParser(add_help_option=None) ; a = parser.add_option
-    parser.usage = &quot;[ &lt;url&gt; [options] | --test ]&quot;
+    (parser, a) = io.init_opts(&quot;[ &lt;url&gt; [options] | --test ]&quot;)
     a(&quot;--dump&quot;, action=&quot;store_true&quot;, help=&quot;Dump urls&quot;)
-    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=io.opts_help, help=&quot;Display this message&quot;)
     a(&quot;--test&quot;, action=&quot;store_true&quot;, help=&quot;Run spider testsuite&quot;)
-    (opts, args) = parser.parse_args()
+    (opts, args) = io.parse_args(parser)
     try:
         if opts.test:
             data = testcases</diff>
      <filename>spider.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 
-import optparse
 import os
 import re
 import sys
@@ -186,15 +185,13 @@ def main(queue, rules, wb):
 
 
 if __name__ == &quot;__main__&quot;:
-    parser = optparse.OptionParser(add_help_option=None) ; a = parser.add_option
-    parser.usage = &quot;&lt;url&gt; [&lt;pattern&gt;] [options]&quot;
+    (parser, a) = io.init_opts(&quot;&lt;url&gt; [&lt;pattern&gt;] [options]&quot;)
     a(&quot;--recipe&quot;, metavar=&quot;&lt;recipe&gt;&quot;, dest=&quot;recipe&quot;, help=&quot;Use a spidering recipe&quot;)
     a(&quot;--fetch&quot;, action=&quot;store_true&quot;, help=&quot;Fetch urls, don't dump&quot;)
     a(&quot;--dump&quot;, action=&quot;store_true&quot;, help=&quot;Dump urls, don't fetch&quot;)
     a(&quot;--host&quot;, action=&quot;store_true&quot;, help=&quot;Only spider this host&quot;)
     a(&quot;--depth&quot;, type=&quot;int&quot;, metavar=&quot;&lt;depth&gt;&quot;, dest=&quot;depth&quot;, help=&quot;Spider to this depth&quot;)
-    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=io.opts_help, help=&quot;Display this message&quot;)
-    (opts, args) = parser.parse_args()
+    (opts, args) = io.parse_args(parser)
     try:
         if opts.fetch:
             os.environ[&quot;FETCH_ALL&quot;] = str(True)</diff>
      <filename>spiderfetch.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 
-import optparse
 import pickle
 import sys
 
@@ -172,8 +171,7 @@ class Web(object):
 
 
 if __name__ == &quot;__main__&quot;:
-    parser = optparse.OptionParser(add_help_option=None) ; a = parser.add_option
-    parser.usage = &quot;&lt;web&gt; [options]&quot;
+    (parser, a) = io.init_opts(&quot;&lt;web&gt; [options]&quot;)
     a(&quot;--dump&quot;, action=&quot;store_true&quot;, help=&quot;Dump all urls in web&quot;)
     a(&quot;--in&quot;, metavar=&quot;&lt;url&gt;&quot;, dest=&quot;into&quot;, help=&quot;Find incoming urls to &lt;url&gt;&quot;)
     a(&quot;--out&quot;, metavar=&quot;&lt;url&gt;&quot;, help=&quot;Find outgoing urls from &lt;url&gt;&quot;)
@@ -182,9 +180,8 @@ if __name__ == &quot;__main__&quot;:
     a(&quot;--trace&quot;, metavar=&quot;&lt;url&gt;&quot;, help=&quot;Trace path from root to &lt;url&gt;&quot;)
     a(&quot;--deepest&quot;, action=&quot;store_true&quot;, help=&quot;Trace url furthest from root&quot;)
     a(&quot;--popular&quot;, action=&quot;store_true&quot;, help=&quot;Find the most referenced urls&quot;)
-    a(&quot;-h&quot;, action=&quot;callback&quot;, callback=io.opts_help, help=&quot;Display this message&quot;)
     a(&quot;--test&quot;, action=&quot;store_true&quot;, help=&quot;Run trace loop test&quot;)
-    (opts, args) = parser.parse_args()
+    (opts, args) = io.parse_args(parser)
     try:
         if opts.test:
             wb = Web()</diff>
      <filename>web.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>78874ff665d7f6c4403b039b0af6bc0a2bffcb19</id>
    </parent>
  </parents>
  <author>
    <name>Martin Matusiak</name>
    <email>numerodix@gmail.com</email>
  </author>
  <url>http://github.com/numerodix/spiderfetch/commit/e93e1634c9f75343401e9ab7a9fe20aa78f24ac3</url>
  <id>e93e1634c9f75343401e9ab7a9fe20aa78f24ac3</id>
  <committed-date>2008-06-27T13:33:20-07:00</committed-date>
  <authored-date>2008-06-27T13:33:20-07:00</authored-date>
  <message>rewrite opts logic</message>
  <tree>46fb041a9ba955bf1f8396698d5057ae94e9f44b</tree>
  <committer>
    <name>Martin Matusiak</name>
    <email>numerodix@gmail.com</email>
  </committer>
</commit>
