Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve morituri configuration handling, help #141

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,33 @@ when possible.
It lives in `$XDG_CONFIG_HOME/morituri/morituri.conf`

The configuration file follows python's ConfigParser syntax.
There is a "main" section and zero or more sections starting with "drive:"

- main section:
The possible sections are:

- main section: [main]
- `path_filter_fat`: whether to filter path components for FAT file systems
- `path_filter_special`: whether to filter path components for special
characters

- drive section:
- drive section: [drive:IDENTIFIER], one for each configured drive
All these values are probed by morituri and should not be edited by hand.
- `defeats_cache`: whether this drive can defeat the audio cache
- `read_offset`: the read offset of the drive

- rip command section: [rip.COMMAND.SUBCOMMAND]
Can be used to change the command options default values.

Example section to configure "rip cd rip" defaults:

[rip.cd.rip]
unknown = True
output_directory = ~/My Music
track_template = new/%%A/%%y - %%d/%%t - %%n
disc_template = %(track_template)s
profile = flac

Note: to get a literal '%' character it must be doubled.

CONTRIBUTING
------------
- Please send pull requests through github.
Expand Down
27 changes: 27 additions & 0 deletions morituri/common/logcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ def __init__(self, parentCommand=None, **kwargs):
command.Command.__init__(self, parentCommand, **kwargs)
self.logCategory = self.name

def parse(self, argv):
cmd = self.getRootCommand()
if hasattr(cmd, 'config'):
config = cmd.config
# find section name
cmd = self
section = []
while cmd is not None:
section.insert(0, cmd.name)
cmd = cmd.parentCommand
section = '.'.join(section)
# get defaults from config
defaults = {}
for opt in self.parser.option_list:
if opt.dest is None:
continue
if 'string' == opt.type:
val = config.get(section, opt.dest)
elif opt.action in ('store_false', 'store_true'):
val = config.getboolean(section, opt.dest)
else:
val = None
if val is not None:
defaults[opt.dest] = val
self.parser.set_defaults(**defaults)
command.Command.parse(self, argv)

# command.Command has a fake debug method, so choose the right one

def debug(self, format, *args):
Expand Down
15 changes: 11 additions & 4 deletions morituri/rip/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,13 @@ def addOptions(self):
help="output directory; will be included in file paths in result "
"files "
"(defaults to absolute path to current directory; set to "
"empty if you want paths to be relative instead) ")
"empty if you want paths to be relative instead; "
"configured value: %default) ")
self.parser.add_option('-W', '--working-directory',
action="store", dest="working_directory",
help="working directory; morituri will change to this directory "
"and files will be created relative to it when not absolute ")
"and files will be created relative to it when not absolute "
"(configured value: %default) ")

rcommon.addTemplate(self)

Expand All @@ -223,8 +225,8 @@ def addOptions(self):

self.parser.add_option('', '--profile',
action="store", dest="profile",
help="profile for encoding (default '%s', choices '%s')" % (
default, "', '".join(encode.PROFILES.keys())),
help="profile for encoding (default '%%default', choices '%s')" % (
"', '".join(encode.PROFILES.keys())),
default=default)
self.parser.add_option('-U', '--unknown',
action="store_true", dest="unknown",
Expand Down Expand Up @@ -254,6 +256,11 @@ def handleOptions(self, options):
options.offset)
if self.options.output_directory is None:
self.options.output_directory = os.getcwd()
else:
self.options.output_directory = os.path.expanduser(self.options.output_directory)

if self.options.working_directory is not None:
self.options.working_directory = os.path.expanduser(self.options.working_directory)

if self.options.logger:
try:
Expand Down