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