Skip to content

Commit

Permalink
add help for env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
numerodix committed Jun 27, 2008
1 parent 8f6c5d0 commit c5130c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fetch.py
Expand Up @@ -339,7 +339,7 @@ def launch(self):
if len(args) > 1:
filename = args[1]
else:
os.environ["ORIG_FILENAMES"] = os.environ.get("ORIG_FILENAMES") or str(True)
os.environ["ORIG_FILENAMES"] = os.environ.get("ORIG_FILENAMES") or "1"
filename = io.safe_filename(urlrewrite.url_to_filename(url))
Fetcher(mode=Fetcher.FETCH, url=url, filename=filename).launch()
except filetype.WrongFileTypeError:
Expand Down
24 changes: 21 additions & 3 deletions io.py
Expand Up @@ -12,7 +12,7 @@

_help_header = "spiderfetch tool suite\n\n"

_tools_help="""\
_help_tools="""\
== spiderfetch ==
Spiders recursively for urls, starting from <url>. Driven either by <pattern>
Expand Down Expand Up @@ -46,6 +46,19 @@
from a file and records with mplayer.
"""

_help_vars="""\
SOCKET_TIMEOUT Seconds to wait before calling a socket timeout.
TRIES Number of tries on 503 Service Unavailable.
ORIG_FILENAMES Save files with their original filenames on the host (1) or
use filenames generated from the full url to avoid name collisions (0).
TMPDIR Temp directory for downloads.
LOGDIR Directory to use for logfiles.
TERM When set and not 'dumb' gives color output.
DEBUG_FETCH Write newlines after every update to see the full output.
"""

#LOGDIR = os.environ.get("LOGDIR") or "logs"
LOGDIR = os.environ.get("LOGDIR") or "."

Expand All @@ -60,7 +73,7 @@ def write_abort():
write_err("\n%s\n" % shcolor.color(shcolor.RED, "User aborted"))

def get_tempfile():
return tempfile.mkstemp(prefix=os.path.basename("." + sys.argv[0]) + ".")
return tempfile.mkstemp(prefix="."+os.path.basename(sys.argv[0])+".")

def safe_filename(filename, dir=None):
if dir:
Expand Down Expand Up @@ -133,13 +146,18 @@ def opts_help(option, opt_str, value, parser):
sys.exit(2)

def help_tools(option, opt_str, value, parser):
write_err(_help_header+_tools_help)
write_err(_help_header+_help_tools)
sys.exit(2)

def help_vars(option, opt_str, value, parser):
write_err(_help_header+_help_vars)
sys.exit(2)

def parse_args(parser):
a = parser.add_option
a("-h", action="callback", callback=opts_help, help="Display this message")
a("--tools", action="callback", callback=help_tools, help="Descriptions of the tools")
a("--vars", action="callback", callback=help_vars, help="Environmental variables")
return parser.parse_args()


Expand Down
6 changes: 3 additions & 3 deletions spiderfetch.py
Expand Up @@ -194,11 +194,11 @@ def main(queue, rules, wb):
(opts, args) = io.parse_args(parser)
try:
if opts.fetch:
os.environ["FETCH_ALL"] = str(True)
os.environ["FETCH_ALL"] = "1"
elif opts.dump:
os.environ["DUMP_ALL"] = str(True)
os.environ["DUMP_ALL"] = "1"
if opts.host:
os.environ["HOST_FILTER"] = str(True)
os.environ["HOST_FILTER"] = "1"
if opts.depth:
os.environ["DEPTH"] = str(opts.depth)

Expand Down

0 comments on commit c5130c4

Please sign in to comment.