ESA.util.otool_menu_m
index
/home/lfeng/otool/ESA/util/otool_menu_m.py

class and functions for extracting options from  xml or text configuration  files
 
  Authors: L. Feng, Edinburgh University
  History: v0.9, 2012.12.08
  History: v0.95, 2013.03.24
  
 
  
  Class
  =================================================================
  1. menu_cl: class for menu list (ie., configure options)
  
  Functions:
  ==================================================================
  1. txt_to_menu: read text file to class menu_cl 
  2. xml_to_menu: read xml file to  class menu_cl
 
  3. update_menu_from_text: update menu class using text lines 
  4. update_menu_from_element: update menu class using element

 
Modules
       
ESA.util.geo_constant
ESA.util.message_m
numpy
ESA.util.otool_obj
ESA.util.time_module

 
Classes
       
menu_cl

 
class menu_cl
    Members:
--------------------------------------------------------
1. menu_item:<dict>: menu chain 
2. attr_dict:<dict>: attributes
 
 
Functions:
--------------------------------------------------------
1. __getitem__: overriding index function ('[]') to check dictionary entry of self.menu_item
2. delete_menu:  remove item from self.menu_item
3. update_menu:  Add or update menu item
4. get_attr:  get attribute 
5. set_attr:  set attribute 
6. print_menu:  print out what is in the menu chain
 
 
Notes:
-------------------------------------------------------------
1. menu_cl is designed to be a container for dictionary trees so it can have a nested structure like:
   Menu P---->Menu C1 
   ---->Menu C2
   etc
   Consquently item under sub-menu (for example menu C1) will be accessed using the 
   full name of menu chain separated by '.' (for example  P.C1.itemname)  
 
2. special words:   __load; __dict; __list;
   ---> __load: If an item value is given as a string in form of  '__load:module_name:module_member' ,  
   self.update_menu will try to import this module, and then assign its corresponding member to the menu item. 
 
   ---> __dict: if an item value is given as a string in form of '__dict:a=x, b=y, ..., 
   self.update_menu will create a dictionary as {'a':x, 'b':y,,.} under the item's name
   
   ---> __list: if an item value is given as a string in form of '__list:a, b, ..., 
   self.update_menu will create a list as [a, b, c] under the item's name
 
  Methods defined here:
__getitem__(self, itemname)
Overriding index function
 
Inputs:
----------------------------------------------------
1. itemname: <str>: name of the menu item to be checked 
 
 
Outputs:
--------------------------------------------------
1. value: the menu value if found 
 
 
Notes:
--------------------------------------
1. if itemname contains '.' (for example  M1.M2.M3), the value will be searched down through chain 
of menu classes (such as M1-->M2--M3)
__init__(self, **menu_dict)
initialization
 
Inputs:
----------------------------------
1. menu_dict:<dict>: menu
delete_menu(self, menu_name)
remove item from self.menu_item
Inputs:
------------------------------------
1. menu_name:<str>: name of the menu to be deleted
get_attr(self, attr_name)
get attribute of the object 
 
Inputs:
------------------------------------------
1.attr_name:<str>: attribut name 
 
Returns:
------------------------------------------
1. val:<obj>: attribute
print_menu(self, parentname='')
print out what is in the menu chain
set_attr(self, attr_name, attr_value)
set attribute  of the object 
 
Inputs:
------------------------------------------
1.attr_name:<str>: attribute name 
2.attr_value:<obj>: attribute value
update_menu(self, menu_name, menu_val)
 Add or update menu item
 
 Inputs:
 --------------------------------------------
 1. menu_name:<str>: name of the menu 
 2. menu_val: <obj>: value 
 
 
 Notes:
 --------------------------------------
 1. if itemname contains '.' (for example  M1.M2.M3), the value will be added or updated down through 
 the chain of menu classes (such as M1-->M2--M3)
 
 2. special words:   __load; __dict; __list;
---> __load: If an item value is given as a string in form of  '__load:module_name:module_member' ,  
self.update_menu will try to import this module, and then assign its corresponding member to the menu item. 
 
---> __dict: if an item value is given as a string in form of '__dict:a=x, b=y, ..., 
self.update_menu will create a dictionary as {'a':x, 'b':y,,.} under the item's name
 
---> __list: if an item value is given as a string in form of '__list:a, b, ..., 
self.update_menu will create a list as [a, b, c] under the item's name
 
---> __range: if an item value is given as a string in form of '__range:a, b, c, 
self.update_menu will create a array as arange(a, b, c) under the item's name

 
Functions
       
preprocess_text(lines)
preprocess text line 
Inputs:
----------------------------------------------------
1. lines:<list, t:str>: lines to be prepressing 
 
Returns:
--------------------------------------------
1. new_lines<list, t:str>: lines after being  prepressing
2. para_dict:<dict>: parameters found. 
 
 
Notes:
1. the parameter block begin with #SETP and end with #ENDP
2. defined parameters will be used to replace $PARANAME$ in text lines.
txt_to_menu(flnm)
function to convert txt file into menu 
 
Inputs:
 
-------------------------------------
1.flnm :<str>: name for txt file 
 
Returns:
----------------------------------
1. root_menu:<menu_cl>: menu read from file
update_menu_from_element(parent_menu, parent_mname, element)
Updatemenu class using element 
 
Inputs:
-------------------------------------------
1. parent_menu:<menu_cl>: menu class 
2. parent_mname:<str>: name of the menu class
3. element:<elment>: element class
 
Returns:
------------------------------------
1. parent_menu:<menu_cl>: updated menu class
update_menu_from_text(parent_menu, lines)
Update menu class using text lines 
 
Inputs:
-------------------------------------------
1. parent_menu:<menu_cl>: parent menu 
2. lines: lines will be go through
 
Returns:
-----------------------------------------------------
1. parent_menu:<menu_cl>: update parent menu
xml_to_menu(flnm)
function to convert xml file into menu 
 
Inputs:
-------------------------------------
1.flnm :<str>: name for xml
 
Returns:
----------------------------------
1. root_menu:<menu_cl>: menu read from file