mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Add documentation for config
This commit is contained in:
		
				
					committed by
					
						
						Davis Goglin
					
				
			
			
				
	
			
			
			
						parent
						
							2bb9756d28
						
					
				
				
					commit
					d5e3d85c4b
				
			@@ -1,3 +1,9 @@
 | 
				
			|||||||
 | 
					""" ESC/POS configuration manager.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This module contains the implentations of abstract base class :py:class:`Config`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from __future__ import absolute_import
 | 
					from __future__ import absolute_import
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
@@ -8,7 +14,11 @@ from . import printer
 | 
				
			|||||||
from . import exceptions
 | 
					from . import exceptions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Config(object):
 | 
					class Config(object):
 | 
				
			||||||
 | 
					    """  Configuration handler class.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This class loads configuration from a default or specificed directory. It
 | 
				
			||||||
 | 
					    can create your defined printer and return it to you.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
    _app_name = 'python-escpos'
 | 
					    _app_name = 'python-escpos'
 | 
				
			||||||
    _config_file = 'config.yaml'
 | 
					    _config_file = 'config.yaml'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,6 +30,12 @@ class Config(object):
 | 
				
			|||||||
        self._printer_config = None
 | 
					        self._printer_config = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def load(self, config_path=None):
 | 
					    def load(self, config_path=None):
 | 
				
			||||||
 | 
					        """ Load and parse the configuration file using pyyaml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        :param config_path: An optional file path, file handle, or byte string
 | 
				
			||||||
 | 
					            for the configuration file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        if not config_path:
 | 
					        if not config_path:
 | 
				
			||||||
            config_path = os.path.join(
 | 
					            config_path = os.path.join(
 | 
				
			||||||
                appdirs.user_config_dir(self._app_name),
 | 
					                appdirs.user_config_dir(self._app_name),
 | 
				
			||||||
@@ -47,6 +63,11 @@ class Config(object):
 | 
				
			|||||||
        self._has_loaded = True
 | 
					        self._has_loaded = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def printer(self):
 | 
					    def printer(self):
 | 
				
			||||||
 | 
					        """ Returns a printer that was defined in the config, or None.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        This method loads the default config if one hasn't beeen already loaded.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        if not self._has_loaded:
 | 
					        if not self._has_loaded:
 | 
				
			||||||
            self.load()
 | 
					            self.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user