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,34 +12,41 @@ import os, sys, re
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import shutil
|
import shutil
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
import logging
|
||||||
|
|
||||||
config = {}
|
def getLogger():
|
||||||
regex = []
|
lgr = logging.getLogger('tvorganise')
|
||||||
|
lgr.addHandler(logging.StreamHandler())
|
||||||
|
return lgr
|
||||||
|
|
||||||
configpsr = ConfigParser.RawConfigParser()
|
def getConfig(file):
|
||||||
configpsr.read('tvorganise.cfg')
|
|
||||||
|
|
||||||
if configpsr.has_section('main'):
|
config = {}
|
||||||
for k, v in configpsr.items('main'):
|
|
||||||
config[k] = v
|
|
||||||
|
|
||||||
if configpsr.has_section('regex'):
|
configpsr = ConfigParser.RawConfigParser()
|
||||||
|
configpsr.read('tvorganise.cfg')
|
||||||
|
|
||||||
|
if configpsr.has_section('main'):
|
||||||
|
for k, v in configpsr.items('main'):
|
||||||
|
config[k] = v
|
||||||
|
|
||||||
|
if configpsr.has_section('regex'):
|
||||||
|
|
||||||
regex_config = {}
|
regex_config = {}
|
||||||
|
regex = []
|
||||||
|
|
||||||
# Load in subs before reading in the regex
|
# Load in subs before reading in the regex
|
||||||
for k, v in configpsr.items('regex'):
|
for k, v in configpsr.items('regex'):
|
||||||
if k[:5] != 'regex':
|
if k[:5] != 'regex':
|
||||||
regex_config[k] = v
|
regex_config[k] = v
|
||||||
|
|
||||||
for k, v in configpsr.items('regex'):
|
for k, v in configpsr.items('regex'):
|
||||||
if k[:5] == 'regex':
|
if k[:5] == 'regex':
|
||||||
print v % regex_config
|
regex.append(re.compile(v % regex_config))
|
||||||
regex.append(re.compile(v % regex_config))
|
|
||||||
|
|
||||||
config['regex'] = regex
|
config['regex'] = regex
|
||||||
|
|
||||||
print config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def findFiles(args):
|
def findFiles(args):
|
||||||
@@ -128,11 +135,27 @@ def main():
|
|||||||
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",
|
||||||
|
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()
|
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 = findFiles(args)
|
||||||
files = processNames(files)
|
files = processNames(files, opts.verbose)
|
||||||
|
|
||||||
# Warn if no files are found, then exit
|
# Warn if no files are found, then exit
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user