Move common functionality into rsutil package
authorIra W. Snyder <devel@irasnyder.com>
Tue, 2 Jan 2007 00:40:43 +0000 (16:40 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Tue, 2 Jan 2007 00:40:43 +0000 (16:40 -0800)
This patch moves all of the common functionality from the RarslaveCommon,
RarslaveConfig, and RarslaveGlobals classes into a new package, called
rsutil. It then converts everything over to the new package.

Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
16 files changed:
Makefile
PAR2Set/Base.py
PAR2Set/ExtractFirstBase.py
PAR2Set/ExtractFirstNewRAR.py
PAR2Set/ExtractFirstOldRAR.py
PAR2Set/Join.py
PAR2Set/NewRAR.py
PAR2Set/OldRAR.py
PAR2Set/ZIP.py
RarslaveDetector.py
rarslave.py
rsutil/__init__.py [new file with mode: 0644]
rsutil/common.py [moved from RarslaveCommon.py with 93% similarity]
rsutil/config.py [moved from RarslaveConfig.py with 99% similarity]
rsutil/globals.py [moved from RarslaveGlobals.py with 89% similarity]
rsutil/par2parser.py [moved from Par2Parser.py with 100% similarity]

index 7fd2ad2..74487a2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ all:
        @echo "Use another target, this has no meaning"
 
 clean:
        @echo "Use another target, this has no meaning"
 
 clean:
-       rm -f *.pyc
+       find -name '*.pyc' -exec rm -f '{}' \;
        rm -rf extract_dir
 
 test:
        rm -rf extract_dir
 
 test:
index 012c01a..46a69de 100644 (file)
@@ -1,8 +1,7 @@
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
-from RarslaveCommon import *
-import Par2Parser
+import rsutil.common
 
 import re
 import os
 
 import re
 import os
@@ -45,34 +44,34 @@ class Base (object):
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
-               self.basename = get_basename (p2file)
+               self.basename = rsutil.common.get_basename (p2file)
 
                # Find files that match by name only
 
                # Find files that match by name only
-               self.name_matched_files = find_name_matches (self.dir, self.basename)
+               self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename)
 
                # Find all par2 files for this set using name matches
 
                # Find all par2 files for this set using name matches
-               self.all_p2files = find_par2_files (self.name_matched_files)
+               self.all_p2files = rsutil.common.find_par2_files (self.name_matched_files)
 
                # Try to get the protected files for this set
 
                # Try to get the protected files for this set
-               self.prot_matched_files = parse_all_par2 (self.dir, self.p2file, self.all_p2files)
+               self.prot_matched_files = rsutil.common.parse_all_par2 (self.dir, self.p2file, self.all_p2files)
 
                # Setup the all_files combined set (for convenience only)
 
                # Setup the all_files combined set (for convenience only)
-               self.all_files = no_duplicates (self.name_matched_files + self.prot_matched_files)
+               self.all_files = rsutil.common.no_duplicates (self.name_matched_files + self.prot_matched_files)
 
        def __eq__ (self, rhs):
                return (self.dir == rhs.dir) and (self.basename == rhs.basename) and \
 
        def __eq__ (self, rhs):
                return (self.dir == rhs.dir) and (self.basename == rhs.basename) and \
-                               list_eq (self.name_matched_files, rhs.name_matched_files) and \
-                               list_eq (self.prot_matched_files, rhs.prot_matched_files)
+                               rsutil.common.list_eq (self.name_matched_files, rhs.name_matched_files) and \
+                               rsutil.common.list_eq (self.prot_matched_files, rhs.prot_matched_files)
 
        def update_matches (self):
                """Updates the contents of instance variables which are likely to change after
                running an operation, usually one which will create new files."""
 
 
        def update_matches (self):
                """Updates the contents of instance variables which are likely to change after
                running an operation, usually one which will create new files."""
 
-               self.name_matched_files = find_name_matches (self.dir, self.basename)
-               self.all_files = no_duplicates (self.name_matched_files + self.prot_matched_files)
+               self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename)
+               self.all_files = rsutil.common.no_duplicates (self.name_matched_files + self.prot_matched_files)
 
        def runVerifyAndRepair (self):
 
        def runVerifyAndRepair (self):
-               PAR2_CMD = config_get_value ('commands', 'par2repair')
+               PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair')
 
                # assemble the command
                # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
 
                # assemble the command
                # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
@@ -83,7 +82,7 @@ class Base (object):
                                command += "\"%s\" " % os.path.split (f)[1]
 
                # run the command
                                command += "\"%s\" " % os.path.split (f)[1]
 
                # run the command
-               ret = run_command (command, self.dir)
+               ret = rsutil.common.run_command (command, self.dir)
 
                # check the result
                if ret != 0:
 
                # check the result
                if ret != 0:
@@ -93,7 +92,7 @@ class Base (object):
                return SUCCESS
 
        def find_deleteable_files (self):
                return SUCCESS
 
        def find_deleteable_files (self):
-               DELETE_REGEX = config_get_value ('regular expressions', 'delete_regex')
+               DELETE_REGEX = rsutil.common.config_get_value ('regular expressions', 'delete_regex')
                dregex = re.compile (DELETE_REGEX, re.IGNORECASE)
 
                return [f for f in self.all_files if dregex.match (f)]
                dregex = re.compile (DELETE_REGEX, re.IGNORECASE)
 
                return [f for f in self.all_files if dregex.match (f)]
@@ -133,7 +132,7 @@ class Base (object):
        def runDelete (self):
                deleteable_files = self.find_deleteable_files ()
                ret = self.delete_list_of_files (self.dir, deleteable_files, \
        def runDelete (self):
                deleteable_files = self.find_deleteable_files ()
                ret = self.delete_list_of_files (self.dir, deleteable_files, \
-                               options_get_value ('interactive'))
+                               rsutil.common.options_get_value ('interactive'))
 
                return ret
 
 
                return ret
 
@@ -198,7 +197,7 @@ class Base (object):
 
                # Call the extraction function on each head
                for h in self.find_extraction_heads ():
 
                # Call the extraction function on each head
                for h in self.find_extraction_heads ():
-                       full_head = full_abspath (os.path.join (self.dir, h))
+                       full_head = rsutil.common.full_abspath (os.path.join (self.dir, h))
                        ret = self.extraction_function (full_head, todir)
                        logging.debug ('Extraction Function returned: %d' % ret)
 
                        ret = self.extraction_function (full_head, todir)
                        logging.debug ('Extraction Function returned: %d' % ret)
 
index 7385c6f..4ebbfc8 100644 (file)
@@ -3,7 +3,7 @@
 
 import logging
 import PAR2Set.Base
 
 import logging
 import PAR2Set.Base
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is another base class for types that must
 
 #
 # This is another base class for types that must
index f646c89..caed58f 100644 (file)
@@ -3,7 +3,7 @@
 
 import PAR2Set.ExtractFirstBase
 import PAR2Set.NewRAR
 
 import PAR2Set.ExtractFirstBase
 import PAR2Set.NewRAR
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is an old-style rar type
 
 #
 # This is an old-style rar type
@@ -27,8 +27,8 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       return has_a_match ('^.*\.part0*1\.rar$', name_files) \
-                       and not has_a_match ('^.*\.part0*1\.rar$', prot_files)
+       return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', name_files) \
+                       and not rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files)
 
 
 class ExtractFirstNewRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \
 
 
 class ExtractFirstNewRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \
index ae2b1f2..1a45c9e 100644 (file)
@@ -3,7 +3,7 @@
 
 import PAR2Set.ExtractFirstBase
 import PAR2Set.OldRAR
 
 import PAR2Set.ExtractFirstBase
 import PAR2Set.OldRAR
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is an old-style rar type
 
 #
 # This is an old-style rar type
@@ -27,8 +27,8 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       return has_a_match ('^.*\.r00$', name_files) \
-                       and not has_a_match ('^.*\.r00$', prot_files)
+       return rsutil.common.has_a_match ('^.*\.r00$', name_files) \
+                       and not rsutil.common.has_a_match ('^.*\.r00$', prot_files)
 
 
 class ExtractFirstOldRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \
 
 
 class ExtractFirstOldRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \
index c2b055f..58648fa 100644 (file)
@@ -3,7 +3,7 @@
 
 import logging
 import PAR2Set.Base
 
 import logging
 import PAR2Set.Base
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is a regular joined file type
 
 #
 # This is a regular joined file type
@@ -21,8 +21,8 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       return has_a_match ('^.*\.\d\d\d$', name_files) \
-                       and not has_a_match ('^.*\.\d\d\d$', prot_files)
+       return rsutil.common.has_a_match ('^.*\.\d\d\d$', name_files) \
+                       and not rsutil.common.has_a_match ('^.*\.\d\d\d$', prot_files)
 
 
 class Join (PAR2Set.Base.Base):
 
 
 class Join (PAR2Set.Base.Base):
@@ -31,10 +31,10 @@ class Join (PAR2Set.Base.Base):
                return 'JOIN'
 
        def find_joinfiles (self):
                return 'JOIN'
 
        def find_joinfiles (self):
-               return find_matches ('^.*\.\d\d\d$', self.name_matched_files)
+               return rsutil.common.find_matches ('^.*\.\d\d\d$', self.name_matched_files)
 
        def runVerifyAndRepair (self):
 
        def runVerifyAndRepair (self):
-               PAR2_CMD = config_get_value ('commands', 'par2repair')
+               PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair')
 
                # assemble the command
                # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
 
                # assemble the command
                # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
@@ -48,7 +48,7 @@ class Join (PAR2Set.Base.Base):
                        command += "\"%s\" " % os.path.split (f)[1]
 
                # run the command
                        command += "\"%s\" " % os.path.split (f)[1]
 
                # run the command
-               ret = run_command (command, self.dir)
+               ret = rsutil.common.run_command (command, self.dir)
 
                # check the result
                if ret != 0:
 
                # check the result
                if ret != 0:
@@ -63,14 +63,14 @@ class Join (PAR2Set.Base.Base):
        def extraction_function (self, file, todir):
                """Extract a single file of this type to the given directory"""
 
        def extraction_function (self, file, todir):
                """Extract a single file of this type to the given directory"""
 
-               NOEXTRACT_CMD = config_get_value ('commands', 'noextract')
+               NOEXTRACT_CMD = rsutil.common.config_get_value ('commands', 'noextract')
 
                # Make sure that both files are not the same file. If they are, don't run at all.
                if os.path.samefile (file, os.path.join (todir, file)):
                        return SUCCESS
 
                cmd = NOEXTRACT_CMD % (file, todir)
 
                # Make sure that both files are not the same file. If they are, don't run at all.
                if os.path.samefile (file, os.path.join (todir, file)):
                        return SUCCESS
 
                cmd = NOEXTRACT_CMD % (file, todir)
-               ret = run_command (cmd)
+               ret = rsutil.common.run_command (cmd)
 
                # Check error code
                if ret != 0:
 
                # Check error code
                if ret != 0:
index f6702c9..e780ec8 100644 (file)
@@ -2,7 +2,7 @@
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is an new-style rar type
 
 #
 # This is an new-style rar type
@@ -26,7 +26,7 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       return has_a_match ('^.*\.part0*1\.rar$', prot_files)
+       return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files)
 
 
 class NewRAR (PAR2Set.Base.Base):
 
 
 class NewRAR (PAR2Set.Base.Base):
@@ -35,16 +35,16 @@ class NewRAR (PAR2Set.Base.Base):
                return 'NEWRAR'
 
        def find_extraction_heads (self):
                return 'NEWRAR'
 
        def find_extraction_heads (self):
-               return find_matches ('^.*\.part0*1\.rar$', self.all_files)
+               return rsutil.common.find_matches ('^.*\.part0*1\.rar$', self.all_files)
 
        def extraction_function (self, file, todir):
                assert os.path.isfile (file)
                assert os.path.isdir (todir)
 
 
        def extraction_function (self, file, todir):
                assert os.path.isfile (file)
                assert os.path.isdir (todir)
 
-               RAR_CMD = config_get_value ('commands', 'unrar')
+               RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar')
 
                cmd = '%s \"%s\"' % (RAR_CMD, file)
 
                cmd = '%s \"%s\"' % (RAR_CMD, file)
-               ret = run_command (cmd, todir)
+               ret = rsutil.common.run_command (cmd, todir)
 
                # Check error code
                if ret != 0:
 
                # Check error code
                if ret != 0:
index 9c89069..a2639a3 100644 (file)
@@ -2,7 +2,7 @@
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is an old-style rar type
 
 #
 # This is an old-style rar type
@@ -26,7 +26,7 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       return has_a_match ('^.*\.r00$', prot_files)
+       return rsutil.common.has_a_match ('^.*\.r00$', prot_files)
 
 
 class OldRAR (PAR2Set.Base.Base):
 
 
 class OldRAR (PAR2Set.Base.Base):
@@ -35,16 +35,16 @@ class OldRAR (PAR2Set.Base.Base):
                return 'OLDRAR'
 
        def find_extraction_heads (self):
                return 'OLDRAR'
 
        def find_extraction_heads (self):
-               return find_matches ('^.*\.rar', self.all_files)
+               return rsutil.common.find_matches ('^.*\.rar', self.all_files)
 
        def extraction_function (self, file, todir):
                assert os.path.isfile (file)
                assert os.path.isdir (todir)
 
 
        def extraction_function (self, file, todir):
                assert os.path.isfile (file)
                assert os.path.isdir (todir)
 
-               RAR_CMD = config_get_value ('commands', 'unrar')
+               RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar')
 
                cmd = '%s \"%s\"' % (RAR_CMD, file)
 
                cmd = '%s \"%s\"' % (RAR_CMD, file)
-               ret = run_command (cmd, todir)
+               ret = rsutil.common.run_command (cmd, todir)
 
                # Check error code
                if ret != 0:
 
                # Check error code
                if ret != 0:
index f7ddc54..35bc73f 100644 (file)
@@ -2,7 +2,7 @@
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 import PAR2Set.Base
-from RarslaveCommon import *
+import rsutil.common
 
 #
 # This is a regular zip file type
 
 #
 # This is a regular zip file type
@@ -18,8 +18,8 @@ from RarslaveCommon import *
 #
 
 def detector (name_files, prot_files):
 #
 
 def detector (name_files, prot_files):
-       all_files = no_duplicates (name_files + prot_files)
-       return has_a_match ('^.*\.zip$', all_files)
+       all_files = rsutil.common.no_duplicates (name_files + prot_files)
+       return rsutil.common.has_a_match ('^.*\.zip$', all_files)
 
 
 class ZIP (PAR2Set.Base.Base):
 
 
 class ZIP (PAR2Set.Base.Base):
@@ -28,13 +28,13 @@ class ZIP (PAR2Set.Base.Base):
                return 'ZIP'
 
        def find_extraction_heads (self):
                return 'ZIP'
 
        def find_extraction_heads (self):
-               return find_matches ('^.*\.zip', self.all_files)
+               return rsutil.common.find_matches ('^.*\.zip', self.all_files)
 
        def extraction_function (self, file, todir):
 
        def extraction_function (self, file, todir):
-               ZIP_CMD = self.config_get_value ('commands', 'unzip')
+               ZIP_CMD = rsutil.common.config_get_value ('commands', 'unzip')
 
                cmd = ZIP_CMD % (file, todir)
 
                cmd = ZIP_CMD % (file, todir)
-               ret = run_command (cmd)
+               ret = rsutil.common.run_command (cmd)
 
                # Check error code
                if ret != 0:
 
                # Check error code
                if ret != 0:
index 0339336..e9988f9 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
-from RarslaveCommon import *
+import rsutil.common
 
 # PAR2Set-derived types
 import PAR2Set.Join
 
 # PAR2Set-derived types
 import PAR2Set.Join
@@ -31,16 +31,16 @@ class RarslaveDetector (object):
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
-               self.basename = get_basename (p2file)
+               self.basename = rsutil.common.get_basename (p2file)
 
                # Find files that match by name only
 
                # Find files that match by name only
-               self.name_matched_files = find_name_matches (self.dir, self.basename)
+               self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename)
 
                # Find all par2 files for this set using name matches
 
                # Find all par2 files for this set using name matches
-               self.all_p2files = find_par2_files (self.name_matched_files)
+               self.all_p2files = rsutil.common.find_par2_files (self.name_matched_files)
 
                # Try to get the protected files for this set
 
                # Try to get the protected files for this set
-               self.prot_matched_files = parse_all_par2 (self.dir, self.p2file, self.all_p2files)
+               self.prot_matched_files = rsutil.common.parse_all_par2 (self.dir, self.p2file, self.all_p2files)
 
        def runMatchingTypes (self):
                # Now tries to run every type of PAR2Set-derived class for which the detector
 
        def runMatchingTypes (self):
                # Now tries to run every type of PAR2Set-derived class for which the detector
index 16b8c78..a27c334 100644 (file)
@@ -5,13 +5,12 @@ VERSION="2.0.0"
 PROGRAM="rarslave2"
 
 import os, sys, optparse, logging
 PROGRAM="rarslave2"
 
 import os, sys, optparse, logging
+import rsutil
 import RarslaveDetector
 import RarslaveDetector
-import RarslaveGlobals
-from RarslaveCommon import *
 
 
-# Global options from the RarslaveGlobals class
-options = RarslaveGlobals.options
-config = RarslaveGlobals.config
+# Global options from the rsutil.globals class
+options = rsutil.globals.options
+config = rsutil.globals.config
 
 # A tiny class to hold logging output until we're finished
 class DelayedLogger (object):
 
 # A tiny class to hold logging output until we're finished
 class DelayedLogger (object):
@@ -43,13 +42,13 @@ class CompareSet (object):
                self.dir = dir
                self.p2file = p2file
 
                self.dir = dir
                self.p2file = p2file
 
-               self.basename = get_basename (self.p2file)
-               self.name_matches = find_name_matches (self.dir, self.basename)
+               self.basename = rsutil.common.get_basename (self.p2file)
+               self.name_matches = rsutil.common.find_name_matches (self.dir, self.basename)
 
        def __eq__ (self, rhs):
                return (self.dir == rhs.dir) \
                                and (self.basename == rhs.basename) \
 
        def __eq__ (self, rhs):
                return (self.dir == rhs.dir) \
                                and (self.basename == rhs.basename) \
-                               and list_eq (self.name_matches, rhs.name_matches)
+                               and rsutil.common.list_eq (self.name_matches, rhs.name_matches)
 
 
 def find_all_par2_files (dir):
 
 
 def find_all_par2_files (dir):
@@ -62,7 +61,7 @@ def find_all_par2_files (dir):
        dir = os.path.abspath (dir)
        files = os.listdir (dir)
 
        dir = os.path.abspath (dir)
        files = os.listdir (dir)
 
-       return find_par2_files (files)
+       return rsutil.common.find_par2_files (files)
 
 def generate_all_parsets (dir):
        # Generate all parsets in the given directory.
 
 def generate_all_parsets (dir):
        # Generate all parsets in the given directory.
@@ -85,13 +84,13 @@ def check_required_progs():
        shell_not_found = 32512
        needed = []
 
        shell_not_found = 32512
        needed = []
 
-       if run_command ('par2repair --help > /dev/null 2>&1') == shell_not_found:
+       if rsutil.common.run_command ('par2repair --help > /dev/null 2>&1') == shell_not_found:
                needed.append ('par2repair')
 
                needed.append ('par2repair')
 
-       if run_command ('unrar --help > /dev/null 2>&1') == shell_not_found:
+       if rsutil.common.run_command ('unrar --help > /dev/null 2>&1') == shell_not_found:
                needed.append ('unrar')
 
                needed.append ('unrar')
 
-       if run_command ('unzip --help > /dev/null 2>&1') == shell_not_found:
+       if rsutil.common.run_command ('unzip --help > /dev/null 2>&1') == shell_not_found:
                needed.append ('unzip')
 
        if needed:
                needed.append ('unzip')
 
        if needed:
@@ -103,7 +102,7 @@ def check_required_progs():
 def run_options (options):
 
        # Fix directories
 def run_options (options):
 
        # Fix directories
-       options.work_dir = full_abspath (options.work_dir)
+       options.work_dir = rsutil.common.full_abspath (options.work_dir)
 
        # Make sure that the directory is valid
        if not os.path.isdir (options.work_dir):
 
        # Make sure that the directory is valid
        if not os.path.isdir (options.work_dir):
@@ -113,7 +112,7 @@ def run_options (options):
                sys.exit (1)
 
        if options.extract_dir != None:
                sys.exit (1)
 
        if options.extract_dir != None:
-               options.extract_dir = full_abspath (options.extract_dir)
+               options.extract_dir = rsutil.common.full_abspath (options.extract_dir)
 
        if options.version:
                print PROGRAM + ' - ' + VERSION
 
        if options.version:
                print PROGRAM + ' - ' + VERSION
@@ -162,19 +161,16 @@ def main ():
 
        # Build the OptionParser
        parser = optparse.OptionParser()
 
        # Build the OptionParser
        parser = optparse.OptionParser()
-       parser.add_option('-n', '--not-recursive',
-                                               action='store_false', dest='recursive',
-                                               default=config_get_value('options', 'recursive'),
+       parser.add_option('-n', '--not-recursive', action='store_false', dest='recursive',
+                                               default=rsutil.common.config_get_value('options', 'recursive'),
                                                help="Don't run recursively")
 
                                                help="Don't run recursively")
 
-       parser.add_option('-d', '--work-dir',
-                                               dest='work_dir', type='string',
-                                               default=config_get_value('directories', 'working_directory'),
+       parser.add_option('-d', '--work-dir', dest='work_dir', type='string',
+                                               default=rsutil.common.config_get_value('directories', 'working_directory'),
                                                help="Start running at DIR", metavar='DIR')
 
                                                help="Start running at DIR", metavar='DIR')
 
-       parser.add_option('-e', '--extract-dir',
-                                               dest='extract_dir', type='string',
-                                               default=config_get_value('directories', 'extract_directory'),
+       parser.add_option('-e', '--extract-dir', dest='extract_dir', type='string',
+                                               default=rsutil.common.config_get_value('directories', 'extract_directory'),
                                                help="Extract to DIR", metavar='DIR')
 
        parser.add_option('-p', '--check-required-programs',
                                                help="Extract to DIR", metavar='DIR')
 
        parser.add_option('-p', '--check-required-programs',
@@ -191,7 +187,7 @@ def main ():
                                                default=False, help="Write out the current config")
 
        parser.add_option('-i', '--interactive', dest='interactive', action='store_true',
                                                default=False, help="Write out the current config")
 
        parser.add_option('-i', '--interactive', dest='interactive', action='store_true',
-                                               default=config_get_value('options', 'interactive'),
+                                               default=rsutil.common.config_get_value('options', 'interactive'),
                                                help="Confirm before removing files")
 
        parser.add_option('-q', '--quiet', dest='quiet', action='count',
                                                help="Confirm before removing files")
 
        parser.add_option('-q', '--quiet', dest='quiet', action='count',
@@ -207,8 +203,8 @@ def main ():
 
        # Parse the given options
        global options
 
        # Parse the given options
        global options
-       (RarslaveGlobals.options, args) = parser.parse_args()
-       options = RarslaveGlobals.options
+       (rsutil.globals.options, args) = parser.parse_args()
+       options = rsutil.globals.options
 
        # Run any special actions that are needed on these options
        run_options (options)
 
        # Run any special actions that are needed on these options
        run_options (options)
diff --git a/rsutil/__init__.py b/rsutil/__init__.py
new file mode 100644 (file)
index 0000000..73c4551
--- /dev/null
@@ -0,0 +1,7 @@
+import globals
+import common
+import config
+import par2parser
+
+__all__ = ['common', 'globals', 'config', 'par2parser']
+
similarity index 93%
rename from RarslaveCommon.py
rename to rsutil/common.py
index 8ffac91..b633171 100644 (file)
@@ -11,8 +11,8 @@ import os
 import re
 import logging
 
 import re
 import logging
 
-import RarslaveGlobals
-import Par2Parser
+import rsutil.globals
+import rsutil.par2parser
 
 # Global constants
 (SUCCESS, ECHECK, EEXTRACT, EDELETE, ECREATE, EDETECT, EPARSE) = range(7)
 
 # Global constants
 (SUCCESS, ECHECK, EEXTRACT, EDELETE, ECREATE, EDETECT, EPARSE) = range(7)
@@ -90,7 +90,7 @@ def parse_all_par2 (dir, p2head, p2files):
                        break
 
                try:
                        break
 
                try:
-                       files = Par2Parser.get_protected_files (dir, f)
+                       files = rsutil.par2parser.get_protected_files (dir, f)
                        done = True
                except (EnvironmentError, OSError, OverflowError):
                        logging.warning ('Corrupt PAR2 file: %s' % f)
                        done = True
                except (EnvironmentError, OSError, OverflowError):
                        logging.warning ('Corrupt PAR2 file: %s' % f)
@@ -133,12 +133,12 @@ def list_eq (l1, l2):
 # Convience functions for the config
 
 def config_get_value (section, name):
 # Convience functions for the config
 
 def config_get_value (section, name):
-       return RarslaveGlobals.config.get_value (section, name)
+       return rsutil.globals.config.get_value (section, name)
 
 # Convience functions for the options
 
 def options_get_value (name):
 
 # Convience functions for the options
 
 def options_get_value (name):
-       return getattr (RarslaveGlobals.options, name)
+       return getattr (rsutil.globals.options, name)
 
 def main ():
        pass
 
 def main ():
        pass
similarity index 99%
rename from RarslaveConfig.py
rename to rsutil/config.py
index 4ba7adf..17e87d3 100644 (file)
@@ -3,7 +3,7 @@
 
 import os, ConfigParser
 
 
 import os, ConfigParser
 
-class RarslaveConfig (object):
+class config (object):
        """A simple class to hold the default configs for the whole program"""
 
        DEFAULT_CONFIG='~/.config/rarslave2/rarslave2.conf'
        """A simple class to hold the default configs for the whole program"""
 
        DEFAULT_CONFIG='~/.config/rarslave2/rarslave2.conf'
similarity index 89%
rename from RarslaveGlobals.py
rename to rsutil/globals.py
index 0ecc0f0..a57fcd0 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
-import RarslaveConfig
+import rsutil.config
 
 # I know that this sucks majorly, but I kinda need it to keep things
 # sane in the code. I don't /want/ to have to keep passing the config
 
 # I know that this sucks majorly, but I kinda need it to keep things
 # sane in the code. I don't /want/ to have to keep passing the config
@@ -9,7 +9,7 @@ import RarslaveConfig
 
 # This will hold the configuration from the configuration file. This should
 # only be used to hold statically, non-runtime alterable content.
 
 # This will hold the configuration from the configuration file. This should
 # only be used to hold statically, non-runtime alterable content.
-config  = RarslaveConfig.RarslaveConfig ()
+config  = rsutil.config.config ()
 
 # This will hold the configuration from the command-line options. You should
 # probably be using this to get values in most cases. It takes its defaults
 
 # This will hold the configuration from the command-line options. You should
 # probably be using this to get values in most cases. It takes its defaults
similarity index 100%
rename from Par2Parser.py
rename to rsutil/par2parser.py