From e13c9c644cd762dcc0266dfa6b75fc003454ed61 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Tue, 26 Dec 2006 15:42:10 -0800 Subject: [PATCH] [RARSLAVE] Config-ify rarslave Have rarslave rely on the RarslaveConfig class for all of its configuration needs, such as options, regexes, etc. Signed-off-by: Ira W. Snyder --- rarslave.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/rarslave.py b/rarslave.py index 2e9861a..3f251f3 100644 --- a/rarslave.py +++ b/rarslave.py @@ -3,10 +3,12 @@ import re, os, sys import par2parser +import RarslaveConfig # Global Variables (TYPE_OLDRAR, TYPE_NEWRAR, TYPE_ZIP, TYPE_NOEXTRACT) = range (4) (ECHECK, EEXTRACT, EDELETE) = range(1,4) +config = RarslaveConfig.RarslaveConfig() class RarslaveExtractor (object): @@ -54,7 +56,7 @@ class RarslaveExtractor (object): assert os.path.isfile (file) assert os.path.isdir (todir) - RAR_CMD = 'unrar x -o+ -- ' + RAR_CMD = config.get_value ('commands', 'unrar') cmd = '%s \"%s\"' % (RAR_CMD, file) ret = run_command (cmd, todir) @@ -64,7 +66,7 @@ class RarslaveExtractor (object): return -EEXTRACT def __extract_zip (self, file, todir): - ZIP_CMD = 'unzip \"%s\" -d \"%s\"' + ZIP_CMD = config.get_value ('commands', 'unzip') cmd = ZIP_CMD % (file, todir) ret = run_command (cmd) @@ -76,7 +78,9 @@ class RarslaveExtractor (object): def __extract_noextract (self, file, todir): # Just move this file to the $todir, since no extraction is needed # FIXME: NOTE: mv will fail by itself if you're moving to the same dir! - cmd = 'mv \"%s\" \"%s\"' % (file, todir) + NOEXTRACT_CMD = config.get_value ('commands', 'noextract') + + cmd = NOEXTRACT_CMD % (file, todir) ret = run_command (cmd) # Check error code @@ -100,7 +104,7 @@ class RarslaveRepairer (object): def checkAndRepair (self): # Form the command: # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES] - PAR2_CMD = 'par2repair -- ' + PAR2_CMD = config.get_value ('commands', 'par2repair') # Get set up basename = get_basename (self.file) @@ -159,7 +163,7 @@ def get_filename (f): def get_basename (name): """Strips most kinds of endings from a filename""" - regex = '^(.+)\.(par2|vol\d+\+\d+|\d\d\d|part\d+|rar|zip|avi|mp4|mkv|ogm)$' + regex = config.get_value ('regular expressions', 'basename_regex') r = re.compile (regex, re.IGNORECASE) done = False @@ -189,7 +193,8 @@ def find_likely_files (name, dir): def find_par2_files (files): """Find all par2 files in the list $files""" - regex = re.compile ('^.*\.par2$', re.IGNORECASE) + PAR2_REGEX = config.get_value ('regular expressions', 'par2_regex') + regex = re.compile (PAR2_REGEX, re.IGNORECASE) return [f for f in files if regex.match (f)] def find_all_par2_files (dir): @@ -305,7 +310,8 @@ def is_noextract (files): def find_deleteable_files (files): # Deleteable types regex should come from the config dfiles = [] - dregex = re.compile ('^.*\.(par2|\d|\d\d\d|rar|r\d\d|zip)$', re.IGNORECASE) + DELETE_REGEX = config.get_value ('regular expressions', 'delete_regex') + dregex = re.compile (DELETE_REGEX, re.IGNORECASE) return [f for f in files if dregex.match (f)] @@ -357,15 +363,17 @@ class PAR2Set (object): return -ECHECK # Extraction Stage + EXTRACT_DIR = config.get_value ('directories', 'extract_directory') extractor = find_extraction_heads (self.dir, self.likely_files) - ret = extractor.extract ('extract_dir') # FIXME: Get it from the config + ret = extractor.extract (EXTRACT_DIR) if ret: # FAILURE return -EEXTRACT # Deletion Stage + DELETE_INTERACTIVE = config.get_value ('options', 'interactive') deleteable_files = find_deleteable_files (self.likely_files) - ret = delete_list (deleteable_files) + ret = delete_list (deleteable_files, DELETE_INTERACTIVE) if ret: # FAILURE return -EDELETE -- 2.25.1