From 13eed737dd224c9fdc2074282901f14744ada80c Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 26 Jan 2010 13:20:35 +0000 Subject: [PATCH] PEP8 work, cleanup --- tvorganise.py | 65 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/tvorganise.py b/tvorganise.py index a036d80..e1a065d 100755 --- a/tvorganise.py +++ b/tvorganise.py @@ -8,20 +8,23 @@ filenames and automatically copies them to the location format defined in the configuration file. """ -import os, sys, re +import os +import sys +import re from optparse import OptionParser import shutil import ConfigParser import logging + class TvOrganiser(): - _config = {} + _config = {} - def __init__(self): - pass + def __init__(self): + pass - @property + @property def _logger(self): if not hasattr(self, "__logger"): self.__logger = logging.getLogger(self.__class__.__name__) @@ -58,7 +61,6 @@ class TvOrganiser(): self._config = config return config - def _findFiles(self, args): """ Takes a list of files/folders, grabs files inside them. Does not recurse @@ -81,41 +83,40 @@ class TvOrganiser(): """ allEps = [] for f in names: - filepath, filename = os.path.split( f ) - filename, ext = os.path.splitext( filename ) - + filepath, filename = os.path.split(f) + filename, ext = os.path.splitext(filename) + # Remove leading . from extension ext = ext.replace(".", "", 1) - + for r in config['regex']: match = r.match(filename) if match: showname, seasno, epno, epname = match.groups() - + #remove ._- characters from name (- removed only if next to end of line) showname = re.sub("[\._]|\-(?=$)", " ", showname).strip() - + seasno, epno = int(seasno), int(epno) - + self._logger.debug("File:", filename) self._logger.debug("Pattern:", r.pattern) self._logger.debug("Showname:", showname) self._logger.debug("Seas:", seasno) self._logger.debug("Ep:", epno) - - allEps.append({ 'file_showname':showname, - 'seasno':seasno, - 'epno':epno, - 'filepath':filepath, - 'filename':filename, - 'ext':ext - }) + + allEps.append({'file_showname': showname, + 'seasno': seasno, + 'epno': epno, + 'filepath': filepath, + 'filename': filename, + 'ext': ext}) break # Matched - to the next file! else: self._logger.warning("Invalid name: %s" % (f)) - + return allEps - + def _same_partition(f1, f2): return os.stat(f1).st_dev == os.stat(f2).st_dev @@ -124,18 +125,17 @@ class TvOrganiser(): def main(self): parser = OptionParser(usage="%prog [options] ") parser.add_option("-a", "--always", dest = "always", - action="store_true", default = False, - help="Do not ask for confirmation before copying") + action = "store_true", default = False, + help = "Do not ask for confirmation before copying") parser.add_option("-q", "--quiet", dest = "quiet", - action="store_true", default = False, - help="Silence output") + action = "store_true", default = False, + help = "Silence output") parser.add_option("-c", "--config", dest = "config", - action="store", default = "tvorganise.cfg", - help="Use a custom configuration file") + action = "store", default = "tvorganise.cfg", + help = "Use a custom configuration file") parser.add_option("-v", "", dest = "verbose", - action="store_true", default = False, - help="Verbose output") - + action = "store_true", default = False, + help = "Verbose output") opts, args = parser.parse_args() @@ -160,7 +160,6 @@ class TvOrganiser(): self._logger.info("Old path:", oldfile) self._logger.info("New path:", newfile) - ans= "always" if opts.always: if not os.path.exists(newpath):