Skip to content

Commit 0147356

Browse files
committed
git subrepo pull uno
subrepo: subdir: "uno" merged: "448f55e2" upstream: origin: "https://github.com/prrvchr/uno.git" branch: "main" commit: "448f55e2" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596"
1 parent c8dc347 commit 0147356

File tree

13 files changed

+286
-166
lines changed

13 files changed

+286
-166
lines changed

uno/.gitrepo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[subrepo]
77
remote = https://github.com/prrvchr/uno.git
88
branch = main
9-
commit = bdc86da71c2050339b611e294cdc250c5d054042
10-
parent = d8c0c059851abc0a600bc5467b65aa000cbe11f2
9+
commit = 448f55e200c506f0edadcf062dd6160ff05c033a
10+
parent = c8dc3475778cb2d4fab1a9c93679a530a6fd0bc3
1111
method = merge
1212
cmdver = 0.4.3

uno/lib/uno/card/card/book.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@
2727
╚════════════════════════════════════════════════════════════════════════════════════╝
2828
"""
2929

30+
from .group import Group
3031

31-
class Book(object):
32+
import json
33+
34+
35+
class Book():
3236
def __init__(self, new, **kwargs):
3337
self._new = new
3438
self._id = kwargs.get('Book')
3539
self._uri = kwargs.get('Uri')
3640
self._name = kwargs.get('Name')
3741
self._tag = kwargs.get('Tag')
3842
self._token = kwargs.get('Token')
43+
groups = (Group(new, *group) for group in json.loads(kwargs.get('Groups', '[]')))
44+
self._groups = {group.Uri: group for group in groups}
3945

4046
@property
4147
def Id(self):
@@ -59,7 +65,21 @@ def isNew(self):
5965
def resetNew(self):
6066
self._new = False
6167

62-
def hasNameChanged(self, name):
68+
def hasGroup(self, uri):
69+
return uri in self._groups
70+
71+
def getGroups(self):
72+
return self._groups.values()
73+
74+
def getGroup(self, uri):
75+
return self._groups[uri]
76+
77+
def setNewGroup(self, uri, *args):
78+
group = Group(True, *args)
79+
self._groups[uri] = group
80+
return group
81+
82+
def isRenamed(self, name):
6383
return self._name != name
6484

6585
def setName(self, name):

uno/lib/uno/card/card/group.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
╔════════════════════════════════════════════════════════════════════════════════════╗
6+
║ ║
7+
║ Copyright (c) 2020 https://prrvchr.github.io ║
8+
║ ║
9+
║ Permission is hereby granted, free of charge, to any person obtaining ║
10+
║ a copy of this software and associated documentation files (the "Software"), ║
11+
║ to deal in the Software without restriction, including without limitation ║
12+
║ the rights to use, copy, modify, merge, publish, distribute, sublicense, ║
13+
║ and/or sell copies of the Software, and to permit persons to whom the Software ║
14+
║ is furnished to do so, subject to the following conditions: ║
15+
║ ║
16+
║ The above copyright notice and this permission notice shall be included in ║
17+
║ all copies or substantial portions of the Software. ║
18+
║ ║
19+
║ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ║
20+
║ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ║
21+
║ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ║
22+
║ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ║
23+
║ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ║
24+
║ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE ║
25+
║ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ║
26+
║ ║
27+
╚════════════════════════════════════════════════════════════════════════════════════╝
28+
"""
29+
30+
31+
class Group():
32+
def __init__(self, new, group, uri, name, token=''):
33+
self._new = new
34+
self._id = group
35+
self._uri = uri
36+
self._name = name
37+
self._token = token
38+
39+
@property
40+
def Id(self):
41+
return self._id
42+
@property
43+
def Uri(self):
44+
return self._uri
45+
@property
46+
def Name(self):
47+
return self._name
48+
@property
49+
def Token(self):
50+
return self._token
51+
52+
def isNew(self):
53+
return self._new
54+
55+
def resetNew(self):
56+
self._new = False
57+
58+
def isRenamed(self, name):
59+
return self._name != name
60+
61+
def setName(self, name):
62+
self._name = name

uno/lib/uno/card/card/replicator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,26 @@ def dispose(self):
6464
def run(self):
6565
mtd = 'run'
6666
logger = getLogger(self._ctx, g_synclog, self._cls)
67-
timeout = 0
67+
timeout = self._config.getByName('ReplicateTimeout')
6868
try:
6969
logger.logprb(INFO, self._cls, mtd, 101)
7070
while not self._canceled:
7171
self._sync.clear()
7272
self._sync.wait(timeout)
7373
if self._canceled:
7474
continue
75-
timeout = self._config.getByName('ReplicateTimeout')
7675
if self._hasConnectedUser():
7776
count = self._syncCard(logger)
7877
if count > 0:
7978
count = self._provider.parseCard(self._database)
8079
if self._provider.supportGroup():
8180
self._syncGroup(logger)
8281
self._database.dispose()
83-
logger.logprb(INFO, self._cls, mtd, 102, timeout // 60)
82+
code = 102
8483
else:
85-
logger.logprb(INFO, self._cls, mtd, 103, timeout // 60)
84+
code = 103
85+
timeout = self._config.getByName('ReplicateTimeout')
86+
logger.logprb(INFO, self._cls, mtd, code, timeout // 60)
8687
logger.logprb(INFO, self._cls, mtd, 104)
8788
except UnoException as e:
8889
logger.logprb(SEVERE, self._cls, mtd, 105, e.Message)

uno/lib/uno/card/card/user.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, ctx, source, logger, database, provider, url, scheme, server,
5454
self._password = pwd
5555
self._sessions = []
5656
logger.logprb(INFO, self._cls, mtd, 1352, name)
57-
metadata, books = database.selectUser(server, name)
57+
metadata, args = database.selectUser(server, name)
5858
new = metadata is None
5959
if not new:
6060
logger.logprb(INFO, self._cls, mtd, 1353, name)
@@ -68,13 +68,14 @@ def __init__(self, ctx, source, logger, database, provider, url, scheme, server,
6868
request = provider.getRequest(url, name)
6969
if request is None:
7070
raise getSqlException(ctx, source, 1002, 1501, self._cls, mtd, name, g_extension)
71-
metadata, books = provider.insertUser(source, logger, database, request, scheme, server, name, pwd)
71+
metadata, args = provider.insertUser(logger, database, request, scheme, server, name, pwd)
7272
if metadata is None:
7373
raise getSqlException(ctx, source, 1005, 1503, self._cls, mtd, name)
7474
database.createUser(getUserSchema(metadata), getUserId(metadata), name, '')
75-
self.Request = request
75+
self._request = request
7676
self._metadata = metadata
77-
self._books = {book.get('Uri'): Book(new, **book) for book in books}
77+
books = (Book(new, **kwargs) for kwargs in args)
78+
self._books = {book.Uri: book for book in books}
7879
logger.logprb(INFO, self._cls, mtd, 1355, name)
7980

8081
@property
@@ -102,11 +103,12 @@ def Password(self):
102103
def BaseUrl(self):
103104
return self.Scheme + self.Server + self.Path
104105
@property
105-
def Books(self):
106-
return self._books.values()
106+
def Request(self):
107+
return self._request
107108

108109
def isOnLine(self):
109110
return self._isOnLine(self.Server)
111+
110112
def isOffLine(self):
111113
return self._isOffLine(self.Server)
112114

@@ -124,11 +126,16 @@ def getSchema(self):
124126
def hasBook(self, uri):
125127
return uri in self._books
126128

129+
def getBooks(self):
130+
return self._books.values()
131+
127132
def getBook(self, uri):
128133
return self._books[uri]
129134

130135
def setNewBook(self, uri, **kwargs):
131-
self._books[uri] = Book(True, **kwargs)
136+
book = Book(True, **kwargs)
137+
self._books[uri] = book
138+
return book
132139

133140
def hasSession(self):
134141
return len(self._sessions) > 0
@@ -143,9 +150,6 @@ def removeSession(self, session):
143150
def unquoteUrl(self, url):
144151
return self.Request.unquoteUrl(url)
145152

146-
def getBooks(self):
147-
return self._books.getBooks()
148-
149153
def _isOffLine(self, server):
150154
return getConnectionMode(self._ctx, server) != ONLINE
151155

uno/lib/uno/card/database.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,13 @@ def getSessionId(self, connection):
156156

157157
def insertUser(self, uri, scheme, server, path, name):
158158
metadata = None
159-
books = []
160159
call = self._getCall('insertUser')
161160
call.setString(1, uri)
162161
call.setString(2, scheme)
163162
call.setString(3, server)
164163
call.setString(4, path)
165164
call.setString(5, name)
166-
result = call.executeQuery()
165+
call.execute()
167166
user = call.getInt(6)
168167
if not call.wasNull():
169168
metadata = {'User': user,
@@ -172,11 +171,8 @@ def insertUser(self, uri, scheme, server, path, name):
172171
'Server': server,
173172
'Path': path,
174173
'Name': name}
175-
while result.next():
176-
books.append(getDataFromResult(result))
177-
result.close()
178174
call.close()
179-
return metadata, books
175+
return metadata, ()
180176

181177
def createUser(self, schema, userid, name, password):
182178
try:
@@ -205,7 +201,7 @@ def _getItemOptions(self, catalog, schema, name, *options):
205201

206202
def selectUser(self, server, name):
207203
metadata = None
208-
books = []
204+
args = []
209205
call = self._getCall('selectUser')
210206
call.setString(1, server)
211207
call.setString(2, name)
@@ -219,10 +215,10 @@ def selectUser(self, server, name):
219215
'Path': call.getString(6),
220216
'Name': name}
221217
while result.next():
222-
books.append(getDataFromResult(result))
218+
args.append(getDataFromResult(result))
223219
result.close()
224220
call.close()
225-
return metadata, books
221+
return metadata, args
226222

227223
# Procedures called by the User
228224
def getUserFields(self):
@@ -239,11 +235,11 @@ def initAddressbooks(self, user):
239235
self._initUserView('Book', *args)
240236
self._updateBookSync(user, stop)
241237

242-
def initGroups(self, user, uri, iterator):
238+
def initGroups(self, user, book, iterator):
243239
uris = []
244240
names = []
245241
call = self._getCall('initGroups')
246-
call.setInt(1, user.getBook(uri).Id)
242+
call.setInt(1, user.getBook(book).Id)
247243
for uri, name in iterator:
248244
uris.append(uri)
249245
names.append(name)
@@ -257,16 +253,18 @@ def initGroups(self, user, uri, iterator):
257253
call.close()
258254
return remove, add
259255

260-
def insertGroups(self, user, iterator):
256+
def insertGroup(self, bookid, uri, name):
257+
args = None
261258
call = self._getCall('insertGroup')
262-
call.setInt(1, user.Id)
263-
for uri, name in iterator:
264-
call.setString(2, uri)
265-
call.setString(3, name)
266-
call.execute()
267-
gid = call.getInt(4)
268-
yield {'Query': 'Inserted', 'User': user.Id, 'Group': gid, 'Schema': user.getSchema(), 'Name': name}
259+
call.setInt(1, bookid)
260+
call.setString(2, uri)
261+
call.setString(3, name)
262+
call.execute()
263+
group = call.getInt(4)
264+
if not call.wasNull():
265+
args = (group, uri, name)
269266
call.close()
267+
return args
270268

271269
def syncGroups(self, user):
272270
start = self.getLastSync('GroupSync', user)
@@ -319,7 +317,7 @@ def _initUserView(self, view, query, schema, user, item, oldname, newname):
319317
if query == 'Deleted' or query == 'Updated':
320318
self._deleteUserView(g_catalog, schema, oldname)
321319
if query == 'Inserted' or query == 'Updated':
322-
template = {'Catalog': g_catalog, 'Schema': g_schema, 'Item': item}
320+
template = {'Catalog': g_catalog, 'Schema': g_schema, 'ItemId': item}
323321
command = getSqlQuery(self._ctx, 'get%sViewCommand' % view, template)
324322
self._createUserView(g_catalog, schema, newname, command, CASCADE)
325323
self._grantPrivileges(g_catalog, schema, newname, user, TABLE, 1)
@@ -333,6 +331,13 @@ def _deleteUserView(self, catalog, schema, name):
333331
if views.hasByName(view):
334332
views.dropByName(view)
335333

334+
def _renameUserView(self, catalog, schema, newname, oldname):
335+
views = self.Connection.getViews()
336+
newview = f'{catalog}.{schema}.{newname}'
337+
oldview = f'{catalog}.{schema}.{oldname}'
338+
if views.hasByName(oldview) and not views.hasByName(newview):
339+
views.rename(oldview, newview)
340+
336341
def insertBook(self, userid, uri, name, tag=None, token=None):
337342
book = None
338343
call = self._getCall('insertBook')
@@ -354,19 +359,18 @@ def insertBook(self, userid, uri, name, tag=None, token=None):
354359
call.close()
355360
return book
356361

357-
def initGroupView(self, user, remove, add):
362+
def createGroupView(self, user, group):
358363
schema = user.getSchema()
359-
if remove:
360-
for item in remove:
361-
self._deleteUserView(g_catalog, schema, item.get('OldName'))
362-
if add:
363-
for item in add:
364-
view = item.get('NewName')
365-
item['Catalog'] = g_catalog
366-
item['Schema'] = g_schema
367-
command = getSqlQuery(self._ctx, 'getGroupViewCommand', item)
368-
self._createUserView(g_catalog, schema, view, command, CASCADE)
369-
self._grantPrivileges(g_catalog, schema, view, user.Name, TABLE, 1)
364+
template = {'Catalog': g_catalog, 'Schema': g_schema, 'ItemId': group.Id}
365+
command = getSqlQuery(self._ctx, 'getGroupViewCommand', template)
366+
self._createUserView(g_catalog, schema, group.Name, command, CASCADE)
367+
self._grantPrivileges(g_catalog, schema, group.Name, user.Name, TABLE, 1)
368+
369+
def removeGroupView(self, user, group):
370+
self._deleteUserView(g_catalog, user.getSchema(), group.Name)
371+
372+
def renameGroupView(self, user, group, name):
373+
self._renameUserView(g_catalog, user.getSchema(), group.Name, name)
370374

371375
def updateAddressbookName(self, addressbook, name):
372376
call = self._getCall('updateAddressbookName')

0 commit comments

Comments
 (0)