Package XPyTools :: Package codetpl :: Module codetpl :: Class CodeTemplateMngr
[hide private]
[frames] | no frames]

Class CodeTemplateMngr

source code

object --+
         |
        CodeTemplateMngr

Manager of code templates.

Provide all functionalities with templates.

Instance Methods [hide private]
 
__get_Errors(self) source code
 
__del_Errors(self) source code
 
__init__(self, spath=[], usedefault=True)
Initialize class.
source code
str or list[(name, value)]
GetConfig(self, section, option=None, default='')
Return preferences from configuration files.
source code
None
Reload(self)
Re/Load template and config modules.
source code
list
GetTemplates(self, type_, filter={}, retIfAbsent=False)
Get list of available templates given type.
source code
tuple
GetMetaInfo(self, type_, name)
Get metainformation for requested template.
source code
list
GetMetaAllValues(self, type_, metaname)
Get list of all values find in given type for given metaname.
source code
str
ParseTemplate(self, type, name, fields, srcfile='', params={})
Parse template used given fields or return preview.
source code
str
ReplaceTemplate(self, tpl, fields, kwds=None, brds='@', case=False, srcfile='', params={})
Parse template tpl.
source code
boolean.
HasType(self, type_)
Test - has such type or not.
source code
string
GetSourceFile(self)
Get edited surce file.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Instance Variables [hide private]
list Errors
List of errors string (copy, not original).
string = '' __srcfile
Edited source file, from which called templates.
SafeConfigParser __config
SafeConfigParser instance.
list = [] __mdls
Loaded module's names.
dict = {} __kwds
Keywords functions readed from files: {"FullMame=???_*",Code_object}.
dict = {} __tpls
Other templates.
dict = {} __tplsmeta
Templates meta (all for keywords and other).
list = [] __errs
Errors list.
list = [] __types
Available types for templates.
list[str] paths to folders with templates. __path
List paths to templates.
bool = True __usedefault
If true then load global and user config files and if allow use global templates.
list __metanames
Names for available fields of metainformation (must present).
list __metare
Regular exspression for metainformation fields (must present).
Properties [hide private]
  Types
List of available templates types (copy, not original).
  MetaNames
List of available metanames (copy, not original).
  SourceFile
Source file which editing in the editor.

Inherited from object: __class__

Method Details [hide private]

__init__(self, spath=[], usedefault=True)
(Constructor)

source code 
Initialize class.
Parameters:
  • spath (list[string] = []) - List of absolute paths to templates folders. If empty string (or False) then set default path == "... /codetpl/templates/"
  • usedefault (bool = True) - If true then load global and user config files and if allow use global templates. Otherwise use only path from spath.
Raises:
  • codetplArgumentError - Template path does not exist. May raise for default path or user specified.
Overrides: object.__init__

Warning: Into initialization folder must be placed configuration file codetpl.cfg else wil be used default values (see module description).

GetConfig(self, section, option=None, default='')

source code 

Return preferences from configuration files.

You may get option value or section items:
  • Option. If option not exist then return default value.
  • Section. For get section items you must leave option parameter empty or set to None. If no such section then return empty list [].
Parameters:
  • section (str) - Section name.
  • option (str='') - Option name.
  • default (str='') - Default value.
Returns: str or list[(name, value)]
Configuration value or list of items for section.

Reload(self)

source code 

Re/Load template and config modules.

Clear previous loaded modules and reload all noe finded. All loaded template modules into __mdls, naming is as "_codetpl_???_*". Walk throw all loaded modules and fill __kwds and __tpls dictionaries.
Returns: None
None.

GetTemplates(self, type_, filter={}, retIfAbsent=False)

source code 

Get list of available templates given type.

type must be one from Types(). If no such type then raise codetplArgumentError.

type are case insensetive (converts to lower).

Filter contains dictionary {name:listofvalues} where listofvalues may be tuple, list or other iterable or str (converted to single tuple). Filter do only from given metanames other is always done.
Parameters:
  • type_ (str) - Type of templates.
  • filter (dict=empty) - Filter from metainformation fields.
  • retIfAbsent (boolean=False) - If metanames from filter absent in templates then if True return this template, if False then skip.
Returns: list
List of templates name for given type.
Raises:

GetMetaInfo(self, type_, name)

source code 

Get metainformation for requested template.

If type or name is absant then return ('',{})
Parameters:
  • type_ (str) - Template type.
  • name - Template name. @type str
Returns: tuple
Tuple of str and dict ('docstr', {'metaname' : 'metavalue'})

Warning: Returned value is not copy, it saved object. If you change it you change metainformation.

GetMetaAllValues(self, type_, metaname)

source code 
Get list of all values find in given type for given metaname.
Parameters:
  • type_ (str) - Template type.
  • metaname - Metaname. @type str
Returns: list
List of all values find in given type for given metaname.

ParseTemplate(self, type, name, fields, srcfile='', params={})

source code 

Parse template used given fields or return preview.

type and name are case insensetive (converts to lower).

If you get empty fields then for all finded keywords will be assigned it's name. It's used for preview template. For real parse you may set into fields neded values.
Parameters:
  • type (str) - Template type. See Types.
  • name (str) - Template name.
  • fields (dict) - Fields of keywods: {"name":"value"}. Changed by this function to finded keywords.
  • srcfile (str ='') - Source file, which editing into editor.
  • params (dict = {}) - Additional parameters. (Usually for boa constructor its 'model' and 'view' objects).
Returns: str
Parsed template, and changed fields (added new).

ReplaceTemplate(self, tpl, fields, kwds=None, brds='@', case=False, srcfile='', params={})

source code 
Parse template tpl. Change all fields rounded borders brd to value of fields. If fields not find then try search into kwds. If not find then use fields key as value.
Parameters:
  • tpl (str) - Template string to parse with fields.
  • fields (dict) - Fields for search and replace into tpl.
  • kwds (None, str or dict{key: str or func()}) - Keywords for search if not find into fields.
    • If None then use instance __kwds.
    • If dict then its value may be:
      • str - use directly.
      • function - call with no arguments, must return string.
  • brds (str = '@') - Borders wrapped around keys. Twice brds is parsed as single character 'brds'.
  • case (boolean = False) - If True then keys is casesensetive.
  • srcfile (str ='') - Source file, which editing into editor.
  • params (dict = {}) - Additional parameters. (Usually for boa constructor its 'model' and 'view' objects).
Returns: str
Replaced template, and changed fields (added new).

HasType(self, type_)

source code 

Test - has such type or not.

It's more perfomance then use 'type' in Types, becouse it use inner fields, then return copy.

type are case insensetive (converts to lower).
Parameters:
  • type_ (str) - Tested template type.
Returns: boolean.
True if has, else False.

GetSourceFile(self)

source code 
Get edited surce file.
Returns: string
Source file path or '' if no.

Instance Variable Details [hide private]

Errors

List of errors string (copy, not original).
Get Method:
XPyTools.codetpl.codetpl.CodeTemplateMngr.__get_Errors(self)
Set Method:
None
Delete Method:
XPyTools.codetpl.codetpl.CodeTemplateMngr.__del_Errors(self)

__tpls

Other templates. {"FullMame=???_*" : func_object}
Type:
dict = {}

__tplsmeta

Templates meta (all for keywords and other). { "FullMame=???_*" : {"metaname" : "metavalue"} }
Type:
dict = {}

__errs

Errors list. You must clear it's self. Auto clear then Reload() calls.
Type:
list = []

__usedefault

If true then load global and user config files and if allow use global templates. Otherwise use only path from spath.
Type:
bool = True

Property Details [hide private]

Types

List of available templates types (copy, not original). Type - list.
Get Method:
unreachable.Types(self) - List of available templates types (copy, not original).
Set Method:
None
Delete Method:
None

MetaNames

List of available metanames (copy, not original). Type - list.
Get Method:
unreachable.MetaNames(self) - List of available metanames (copy, not original).
Set Method:
None
Delete Method:
None

SourceFile

Source file which editing in the editor. Type - str = ''
Get Method:
unreachable.SourceFile(self) - Source file which editing in the editor.
Set Method:
None
Delete Method:
None