HowTo : author Packages - waidyanatha/dongcha GitHub Wiki

Introduction

A package is a file consisting of classes and methods. A package can be imported and inherited to make use of the methods and properties.

Standard class elements

  1. Default property values
  2. Default import packages
  3. init() method

Default property values

There is a mandatory set and you may add any default value

##
## Mandatory default environment variables '''
    __name__ = "scraperUtils"
    __package__ = "scraper"
    __module__ = "ota"
    __app__ = "wrangler"
    __conf_fname__ = "app.ini"
##
## Additional package-specific default values
    __bookings_data__ = "hospitality/bookings/"

Default import packages

The following packages are necessary for the dongcha platform specific utils to work

    import os
    import sys
    import logging
    import traceback
    import configparser

init() method

There are a standard set of required properties that are used across the package

## identifying the class and methods in logs and error messages
    self.__name__ = __name__
    self.__package__ = __package__
    self.__module__ = __module__
    self.__app__ = __app__
    self.__ini_fname__ = __ini_fname__
    self.__desc__ = desc

## defines the package method name to use in error messages
    _s_fn_id = "__init__"

## declares the working and dongcha directory
    self.cwd = os.path.dirname(__file__)
    self.rezHome = config.get("CWDS","DONGCHA")
    self.pckgDir = config.get("CWDS",self.__package__)
    self.appDir = config.get("CWDS",self.__app__)

## declare the logger handler
    self.logger = logs.get_logger(
        cwd=self.rezHome,
        app=self.__app__, 
        module=self.__module__,
        package=self.__package__,
        ini_file=self.__ini_fname__)