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:
@echo "Use another target, this has no meaning"
clean:
@echo "Use another target, this has no meaning"
clean:
+ find -name '*.pyc' -exec rm -f '{}' \;
#!/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
# 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]
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:
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)]
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'))
# 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)
import logging
import PAR2Set.Base
import logging
import PAR2Set.Base
-from RarslaveCommon import *
#
# This is another base class for types that must
#
# This is another base class for types that must
import PAR2Set.ExtractFirstBase
import PAR2Set.NewRAR
import PAR2Set.ExtractFirstBase
import PAR2Set.NewRAR
-from RarslaveCommon import *
#
# This is an old-style rar type
#
# This is an old-style rar type
#
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, \
import PAR2Set.ExtractFirstBase
import PAR2Set.OldRAR
import PAR2Set.ExtractFirstBase
import PAR2Set.OldRAR
-from RarslaveCommon import *
#
# This is an old-style rar type
#
# This is an old-style rar type
#
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, \
import logging
import PAR2Set.Base
import logging
import PAR2Set.Base
-from RarslaveCommon import *
#
# This is a regular joined file type
#
# This is a regular joined file type
#
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):
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]
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:
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:
# 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 *
#
# This is an new-style rar type
#
# This is an new-style rar type
#
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):
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:
# 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 *
#
# This is an old-style rar type
#
# This is an old-style rar type
#
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):
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:
# 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 *
#
# This is a regular zip file type
#
# This is a regular zip file type
#
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):
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:
#!/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 *
# PAR2Set-derived types
import PAR2Set.Join
# PAR2Set-derived types
import PAR2Set.Join
# 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
PROGRAM="rarslave2"
import os, sys, optparse, logging
PROGRAM="rarslave2"
import os, sys, optparse, logging
-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):
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):
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.
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:
- 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:
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):
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
# 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',
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',
# 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)
--- /dev/null
+import globals
+import common
+import config
+import par2parser
+
+__all__ = ['common', 'globals', 'config', 'par2parser']
+
-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)
- 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)
# 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)
-class RarslaveConfig (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'
#!/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:
# 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
# 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