コード例 #1
0
ファイル: model.py プロジェクト: InQuant/TracWikiSync
 def synchronized(self):
     """Returns an instance marked as status='synced'"""
     assert safe_int(self.remote_version), \
         "Invalid remote_version '%s'" % self.remote_version
     assert safe_int(self.local_version), \
         "Invalid local_version '%s'" % self.local_version
     return self.replace(
         sync_remote_version=self.remote_version,
         sync_local_version=self.local_version,
         sync_time = time.time(),
     )
コード例 #2
0
ファイル: model.py プロジェクト: InQuant/TracWikiSync
 def replace(self, *args, **kwargs):
     """Returns a new instance with the updated properties.
     
     The 'status' property is calculated dynamically, setting this
     property will have no effect in the output.
     
     @param *args: non-keyworded arguments must be in the same order
         as the WikiSync._fields.
     @param **kwargs: An exception will be thrown on non-existent keywords.
     """
     if len(args):
         kwargs = dict(zip(WikiSync._fields, args))
     o = self._replace(**kwargs)
     status = "unknown"
     if o.ignore:
         status = "ignored"
     elif o.sync_time:
         rv = safe_int(o.remote_version)
         lv = safe_int(o.local_version)
         srv = safe_int(o.sync_remote_version)
         slv = safe_int(o.sync_local_version)
         if rv and not lv:
             # can"t find local copy
             status = "missing"
         elif lv and not rv:
             # can"t find remote copy
             status = "new"
         elif rv > srv and lv > slv:
             # both remote and local are out of sync
             status = "conflict"
         elif rv > srv:
             # local in-sync, but remote out of sync
             status = "outdated"
         elif lv > slv:
             # local out of sync, but remote in sync
             status = "modified"
         elif rv == srv and lv == slv:
             status = "synced"
         elif rv < srv or lv < slv:
             # edge case, local wiki or remote wiki was deleted
             # and re-added, causing the synced version to be higher
             # we mark the status as conflict and prompt user to resolve it
             status = "conflict"
     return o.status == status and o or o._replace(status=status)