No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python_factory.py 1.1KB

1234567891011121314151617181920212223242526
  1. #-*- coding: utf-8 -*-
  2. import os
  3. ## @brief Abstract class designed to generate python code files
  4. # @note implemented by leapi.lefactory.LeFactory and acl.factory.AclFactory classes
  5. class PythonFactory(object):
  6. ## @brief Instanciate the generator
  7. # @param code_filename str : the output filename for python code
  8. def __init__(self, code_filename):
  9. if self.__class__ == PythonFactory:
  10. raise NotImplementedError("Abtract class")
  11. self._code_filename = code_filename
  12. self._dyn_file = os.path.basename(code_filename)
  13. self._modname = os.path.dirname(code_filename).strip('/').replace('/', '.') #Warning Windaube compatibility
  14. ## @brief Create dynamic code python file
  15. # @param *args : positional arguments forwarded to generate_python() method
  16. # @param **kwargs : named arguments forwarded to generate_python() method
  17. def create_pyfile(self, *args, **kwargs):
  18. with open(self._code_filename, "w+") as dynfp:
  19. dynfp.write(self.generate_python(*args, **kwargs))
  20. def generate_python(self, *args, **kwargs):
  21. raise NotImplemented("Abtract method")