Skip to content

Commit

Permalink
Added skeleton code to write data from loaded Paradox database into S…
Browse files Browse the repository at this point in the history
…QLite database.
  • Loading branch information
grigoryvp committed Mar 2, 2012
1 parent 9c5aa03 commit 558bd45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Binary file removed a.sqlite
Binary file not shown.
22 changes: 14 additions & 8 deletions parabridge_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import json
import re
import sqlite3
from SimpleXMLRPCServer import SimpleXMLRPCServer
from settings import Settings

Expand Down Expand Up @@ -61,19 +62,20 @@ def setRes( i_sTxt ) :
return setRes( "No .db files in \"{0}\".".format( i_sSrc ) )
lProcessed = []
nTotal = len( lSrcFiles )
for i, sSrcFile in enumerate( lSrcFiles ) :
setRes( "Processing {0}/{1}".format( i + 1, nTotal ) )
if self.processParadoxFile( i_sGuid, sSrcFile, i_sDst ) :
if self.m_fShutdown :
return
lProcessed.append( True )
with sqlite3.connect( i_sDst ) as oConn :
for i, sSrcFile in enumerate( lSrcFiles ) :
setRes( "Processing {0}/{1}".format( i + 1, nTotal ) )
if self.processParadoxFile( i_sGuid, sSrcFile, oConn ) :
if self.m_fShutdown :
return
lProcessed.append( True )
sTime = time.strftime( '%Y.%m.%d %H:%M:%S' )
nProcessed = len( lProcessed )
setRes( "Processed {0}/{1} at {2}.".format( nProcessed, nTotal, sTime ) )

##x Process individual Paradox |.db| file and synchronize specified
## SQLite database file with it.
def processParadoxFile( self, i_sGuid, i_sSrc, i_sDst ) :
def processParadoxFile( self, i_sGuid, i_sSrc, i_oConn ) :
try :
sFile = os.path.basename( i_sSrc )
nIndexLast = Settings.indexLastGet( i_sGuid, sFile )
Expand All @@ -97,11 +99,15 @@ def processParadoxFile( self, i_sGuid, i_sSrc, i_sDst ) :
if nIndexLast is not None and nIndexLast >= nIndex :
raise Exception( "Consistency error." )
nIndexLast = nIndex
print( "{0}: {1}".format( sFile, nIndexLast ) )
self.processParadoxRecord( oRecord, i_oConn )
Settings.indexLastSet( i_sGuid, sFile, nIndexLast )
except pyparadox.Shutdown :
return False
return True

def processParadoxRecord( self, i_oRecord, i_oConn ) :
pass

def shutdown( self ) :
self.m_fShutdown = True
##! After |m_fShutdown| is set to prevent races.
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def taskAdd( self, i_sName, i_sSrc, i_sDst ) :
self.notifyIfNeeded()

@classmethod
def indexLastSet( i_sGuid, i_sFile, i_nIndex ) :
def indexLastSet( self, i_sGuid, i_sFile, i_nIndex ) :
with sqlite3.connect( FILE_CFG ) as oConn :
mArgs = {
'guid' : i_sGuid,
Expand All @@ -100,6 +100,7 @@ def indexLastGet( self, i_sGuid, i_sFile ) :
@classmethod
def taskDelByName( self, i_sName ) :
with sqlite3.connect( FILE_CFG ) as oConn :
oConn.row_factory = sqlite3.Row
try :
mArgs = { 'name' : i_sName }
oRow = oConn.execute( SQL_TASK_GUID_BY_NAME, mArgs ).fetchone()
Expand Down

0 comments on commit 558bd45

Please sign in to comment.