Make config paths easier to override
This commit is contained in:
		
							parent
							
								
									92d6579c83
								
							
						
					
					
						commit
						c68fd12d67
					
				@ -1,18 +1,19 @@
 | 
				
			|||||||
import configparser
 | 
					import configparser
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os.path
 | 
					import os
 | 
				
			||||||
 | 
					from os.path import dirname, realpath
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					paths = [
 | 
				
			||||||
 | 
					    "/etc/ankisyncd/ankisyncd.conf",
 | 
				
			||||||
 | 
					    os.environ.get("XDG_CONFIG_HOME") and
 | 
				
			||||||
 | 
					        (os.path.join(os.environ['XDG_CONFIG_HOME'], "ankisyncd", "ankisyncd.conf")) or
 | 
				
			||||||
 | 
					        os.path.join(os.path.expanduser("~"), ".config", "ankisyncd", "ankisyncd.conf"),
 | 
				
			||||||
 | 
					    os.path.join(dirname(dirname(realpath(__file__))), "ankisyncd.conf"),
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def load(path=None):
 | 
					def load(path=None):
 | 
				
			||||||
    dirname = os.path.dirname
 | 
					    choices = paths
 | 
				
			||||||
    realpath = os.path.realpath
 | 
					 | 
				
			||||||
    choices = [
 | 
					 | 
				
			||||||
        "/etc/ankisyncd/ankisyncd.conf",
 | 
					 | 
				
			||||||
        os.environ.get("XDG_CONFIG_DIR") and
 | 
					 | 
				
			||||||
            (os.path.join(os.environ['XDG_CONFIG_DIR'], "ankisyncd", "ankisyncd.conf")) or
 | 
					 | 
				
			||||||
            os.path.join(os.path.expanduser("~"), ".config", "ankisyncd", "ankisyncd.conf"),
 | 
					 | 
				
			||||||
        os.path.join(dirname(dirname(realpath(__file__))), "ankisyncd.conf"),
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
    parser = configparser.ConfigParser()
 | 
					    parser = configparser.ConfigParser()
 | 
				
			||||||
    if path:
 | 
					    if path:
 | 
				
			||||||
        choices = [path]
 | 
					        choices = [path]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user