From 621671f490ec7c7155fed6521449148ad9a8faaf Mon Sep 17 00:00:00 2001 From: mikeos Date: Mon, 7 Oct 2013 00:20:05 +0400 Subject: create default config on startup --- TODO | 2 +- cutter/config.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index a035b6f..232104c 100644 --- a/TODO +++ b/TODO @@ -7,4 +7,4 @@ OK 6. copy file instead of convert if possible OK 7. substitute odd symbols in track names OK 8. add charset coding argument OK 9. prepare setup -10. create default config on startup +OK 10. create default config on startup diff --git a/cutter/config.py b/cutter/config.py index 655c0d6..d1a5f39 100644 --- a/cutter/config.py +++ b/cutter/config.py @@ -6,8 +6,48 @@ try: except ImportError: import ConfigParser as configparser +CONFIG_FILE_PATH = os.path.expanduser("~/.cutter.cfg") + ConfigParserClass = configparser.RawConfigParser +def __create_default(name): + fp = open(name, "w") + + fp.write( +"""[encoding] +# type = + +# where to place new files +dir = . + +# use temporary directory for converted files +use_tempdir = false + +[output] +# sample_rate = +# channels = +# bits_per_sample = + +[filename] +format = %s + +# convert illegal for fat32 filesystem characters +convert_chars = false + +[flac] +# from the least compression (but fastest) to the best compression (but slowest) +# compression = <0 .. 8> + +[ogg] +# from the highest compression (lowest quality) to the lowest compression (highest quality) +# compression = <-1 .. 10> + +[mp3] +# bitrate = <32 .. 320> +""" % DEFAULT_FILENAME_FORMAT) + + fp.close() + def with_default(func, msg = None): def method(cls, section, option, default = None): try: @@ -41,12 +81,12 @@ class CfgParser: DEFAULT_FILENAME_FORMAT = "{tracknumber:02d}.{title}" cfg = CfgParser() -cfg.read(os.path.expanduser("~/.cutter.cfg")) +if not cfg.read(os.path.expanduser(CONFIG_FILE_PATH)): + __create_default(CONFIG_FILE_PATH) DIR = cfg.get("encoding", "dir", ".") TYPE = cfg.get("encoding", "type") USE_TEMPDIR = cfg.getbool("encoding", "use_tempdir") -COMPRESSION = cfg.getint("encoding", "compression") SAMPLE_RATE = cfg.getint("output", "sample_rate") CHANNELS = cfg.getint("output", "channels") -- cgit v1.2.3-70-g09d2