#!/usr/bin/env python
-# vim: set ts=4 sts=4 sw=4 textwidth=112 :
+# vim: set ts=4 sts=4 sw=4 textwidth=92:
+
+"""
+The main program of the rarslave project.
+
+This handles all of the commandline, configuration file, and option
+work. It gets the environment set up for a run using the RarslaveDetector
+class.
+"""
+
+__author__ = "Ira W. Snyder (devel@irasnyder.com)"
+__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)"
+__license__ = "GNU GPL v2 (or, at your option, any later version)"
+
+# rarslave.py -- a usenet autorepair and autoextract utility
+#
+# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
VERSION="2.0.0"
-PROGRAM="rarslave2"
+PROGRAM="rarslave"
import os, sys, optparse, logging
import rsutil
# A tiny class to hold logging output until we're finished
class DelayedLogger (object):
+
+ """A small class to hold logging output until the program is finished running.
+ It emulates sys.stdout in the needed ways for the logging module."""
+
def __init__ (self, output=sys.stdout.write):
self.__messages = []
self.__output = output
# A tiny class used to find unique PAR2 sets
class CompareSet (object):
+ """A small class used to find unique PAR2 sets"""
+
def __init__ (self, dir, p2file):
self.dir = dir
self.p2file = p2file
def find_all_par2_files (dir):
- """Finds all par2 files in a directory"""
- # NOTE: does NOT return absolute paths
+ """Finds all par2 files in the given directory.
+
+ dir -- the directory in which to search for PAR2 files
+
+ NOTE: does not return absolute paths"""
if not os.path.isdir (os.path.abspath (dir)):
raise ValueError # bad directory given
return rsutil.common.find_par2_files (files)
def generate_all_parsets (dir):
- # Generate all parsets in the given directory.
+ """Generate all parsets in the given directory
+
+ dir -- the directory in which to search"""
assert os.path.isdir (dir) # Directory MUST be valid
sys.exit(1)
def run_options (options):
+ """Process all of the commandline options, doing thing such as printing the
+ version number, etc."""
# Fix directories
options.work_dir = rsutil.common.full_abspath (options.work_dir)
if options.write_def_config:
config.write_config (default=True)
+ sys.exit (0)
if options.write_config:
config.write_config ()
+ sys.exit (0)
def find_loglevel (options):
+ """Find the log level that should be printed by the logging class"""
loglevel = options.verbose - options.quiet