mirror of
https://github.com/nikdoof/tvorganise.git
synced 2025-12-13 06:42:16 +00:00
Added options to specify custom config and verbosity.
This commit is contained in:
@@ -12,9 +12,16 @@ import os, sys, re
|
||||
from optparse import OptionParser
|
||||
import shutil
|
||||
import ConfigParser
|
||||
import logging
|
||||
|
||||
def getLogger():
|
||||
lgr = logging.getLogger('tvorganise')
|
||||
lgr.addHandler(logging.StreamHandler())
|
||||
return lgr
|
||||
|
||||
def getConfig(file):
|
||||
|
||||
config = {}
|
||||
regex = []
|
||||
|
||||
configpsr = ConfigParser.RawConfigParser()
|
||||
configpsr.read('tvorganise.cfg')
|
||||
@@ -26,6 +33,7 @@ if configpsr.has_section('main'):
|
||||
if configpsr.has_section('regex'):
|
||||
|
||||
regex_config = {}
|
||||
regex = []
|
||||
|
||||
# Load in subs before reading in the regex
|
||||
for k, v in configpsr.items('regex'):
|
||||
@@ -34,12 +42,11 @@ if configpsr.has_section('regex'):
|
||||
|
||||
for k, v in configpsr.items('regex'):
|
||||
if k[:5] == 'regex':
|
||||
print v % regex_config
|
||||
regex.append(re.compile(v % regex_config))
|
||||
|
||||
config['regex'] = regex
|
||||
|
||||
print config
|
||||
return config
|
||||
|
||||
|
||||
def findFiles(args):
|
||||
@@ -128,11 +135,27 @@ def main():
|
||||
parser.add_option("-a", "--always", dest = "always",
|
||||
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")
|
||||
parser.add_option("-c", "--config", dest = "config",
|
||||
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")
|
||||
|
||||
|
||||
opts, args = parser.parse_args()
|
||||
|
||||
if os.path.exists(opts.config):
|
||||
config = getConfig(opts.config)
|
||||
else:
|
||||
print 'Unable to find configuration file!'
|
||||
sys.exit(1)
|
||||
|
||||
files = findFiles(args)
|
||||
files = processNames(files)
|
||||
files = processNames(files, opts.verbose)
|
||||
|
||||
# Warn if no files are found, then exit
|
||||
if len(files) == 0:
|
||||
|
||||
Reference in New Issue
Block a user