- if(os.path.isfile(self.filename)):
- with open(self.filename) as f:
- for line in f:
- line="".join(line.split())
- if(line.startswith("#")):
- pass
- elif(line.startswith("library_path=")):
- self.conf["library_path"]=line[13:]
- if(os.path.isdir(self.conf["library_path"])):
- if(not self.conf["library_path"].endswith("/")):
- self.conf["library_path"]+="/"
- elif(line.startswith("custom_path=")):
- self.conf["custom_path"]=line[12:]
- if(os.path.isdir(self.conf["custom_path"])):
- if(not self.conf["custom_path"].endswith("/")):
- self.conf["custom_path"]+="/"
- elif(line.startswith("index_path=")):
- self.conf["index_path"]=line[11:]
- if(os.path.isdir(self.conf["index_path"])):
- if(not self.conf["index_path"].endswith("/")):
- self.conf["index_path"]+="/"
- elif(line.startswith("alias_path=")):
- self.conf["alias_path"]=line[11:]
- if(os.path.isdir(self.conf["alias_path"])):
- if(not self.conf["alias_path"].endswith("/")):
- self.conf["alias_path"]+="/"
- elif(line.startswith("module_path=")):
- self.conf["module_path"]=line[12:]
- if(os.path.isdir(self.conf["module_path"])):
- if(not self.conf["module_path"].endswith("/")):
- self.conf["module_path"]+="/"
- elif(line.startswith("splash_screen=")):
- self.conf["splash_screen"]=line[14:]
- elif(line.startswith("clean_log=")):
- self.conf["clean_log"]=line[10:]
- elif(line.startswith("status_message=")):
- self.conf["status_message"]=line[15:]
- else:
- logging.warning("Unrecognized configuration: "+line)
+ ''' Reads the configuration file and collects the values '''
+ if(os.path.isfile(self.filename)): # If file is actually present
+ try:
+ with open(self.filename) as f: # Open file
+ for line in f:
+ line="".join(line.split()) # Removes any stray whitespaces
+ if(line.startswith("#")): # Ignores comments
+ pass
+ elif(line.startswith("library_path=")): # Library files path
+ self.conf["library_path"]=line[13:]
+ if(os.path.isdir(self.conf["library_path"])):
+ if(not self.conf["library_path"].endswith("/")):
+ self.conf["library_path"]+="/"
+ elif(line.startswith("custom_path=")): # Custom files path
+ self.conf["custom_path"]=line[12:]
+ if(os.path.isdir(self.conf["custom_path"])):
+ if(not self.conf["custom_path"].endswith("/")):
+ self.conf["custom_path"]+="/"
+ elif(line.startswith("index_path=")): # Index files path
+ self.conf["index_path"]=line[11:]
+ if(os.path.isdir(self.conf["index_path"])):
+ if(not self.conf["index_path"].endswith("/")):
+ self.conf["index_path"]+="/"
+ elif(line.startswith("alias_path=")): # Alias files path
+ self.conf["alias_path"]=line[11:]
+ if(os.path.isdir(self.conf["alias_path"])):
+ if(not self.conf["alias_path"].endswith("/")):
+ self.conf["alias_path"]+="/"
+ elif(line.startswith("module_path=")): # Path to save compiled modules
+ self.conf["module_path"]=line[12:]
+ if(os.path.isdir(self.conf["module_path"])):
+ if(not self.conf["module_path"].endswith("/")):
+ self.conf["module_path"]+="/"
+ elif(line.startswith("splash_screen=")): # Whether to show a splash screen
+ self.conf["splash_screen"]=line[14:]
+ elif(line.startswith("clean_log=")): # Whether to clean logs before exit
+ self.conf["clean_log"]=line[10:]
+ elif(line.startswith("status_message=")): # Whether to show status messages
+ self.conf["status_message"]=line[15:]
+ else:
+ logging.warning("Unrecognized configuration: "+line) # Log a warning if unrecognized option found
+ except: # Go with default if file could not be read and log an error
+ logging.error("Configuration file "+self.filename+" could not be read. Using default configurations.")