over-video/aux.py
2016-05-18 12:59:13 +02:00

61 lines
1.9 KiB
Python

#! /usr/bin/env python3
# encoding: utf-8
import os
import pathlib
import over
# --------------------------------------------------
def parse_fps(raw):
if '/' in raw:
num, den = (int(x) for x in raw.split('/'))
return float(num) / float(den)
return float(raw)
# --------------------------------------------------
def to_Path(raw_path):
'''
Returns pathlib.Path pointing to raw_path, handling '~/' correctly.
To be removed after python:3.5 move.
'''
if raw_path.startswith('~'):
raw_path = os.path.expanduser(raw_path)
return pathlib.Path(raw_path)
# --------------------------------------------------
context_file_header = """# Context file for %s-%s
# This file stores configuration valid for this directory.
# It is updated automatically with options you use.
"""
def update_cfg_context(main, ignore=[]):
"""
All main.options that are sourced from either the cfg file or defaults get overridden by those in .over-video.
Those that are from command line get saved into .over-video.
File format:
name=value
"""
options_to_consider = [option for option in main.options.values() if option.name not in ignore and option.in_cfg_file]
options_to_write = {option.name: option for option in options_to_consider if option.source == over.app.Option_sources.command_line}
options_to_read = {option.name: option for option in options_to_consider if option.source != over.app.Option_sources.command_line}
context_file_read = over.app.ConfigFile(options_to_read, ".over-video")
restored = context_file_read.read_config()
if restored:
main.print("restored from <m>.over-video<.>: %s" %(", ".join("<g>%s<.>" %(o.name) for o in restored)), main.print.tl.note)
context_file_write = over.app.ConfigFile(options_to_write, ".over-video")
added = context_file_write.update_config(context_file_header, (main.name, main.version))
if added:
main.print("added to <m>.over-video<.>: %s" %(", ".join("<g>%s<.>" %(o.name) for o in added)))