Changeset 1797 for CodeSnippets/VideoTools/shared/config.py
- Timestamp:
- 11/14/08 17:48:21 (16 months ago)
- Files:
-
- 1 modified
-
CodeSnippets/VideoTools/shared/config.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/VideoTools/shared/config.py
r1790 r1797 6 6 from ConfigParser import RawConfigParser 7 7 8 from t ools import askopenfilename2, askdirectory28 from tk_tools import askopenfilename2, askdirectory2 9 9 10 10 … … 14 14 "out_dir": "", 15 15 16 "skip_size": 100 * 1024 * 1024, 16 "glob": "*.m2ts", 17 "skip_size": 200 * 1024 * 1024, 17 18 "stream_dir": "BDMV\\STREAM", 18 19 "out_video_ext": "mkv", … … 39 40 class PickleConfig(dict): 40 41 41 def __init__(self ):42 self. update(DEFAULT_CONFIG)42 def __init__(self, filename, defaults={}): 43 self.filename = filename 43 44 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 45 51 try: 46 f = file( CONFIG_FILENAME, "r")52 f = file(filename, "r") 47 53 except IOError, err: 48 54 print "Error reading config:", err … … 51 57 f.close() 52 58 self.update(pickle_data) 59 53 60 54 61 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") 57 64 pickle.dump(self, f) 58 65 f.close() … … 60 67 61 68 def debug(self): 62 print " Debug config:"69 print "PickleConfig debug:" 63 70 pprint(self) 64 71 print "-"*80 … … 68 75 class VideoToolsConfig(PickleConfig): 69 76 def __init__(self): 70 super(VideoToolsConfig, self).__init__( )77 super(VideoToolsConfig, self).__init__(CONFIG_FILENAME, DEFAULT_CONFIG) 71 78 72 79 # Check/set the path to all EXE files … … 97 104 ) 98 105 self.out_dir_set = True 99 self.save_config()100 106 101 107 … … 103 109 from pprint import pprint 104 110 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) 108 114 109 115 # Simple Test 110 c = PickleConfig( )116 c = PickleConfig(test_config, DEFAULT_CONFIG) 111 117 c.debug() 112 118 print "-"*80 … … 118 124 print "-"*80 119 125 # Reopen the written ini file: 120 c = PickleConfig( )126 c = PickleConfig(test_config) 121 127 c.debug()