Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoryvp committed Jan 7, 2013
1 parent 81cf23c commit 8ddad70
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 152 deletions.
7 changes: 0 additions & 7 deletions parabridge.py

This file was deleted.

48 changes: 25 additions & 23 deletions parabridge_core/__init__.py → parabridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# coding:utf-8 vi:et:ts=2

import os
import sys
import argparse
import subprocess
import xmlrpclib
import json
import socket
import logging
from settings import Settings
from common import *

import settings
import info

HELP_APP = """Paradox to SQLite bridge. This tool monitors specified
Paradox database and reflects all changes to specified SQLite database
Expand All @@ -27,37 +26,40 @@
HELP_TASK_DEL = """Deletes task with specified name."""
HELP_TASK_LIST = """Displays list of added tasks."""

def start( i_oArgs ) :

def start( _ ) :
sFile = os.path.join( os.path.dirname( __file__ ), "parabridge_daemon.py" )
subprocess.Popen( [ 'python', sFile, str( COMM_PORT ) ] )
subprocess.Popen( [ 'python', sFile, str( info.COMM_PORT ) ] )

def stop( i_oArgs ) :

def stop( _ ) :
try :
oSrv = xmlrpclib.ServerProxy( COMM_ADDR )
oSrv = xmlrpclib.ServerProxy( info.COMM_ADDR )
oSrv.stop()
except socket.error :
pass

def status( i_oArgs ) :

def status( _ ) :
try :
oSrv = xmlrpclib.ServerProxy( COMM_ADDR )
oSrv = xmlrpclib.ServerProxy( info.COMM_ADDR )
print( oSrv.status() )
except socket.error :
print( "Daemon is not running." )

def task_add( i_oArgs ) :
sName = i_oArgs.task_name
sSrc = i_oArgs.task_src
sDst = i_oArgs.task_dst
if not Settings.taskAdd( sName, sSrc, sDst ) :
def task_add( m_args ) :
sName = m_args[ 'task_name' ]
sSrc = m_args[ 'task_src' ]
sDst = m_args[ 'task_dst' ]
if not settings.instance.taskAdd( sName, sSrc, sDst ) :
logging.warning( "Already has '{0}' task".format( sName ) )

def task_del( i_oArgs ) :
if not Settings.taskDelByName( i_oArgs.task_name ) :
logging.warning( "No task named '{0}'".format( i_oArgs.task_name ) )
def task_del( m_args ) :
if not settings.instance.taskDelByName( m_args[ 'task_name' ] ) :
logging.warning( "No task named '{0}'".format( m_args[ 'task_name' ] ) )

def task_list( i_oArgs ) :
lTasks = Settings.taskList()
def task_list( _ ) :
lTasks = settings.instance.taskList()
if 0 == len( lTasks ) :
print( "Tasks list is empty." )
return
Expand All @@ -67,8 +69,8 @@ def task_list( i_oArgs ) :
mTask[ 'src' ],
mTask[ 'dst' ] ) )

def app() :
Settings.init( notify = True )
def main() :
settings.instance.init( f_notify = True )
oParser = argparse.ArgumentParser( description = HELP_APP )
oSubparsers = oParser.add_subparsers()
oSubparser = oSubparsers.add_parser( 'start', help = HELP_START )
Expand All @@ -88,5 +90,5 @@ def app() :
oSubparser = oSubparsers.add_parser( 'task_list', help = HELP_TASK_LIST )
oSubparser.set_defaults( handler = task_list )
oArgs = oParser.parse_args()
oArgs.handler( oArgs )
oArgs.handler( vars( oArgs ) )

34 changes: 34 additions & 0 deletions parabridge/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# coding:utf-8 vi:et:ts=2

# parabridge information
# Copyright 2013 Grigory Petrov
# See LICENSE for details.

import os
import pkg_resources

NAME_SHORT = "parabridge"
VER_MAJOR = 0
VER_MINOR = 1
try :
VER_TXT = pkg_resources.require( NAME_SHORT )[ 0 ].version
## Installing via 'setup.py develop'?
except pkg_resources.DistributionNotFound :
VER_BUILD = 0
VER_TXT = ".".join( map( str, [ VER_MAJOR, VER_MINOR, VER_BUILD ] ) )
DIR_THIS = os.path.dirname( os.path.abspath( __file__ ) )
DIR_HOME = os.path.expanduser( '~' )
NAME_FULL = "Paradox to SQLite bridge."
DESCR = """
{s_name_short} v. {s_ver_txt}\\n\\n
A simple python daemon that can dynamically sync paradox database with
SQLite database.
""".replace( '\n', '' ).replace( '\\n', '\n' ).strip().format(
s_name_short = NAME_SHORT,
s_ver_txt = VER_TXT )

COMM_PORT = 17963
COMM_ADDR = 'http://localhost:{0}/'.format( COMM_PORT )
FILE_CFG = os.path.join( DIR_HOME, '.{0}'.format( NAME_SHORT ) )

Loading

0 comments on commit 8ddad70

Please sign in to comment.