Show
Ignore:
Timestamp:
11/14/08 17:48:21 (16 months ago)
Author:
JensDiemer
Message:

CodeSnippets/VideoTools?: many updates for eac3to.py

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • CodeSnippets/VideoTools/shared/config.py

    r1790 r1797  
    66from ConfigParser import RawConfigParser 
    77 
    8 from tools import askopenfilename2, askdirectory2 
     8from tk_tools import askopenfilename2, askdirectory2 
    99 
    1010 
     
    1414    "out_dir": "", 
    1515 
    16     "skip_size": 100 * 1024 * 1024, 
     16    "glob": "*.m2ts", 
     17    "skip_size": 200 * 1024 * 1024, 
    1718    "stream_dir": "BDMV\\STREAM", 
    1819    "out_video_ext": "mkv", 
     
    3940class PickleConfig(dict): 
    4041 
    41     def __init__(self): 
    42         self.update(DEFAULT_CONFIG) 
     42    def __init__(self, filename, defaults={}): 
     43        self.filename = filename 
    4344         
    44         if os.path.isfile(CONFIG_FILENAME): 
     45        self.update(defaults) 
     46         
     47        if not os.path.isfile(self.filename): 
     48            print "Info: Config file '%s' doesn't exist, yet." % self.filename 
     49        else: 
     50            print "Reading '%s'..." % self.filename 
    4551            try: 
    46                 f = file(CONFIG_FILENAME, "r") 
     52                f = file(filename, "r") 
    4753            except IOError, err: 
    4854                print "Error reading config:", err 
     
    5157                f.close() 
    5258                self.update(pickle_data) 
     59         
    5360 
    5461    def save_config(self): 
    55         print "Save config to '%s'..." % CONFIG_FILENAME, 
    56         f = file(CONFIG_FILENAME, "w") 
     62        print "Save '%s'..." % self.filename, 
     63        f = file(self.filename, "w") 
    5764        pickle.dump(self, f) 
    5865        f.close() 
     
    6067 
    6168    def debug(self): 
    62         print "Debug config:" 
     69        print "PickleConfig debug:" 
    6370        pprint(self) 
    6471        print "-"*80 
     
    6875class VideoToolsConfig(PickleConfig): 
    6976    def __init__(self): 
    70         super(VideoToolsConfig, self).__init__() 
     77        super(VideoToolsConfig, self).__init__(CONFIG_FILENAME, DEFAULT_CONFIG) 
    7178         
    7279        # Check/set the path to all EXE files 
     
    97104        ) 
    98105        self.out_dir_set = True 
    99         self.save_config() 
    100106         
    101107 
     
    103109    from pprint import pprint 
    104110 
    105     CONFIG_FILENAME = "config_test.ini" 
    106     if os.path.isfile(CONFIG_FILENAME): 
    107         os.remove(CONFIG_FILENAME) 
     111    test_config = "config_test.ini" 
     112    if os.path.isfile(test_config): 
     113        os.remove(test_config) 
    108114 
    109115    # Simple Test 
    110     c = PickleConfig() 
     116    c = PickleConfig(test_config, DEFAULT_CONFIG) 
    111117    c.debug() 
    112118    print "-"*80 
     
    118124    print "-"*80 
    119125    # Reopen the written ini file: 
    120     c = PickleConfig() 
     126    c = PickleConfig(test_config) 
    121127    c.debug()