PEP8 work, cleanup

This commit is contained in:
2010-01-26 13:20:35 +00:00
parent 18f8e298fd
commit 13eed737dd

View File

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