<s> from ajenti . api import * <EOL> from ajenti . plugins . main . api import SectionPlugin <EOL> from ajenti . plugins import manager <EOL> from ajenti . ui import on <EOL> from ajenti . ui . binder import Binder , DictAutoBinding <EOL> from api import Task , TaskDefinition , JobDefinition <EOL> from manager import TaskManager <EOL> @ plugin <EOL> class Tasks ( SectionPlugin ) : <EOL> def init ( self ) : <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> self . icon = '<STR_LIT>' <EOL> self . category = _ ( '<STR_LIT>' ) <EOL> self . append ( self . ui . inflate ( '<STR_LIT>' ) ) <EOL> self . manager = TaskManager . get ( ) <EOL> self . binder = Binder ( None , self ) <EOL> def post_td_bind ( object , collection , item , ui ) : <EOL> if item . get_class ( ) : <EOL> params_ui = self . ui . inflate ( item . get_class ( ) . ui ) <EOL> item . binder = DictAutoBinding ( item , '<STR_LIT>' , params_ui . find ( '<STR_LIT>' ) ) <EOL> item . binder . populate ( ) <EOL> ui . find ( '<STR_LIT>' ) . empty ( ) <EOL> ui . find ( '<STR_LIT>' ) . append ( params_ui ) <EOL> def post_td_update ( object , collection , item , ui ) : <EOL> if hasattr ( item , '<STR_LIT>' ) : <EOL> item . binder . update ( ) <EOL> def post_rt_bind ( object , collection , item , ui ) : <EOL> def abort ( ) : <EOL> item . abort ( ) <EOL> self . refresh ( ) <EOL> ui . find ( '<STR_LIT>' ) . on ( '<STR_LIT>' , abort ) <EOL> self . find ( '<STR_LIT>' ) . post_item_bind = post_td_bind <EOL> self . find ( '<STR_LIT>' ) . post_item_update = post_td_update <EOL> self . find ( '<STR_LIT>' ) . post_item_bind = post_rt_bind <EOL> self . find ( '<STR_LIT>' ) . new_item = lambda c : JobDefinition ( ) <EOL> def on_page_load ( self ) : <EOL> self . refresh ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def refresh ( self ) : <EOL> self . manager . refresh ( ) <EOL> self . binder . unpopulate ( ) <EOL> dd = self . find ( '<STR_LIT>' ) <EOL> dd . labels = [ ] <EOL> dd . values = [ ] <EOL> for task in Task . get_classes ( ) : <EOL> if not task . hidden : <EOL> dd . labels . append ( task . name ) <EOL> dd . values . append ( task . classname ) <EOL> dd = self . find ( '<STR_LIT>' ) <EOL> dd . labels = [ _ . name for _ in self . manager . task_definitions ] <EOL> dd . values = [ _ . id for _ in self . manager . task_definitions ] <EOL> self . find ( '<STR_LIT>' ) . labels = dd . labels <EOL> self . find ( '<STR_LIT>' ) . values = dd . values <EOL> self . binder . setup ( self . manager ) . populate ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def on_run_task ( self ) : <EOL> self . manager . run ( task_id = self . find ( '<STR_LIT>' ) . value , context = self . context ) <EOL> self . refresh ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def on_create_task ( self ) : <EOL> cls = self . find ( '<STR_LIT>' ) . value <EOL> td = TaskDefinition ( task_class = cls ) <EOL> td . name = td . get_class ( ) . name <EOL> self . manager . task_definitions . append ( td ) <EOL> self . refresh ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def on_save ( self ) : <EOL> self . binder . update ( ) <EOL> self . manager . save ( ) <EOL> self . refresh ( ) </s>
