Skip to content

Commit

Permalink
Settings singleton is now initialized before usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoryvp committed Feb 29, 2012
1 parent b8c41a7 commit 1c9ec93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions parabridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def task_add( i_oArgs ) :
'src' : i_oArgs.task_src,
'dst' : i_oArgs.task_dst
}
Settings.set( 'tasks', Settings.get( 'tasks' ) + [ mTask ], notify = True )
Settings.set( 'tasks', Settings.get( 'tasks' ) + [ mTask ] )

def task_del( i_oArgs ) :
lTasks = Settings.get( 'tasks' )
for mTask in lTasks :
if i_oArgs.task_name == mTask[ 'name' ] :
lTasks.remove( mTask )
Settings.set( 'tasks', lTasks, notify = True )
Settings.set( 'tasks', lTasks )
return
logging.warning( "No task named '{0}'".format( i_oArgs.task_name ) )

Expand All @@ -77,6 +77,7 @@ def task_list( i_oArgs ) :
mTask[ 'src' ],
mTask[ 'dst' ] ) )

Settings.init( notify = True )
oParser = argparse.ArgumentParser( description = HELP_APP )
oSubparsers = oParser.add_subparsers()
oSubparser = oSubparsers.add_parser( 'start', help = HELP_START )
Expand Down
2 changes: 2 additions & 0 deletions parabridge_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import re
from SimpleXMLRPCServer import SimpleXMLRPCServer
from settings import Settings

# Allow to import packages from 'vendor' subfolder.
sys.path.append( '{0}/vendor'.format( sys.path[ 0 ] ) )
Expand Down Expand Up @@ -134,6 +135,7 @@ def cfg_changed( self ) :
Config().reload()
return True

Settings.init()
oParser = argparse.ArgumentParser( description = "Parabridge daemon" )
oParser.add_argument( 'port', type = int, help = "Port to listen on" )
oArgs = oParser.parse_args()
Expand Down
13 changes: 11 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ class Settings( object ) :
sPath = os.path.expanduser( "~/.parabridge" )
if os.path.exists( sPath ) :
m_mItems.update( json.load( open( sPath ) ) )
m_fInit = False
m_fNotify = False

@classmethod
def set( self, i_sName, i_uVal, notify = False ) :
def init( self, notify = False ) :
self.m_fNotify = notify
self.m_fInit = True

@classmethod
def set( self, i_sName, i_uVal ) :
if not m_fInit : raise Exception( "Init not called." )
self.m_mItems[ i_sName ] = i_uVal
sPath = os.path.expanduser( "~/.parabridge" )
json.dump( self.m_mItems, open( sPath, 'w' ) )
if notify :
if m_fNotify :
try :
oSrv = xmlrpclib.ServerProxy( COMM_ADDR )
oSrv.cfg_changed()
Expand All @@ -28,5 +36,6 @@ def set( self, i_sName, i_uVal, notify = False ) :

@classmethod
def get( self, i_sName ) :
if not m_fInit : raise Exception( "Init not called." )
return self.m_mItems[ i_sName ]

0 comments on commit 1c9ec93

Please sign in to comment.