Skip to content

Commit

Permalink
git subrepo pull uno
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "uno"
  merged:   "ac728d9"
upstream:
  origin:   "https://github.com/prrvchr/uno.git"
  branch:   "main"
  commit:   "ac728d9"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
  • Loading branch information
prrvchr committed Jan 16, 2024
1 parent a7f845b commit 1467609
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 140 deletions.
4 changes: 2 additions & 2 deletions uno/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/prrvchr/uno.git
branch = main
commit = 0008ec522c4e2e949fa1a33f336a78955fedc2d8
parent = 35f1485e5dc0168c146bb854368cb3faac66781c
commit = ac728d9b5dd94b185f508d021b400263aaf83173
parent = a7f845bd8f4f208f5945aa57e58e0e20eb54dce5
method = merge
cmdver = 0.4.3
1 change: 1 addition & 0 deletions uno/lib/uno/ucb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def insertIdentifier(self, iterator, userid):
if count > 0:
call.executeBatch()
call.close()
return count

# Pull procedure
def pullItems(self, iterator, userid, timestamp, mode=1):
Expand Down
96 changes: 44 additions & 52 deletions uno/lib/uno/ucb/replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def __init__(self, ctx, url, provider, users, sync, lock):
sync.clear()
self.start()
except Exception as e:
self._logger.logprb(INFO, 'Replicator', '__init__()', 102, e, traceback.format_exc())
self._logger.logprb(INFO, g_basename, '__init__()', 102, e, traceback.format_exc())
else:
self._logger.logprb(INFO, 'Replicator', '__init__()', 101)
self._logger.logprb(INFO, g_basename, '__init__()', 101)

def fullPull(self):
return self._fullPull
Expand All @@ -98,23 +98,23 @@ def cancel(self):

def run(self):
try:
self._logger.logprb(INFO, 'Replicator', 'run()', 111, self._provider.Scheme)
self._logger.logprb(INFO, g_basename, 'run()', 111, self._provider.Scheme)
while not self._canceled:
timeout = self._getReplicateTimeout()
self._logger.logprb(INFO, 'Replicator', 'run()', 112, round(timeout /60))
self._logger.logprb(INFO, g_basename, 'run()', 112, timeout // 60)
self._sync.wait(timeout)
self._synchronize()
self._sync.clear()
except Exception as e:
self._logger.logprb(SEVERE, 'Replicator', 'run()', 113, e, traceback.format_exc())
self._logger.logprb(SEVERE, g_basename, 'run()', 113, e, traceback.format_exc())

def _synchronize(self):
policy = self._getPolicy()
if policy == self._getSynchronizePolicy('NONE_IS_MASTER'):
return
self._logger.logprb(INFO, 'Replicator', '_synchronize()', 121)
self._logger.logprb(INFO, g_basename, '_synchronize()', 121)
if self._provider.isOffLine():
self._logger.logprb(INFO, 'Replicator', '_synchronize()', 122)
self._logger.logprb(INFO, g_basename, '_synchronize()', 122)
elif policy == self._getSynchronizePolicy('SERVER_IS_MASTER'):
if not self._canceled:
self._pullUsers()
Expand All @@ -125,44 +125,59 @@ def _synchronize(self):
self._pushUsers()
if not self._canceled:
self._pullUsers()
self._logger.logprb(INFO, 'Replicator', '_synchronize()', 123)
self._logger.logprb(INFO, g_basename, '_synchronize()', 123)

def _pullUsers(self):
try:
for user in self._users.values():
if self._canceled:
break
self._logger.logprb(INFO, 'Replicator', '_pullUsers()', 131, user.Name)
self._logger.logprb(INFO, g_basename, '_pullUsers()', 201, user.Name)
# In order to make the creation of files or directories possible quickly,
# it is necessary to run the verification of the identifiers first.
self._checkNewIdentifier(user)
#if not user.Token:
if self._isNewUser(user):
self._initUser(user)
else:
self._pullUser(user)
self._logger.logprb(INFO, 'Replicator', '_pullUsers()', 132, user.Name)
self._logger.logprb(INFO, g_basename, '_pullUsers()', 202, user.Name)
except Exception as e:
self._logger.logprb(SEVERE, 'Replicator', '_pullUsers()', 133, e, traceback.format_exc())
self._logger.logprb(SEVERE, g_basename, '_pullUsers()', 203, e, traceback.format_exc())

def _checkNewIdentifier(self, user):
if not self._provider.GenerateIds:
user.CanAddChild = True
return
if self._provider.isOffLine():
user.CanAddChild = self.DataBase.countIdentifier(user.Id) > 0
return
count = self.DataBase.countIdentifier(user.Id)
if count < min(self._provider.IdentifierRange):
total, msg = self._provider.pullNewIdentifiers(user)
if total:
self._logger.logprb(INFO, g_basename, '_checkNewIdentifier()', 211, user.Name, count, total)
else:
self._logger.logprb(INFO, g_basename, '_checkNewIdentifier()', 212, user.Name, msg)
# Need to postpone the creation authorization after this verification...
user.CanAddChild = True

def _initUser(self, user):
# This procedure is launched only once for each new user
# This procedure corresponds to the initial pull for a new User (ie: without Token)
self._logger.logprb(INFO, 'Replicator', '_initUser()', 141, user.Name)
self._logger.logprb(INFO, g_basename, '_initUser()', 221, user.Name)
pages, count, token = self._provider.firstPull(user)
self._provider.initUser(self.DataBase, user, token)
user.SyncMode = 1
self._fullPull = True
self._logger.logprb(INFO, 'Replicator', '_initUser()', 142, user.Name)
self._logger.logprb(INFO, g_basename, '_initUser()', 222, user.Name)

def _pullUser(self, user):
# This procedure is launched each time the synchronization is started
# This procedure corresponds to the pull for a User (ie: a Token is required)
print("Replicator._pullUser() 1")
pages, count, token = self._provider.pullUser(user)
if token:
user.setToken(token)
print("Replicator._pullUser() 2 Items count: %s - Pages count: %s - Token: %s" % (count, pages, token))
self._logger.logprb(INFO, g_basename, '_pullUser()', 231, user.Name, count, pages, token)

def _pushUsers(self):
# This procedure is launched each time the synchronization is started
Expand All @@ -171,7 +186,7 @@ def _pushUsers(self):
try:
end = currentDateTimeInTZ()
for user in self._users.values():
self._logger.logprb(INFO, 'Replicator', '_pushUsers()', 151, user.Name)
self._logger.logprb(INFO, g_basename, '_pushUsers()', 301, user.Name)
if self._isNewUser(user):
self._initUser(user)
items = []
Expand All @@ -183,25 +198,13 @@ def _pushUsers(self):
items.append(newid)
else:
modified = getDateTimeToString(metadata.get('DateModified'))
self._logger.logprb(SEVERE, 'Replicator', '_pushUsers()', 152, metadata.get('Title'), modified, metadata.get('Id'))
self._logger.logprb(SEVERE, g_basename, '_pushUsers()', 302, metadata.get('Title'), modified, metadata.get('Id'))
break
if items:
self.DataBase.updatePushItems(user, items)
self._logger.logprb(INFO, 'Replicator', '_pushUsers()', 153, user.Name)
self._logger.logprb(INFO, g_basename, '_pushUsers()', 303, user.Name)
except Exception as e:
self._logger.logprb(SEVERE, 'Replicator', '_pushUsers()', 154, e, traceback.format_exc())

def _checkNewIdentifier(self, user):
if not self._provider.GenerateIds:
user.CanAddChild = True
return
if self._provider.isOffLine():
user.CanAddChild = self.DataBase.countIdentifier(user.Id) > 0
return
if self.DataBase.countIdentifier(user.Id) < min(self._provider.IdentifierRange):
self._provider.pullNewIdentifiers(user)
# Need to postpone the creation authorization after this verification...
user.CanAddChild = True
self._logger.logprb(SEVERE, g_basename, '_pushUsers()', 304, e, traceback.format_exc())


def _filterParents(self, call, provider, items, childs, roots, start):
Expand All @@ -226,28 +229,20 @@ def _pushItem(self, user, item, metadata, start, end):
timestamp = item.get('TimeStamp')
action = item.get('ChangeAction')
chunk, retry, delay = self._getUploadSetting()
print("Replicator._pushItem() 3 Insert/Update Title: %s Id: %s - Action: %s" % (metadata.get('Title'),
itemid,
action))
# If the synchronization of an INSERT or an UPDATE fails
# then the user's TimeStamp will not be updated
# INSERT procedures, new files and folders are synced here.
if action & INSERT:
print("Replicator._pushItem() INSERT 1")
mediatype = metadata.get('MediaType')
print("Replicator._pushItem() INSERT 2")
created = getDateTimeToString(metadata.get('DateCreated'))
if self._provider.isFolder(mediatype):
print("Replicator._pushItem() INSERT 3")
newid = self._provider.createFolder(user, itemid, metadata)
print("Replicator._pushItem() INSERT 4")
self._logger.logprb(INFO, 'Replicator', '_pushItem()', 161, metadata.get('Title'), created)
print("Replicator._pushItem() INSERT 5")
self._logger.logprb(INFO, g_basename, '_pushItem()', 311, metadata.get('Title'), created)
elif self._provider.isLink(mediatype):
pass
elif self._provider.isDocument(mediatype):
newid, args = self._provider.uploadFile(165, user, itemid, metadata, created, chunk, retry, delay, True)
self._logger.logprb(INFO, 'Replicator', '_pushItem()', *args)
newid, args = self._provider.uploadFile(314, user, itemid, menewidtadata, created, chunk, retry, delay, True)
self._logger.logprb(INFO, g_basename, '_pushItem()', *args)
# UPDATE procedures, only a few properties are synchronized: Title and content(ie: Size or DateModified)
elif action & UPDATE:
for property in self.DataBase.getPushProperties(user.Id, itemid, start, end):
Expand All @@ -256,26 +251,23 @@ def _pushItem(self, user, item, metadata, start, end):
modified = getDateTimeToString(metadata.get('DateModified'))
if properties & TITLE:
newid = self._provider.updateTitle(user.Request, itemid, metadata)
self._logger.logprb(INFO, 'Replicator', '_pushItem()', 170, metadata.get('Title'), modified)
self._logger.logprb(INFO, g_basename, '_pushItem()', 312, metadata.get('Title'), modified)
elif properties & CONTENT:
newid, args = self._provider.uploadFile(175, user, itemid, metadata, modified, chunk, retry, delay, False)
self._logger.logprb(INFO, 'Replicator', '_pushItem()', *args)
newid, args = self._provider.uploadFile(314, user, itemid, metadata, modified, chunk, retry, delay, False)
self._logger.logprb(INFO, g_basename, '_pushItem()', *args)
elif properties & TRASHED:
newid = self._provider.updateTrashed(user.Request, itemid, metadata)
self._logger.logprb(INFO, 'Replicator', '_pushItem()', 172, metadata.get('Title'), modified)
self._logger.logprb(INFO, g_basename, '_pushItem()', 313, metadata.get('Title'), modified)
# MOVE procedures to follow parent changes of a resource
elif action & MOVE:
print("Replicator._pushItem() MOVE")
self.DataBase.getItemParentIds(itemid, metadata, start, end)
newid = self._provider.updateParents(user.Request, itemid, metadata)
print("Replicator.._pushItem() MOVE ToAdd: %s - ToRemove: %s" % (toadd, toremove))
elif action & DELETE:
print("Replicator._pushItem() DELETE")
newid = self._provider.updateTrashed(user.Request, itemid, metadata)
self._logger.logprb(INFO, 'Replicator', '_pushItem()', 172, metadata.get('Title'), timestamp)
self._logger.logprb(INFO, g_basename, '_pushItem()', 313, metadata.get('Title'), timestamp)
return newid
except Exception as e:
self._logger.logprb(SEVERE, 'Replicator', '_pushItem()', 179, e, traceback.format_exc())
self._logger.logprb(SEVERE, g_basename, '_pushItem()', 319, e, traceback.format_exc())

def _isNewUser(self, user):
return user.SyncMode == 0
Expand Down
47 changes: 27 additions & 20 deletions uno/lib/uno/ucb/ucp/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ def getDocumentContent(self, content, url):

# Method called by Replicator
def pullNewIdentifiers(self, user):
count, msg = 0, ''
parameter = self.getRequestParameter(user.Request, 'getNewIdentifier', user)
response = user.Request.execute(parameter)
if response.Ok:
iterator = self.parseNewIdentifiers(response)
if not response.Ok:
msg = response.Text
else:
# TODO: raise exception with the right message...
self._logger.logprb(SEVERE, 'Replicator', '_checkNewIdentifier', 403, user.Name)
user.DataBase.insertIdentifier(iterator, user.Id)
iterator = self.parseNewIdentifiers(response)
count = user.DataBase.insertIdentifier(iterator, user.Id)
response.close()
return count, msg

def firstPull(self, user):
datetime = currentDateTimeInTZ()
Expand Down Expand Up @@ -306,26 +307,32 @@ def createFolder(self, user, itemid, item):
return self.mergeNewFolder(user, itemid, response)

def uploadFile(self, code, user, item, data, created, chunk, retry, delay, new=False):
newid = None
method = 'getNewUploadLocation' if new else 'getUploadLocation'
parameter = self.getRequestParameter(user.Request, method, data)
response = user.Request.execute(parameter)
if not response.Ok:
msg = response.Text
response.close()
return None, (code +1, data.get('Title'), msg)
location = self.parseUploadLocation(response)
if location is None:
return None, (code +2, data.get('Title'))
parameter = self.getRequestParameter(user.Request, 'getUploadStream', location)
url = self.SourceURL + g_separator + item
response = user.Request.upload(parameter, url, chunk, retry, delay)
if not response.Ok:
msg = response.Text
args = code, data.get('Title'), response.Text
response.close()
return None, (code +3, data.get('Title'), msg)
newid = self.updateItemId(user.DataBase, item, response)
return newid, (code, data.get('Title'), created, data.get('Size'))

else:
location = self.parseUploadLocation(response)
if location is None:
args = code + 1, data.get('Title')
else:
parameter = self.getRequestParameter(user.Request, 'getUploadStream', location)
url = self.SourceURL + g_separator + item
response = user.Request.upload(parameter, url, chunk, retry, delay)
if not response.Ok:
args = code + 2, data.get('Title'), response.Text
response.close()
elif new:
newid = self.updateItemId(user.DataBase, item, response)
args = code + 3, data.get('Title'), created, data.get('Size')
else:
response.close()
newid = item
args = code + 4, data.get('Title'), created, data.get('Size')
return newid, args

def updateTitle(self, request, itemid, item):
parameter = self.getRequestParameter(request, 'updateTitle', item)
Expand Down
65 changes: 32 additions & 33 deletions uno/resource/ucb/Replicator_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,38 @@
122=Synchronization is not possible network is offline!!!
123=End of data synchronization.

130=Replicator._pullUsers()
131=Starting data download for user: {}.
132=End of download for user: {}.
133=Replicator thread throw error: {}\n{}

140=Replicator._initUser()
141=Initialize user name: {}.
142=First data pull for user name {}, done...

150=Replicator._pushUsers()
151=Starting data replication for user: {}.
152=Has encountered an error while replicating the file/folder: {} of {} with Id: {}
153=End of replicating data for user: {}.
154=Replicator thread throw error: {}\n{}

160=Replicator._pushItem
161=Has replicated the creation of a folder: {} of {}

165=Has replicated the creation of a file: {} of {} size: {}
166=Can't retrieve upload location for file: {} HTTP response: {}
167=Can't retrieve upload location for file: {}
168=Can't upload file: {} HTTP response: {}
170=Has replicated the file/folder's title: {} update of {}
172=Has replicated the file/folder's trashed: {} of {}
175=Has replicated the update of file: {} of {} size: {}
176=Can't retrieve upload location for file: {} HTTP response: {}
177=Can't retrieve upload location for file: {}
178=Can't upload file: {} HTTP response: {}

179=Replicator thread throw error: {}\n{}

200=Replicator._pullUsers()
201=Starting data download for user: {}.
202=End of download for user: {}.
203=Replicator thread throw error: {}\n{}

210=Replicator._checkNewIdentifier()
211=User {} only has {} identifiers left, {} identifiers have just been downloaded.
212=Has throw an error when requesting identifiers for user {} with the message: {}

220=Replicator._initUser()
221=Initialize user name: {}.
222=First data pull for user name {}, done...

230=Replicator._pullUser()
231=User {} pull #{} changes on #{} pages with token {}

300=Replicator._pushUsers()
301=Starting data replication for user: {}.
302=Has encountered an error while replicating the file/folder: {} of {} with Id: {}
303=End of replicating data for user: {}.
304=Replicator thread throw error: {}\n{}

310=Replicator._pushItem
311=Has replicated the creation of a folder: {} of {}
312=Has replicated the file/folder's title: {} update of {}
313=Has replicated the file/folder's trashed: {} of {}
314=Can't retrieve upload location for file: {} HTTP response: {}
315=Can't retrieve upload location for file: {}
316=Can't upload file: {} HTTP response: {}
317=Has replicated the creation of file: {} of {} size: {}
318=Has replicated the update of file: {} of {} size: {}
319=Replicator thread throw error: {}\n{}
400=DataBase.__init__()
401=DataBase: Loading completed
Expand Down
Loading

0 comments on commit 1467609

Please sign in to comment.