<s> import os <EOL> from ajenti . api import * <EOL> from ajenti . plugins . main . api import SectionPlugin <EOL> from ajenti . ui import on <EOL> from ajenti . ui . binder import Binder <EOL> from ajenti . util import platform_select <EOL> from reconfigure . configs import NSDConfig <EOL> from reconfigure . items . nsd import ZoneData <EOL> @ plugin <EOL> class NSDPlugin ( 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 . config = NSDConfig ( path = platform_select ( <EOL> default = '<STR_LIT>' , <EOL> arch = '<STR_LIT>' , <EOL> ) ) <EOL> self . binder = Binder ( None , self ) <EOL> self . find ( '<STR_LIT>' ) . new_item = lambda c : ZoneData ( ) <EOL> def post_zone_bind ( o , c , i , u ) : <EOL> path = i . file <EOL> if not path . startswith ( '<STR_LIT:/>' ) : <EOL> path = '<STR_LIT>' + path <EOL> exists = os . path . exists ( path ) <EOL> u . find ( '<STR_LIT>' ) . visible = not exists <EOL> u . find ( '<STR_LIT:file>' ) . visible = exists <EOL> if exists : <EOL> u . find ( '<STR_LIT>' ) . value = open ( path ) . read ( ) <EOL> def on_save_zone ( ) : <EOL> open ( path , '<STR_LIT:w>' ) . write ( u . find ( '<STR_LIT>' ) . value ) <EOL> self . context . notify ( '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) <EOL> def on_create_zone ( ) : <EOL> open ( path , '<STR_LIT:w>' ) . write ( """<STR_LIT>""" ) <EOL> post_zone_bind ( o , c , i , u ) <EOL> u . find ( '<STR_LIT>' ) . on ( '<STR_LIT>' , on_save_zone ) <EOL> u . find ( '<STR_LIT>' ) . on ( '<STR_LIT>' , on_create_zone ) <EOL> self . find ( '<STR_LIT>' ) . post_item_bind = post_zone_bind <EOL> def on_page_load ( self ) : <EOL> self . refresh ( ) <EOL> def refresh ( self ) : <EOL> if not os . path . exists ( self . config . origin ) : <EOL> self . context . notify ( <EOL> '<STR_LIT:error>' , <EOL> _ ( '<STR_LIT>' ) % self . config . origin <EOL> ) <EOL> return <EOL> self . config . load ( ) <EOL> self . binder . setup ( self . config . tree ) . populate ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def save ( self ) : <EOL> self . binder . update ( ) <EOL> self . config . save ( ) <EOL> self . refresh ( ) <EOL> self . context . notify ( '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) </s>
