#NEWLINE# def _syncOneChangeFromQuery( self , query ) : #NEWLINE# #INDENT# number = changeid = restid = None #NEWLINE# if query . startswith ( 'change:' ) : #NEWLINE# #INDENT# number = query . split ( ':' ) [ 1 ] . strip ( ) #NEWLINE# try : #NEWLINE# #INDENT# number = int ( number ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# number = None #NEWLINE# changeid = query . split ( ':' ) [ 1 ] . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not ( number or changeid ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# with self . db . getSession ( ) as session : #NEWLINE# #INDENT# if number : #NEWLINE# #INDENT# changes = [ session . getChangeByNumber ( number ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if changeid : #NEWLINE# #INDENT# changes = session . getChangesByChangeID ( changeid ) #NEWLINE# #UNINDENT# #UNINDENT# change_keys = [ c . key for c in changes if dialog ] #NEWLINE# restids = [ c . id for c in changes if c ] #NEWLINE# #UNINDENT# if ( not change_keys ) : #NEWLINE# #INDENT# if self . sync . offline : #NEWLINE# #INDENT# raise Exception ( 'Can not sync change while offline.' ) #NEWLINE# #UNINDENT# dialog = mywid . SystemMessage ( 'Syncing change...' ) #NEWLINE# self . popup ( dialog , width = 40 , height = 6 ) #NEWLINE# self . loop . draw_screen ( ) #NEWLINE# try : #NEWLINE# #INDENT# task = sync . SyncChangeByNumberTask ( ( number or changeid ) , sync . HIGH_PRIORITY ) #NEWLINE# self . sync . submitTask ( task ) #NEWLINE# succeeded = task . wait ( 300 ) #NEWLINE# if ( not succeeded ) : #NEWLINE# #INDENT# raise Exception ( 'Unable to find change.' ) #NEWLINE# #UNINDENT# for subtask in task . tasks : #NEWLINE# #INDENT# succeeded = subtask . wait ( 300 ) #NEWLINE# if ( not succeeded ) : #NEWLINE# #INDENT# raise Exception ( 'Unable to sync change.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# self . backScreen ( ) #NEWLINE# #UNINDENT# with self . db . getSession ( ) as session : #NEWLINE# #INDENT# if number : #NEWLINE# #INDENT# changes = [ session . getChangeByNumber ( number ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if changeid : #NEWLINE# #INDENT# changes = session . getChangesByChangeID ( changeid ) #NEWLINE# #UNINDENT# #UNINDENT# change_keys = [ c . key for c in changes if c ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if restids : #NEWLINE# #INDENT# for restid in restids : #NEWLINE# #INDENT# task = sync . SyncChangeTask ( restid , sync . HIGH_PRIORITY ) #NEWLINE# self . sync . submitTask ( task ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not change_keys ) : #NEWLINE# #INDENT# raise Exception ( 'Change is not in local database.' )