Skip to content

Commit

Permalink
git subrepo pull uno
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "uno"
  merged:   "37d15f61"
upstream:
  origin:   "https://github.com/prrvchr/uno.git"
  branch:   "main"
  commit:   "37d15f61"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
  • Loading branch information
prrvchr committed Apr 16, 2024
1 parent eb368f1 commit 608bf4f
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 115 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 = 860ad296f258a7d4376abf1b5b7f1df26e330440
parent = 96d94067dd03fb79a5a80196db31cf6167d8951d
commit = 37d15f613e82192a3da5a10e70c8d272f0ee2f74
parent = eb368f1fcfb495ef3d3bddc4f36b27dad1f1982d
method = merge
cmdver = 0.4.3
2 changes: 0 additions & 2 deletions uno/lib/uno/embedded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

from .configuration import g_extension
from .configuration import g_identifier
from .configuration import g_catalog
from .configuration import g_user

from .options import OptionsManager

Expand Down
142 changes: 72 additions & 70 deletions uno/lib/uno/embedded/documenthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from com.sun.star.embed.ElementModes import SEEKABLEREAD
from com.sun.star.embed.ElementModes import READWRITE
from com.sun.star.embed.ElementModes import TRUNCATE

from com.sun.star.logging.LogLevel import INFO
from com.sun.star.logging.LogLevel import SEVERE
Expand All @@ -48,6 +49,7 @@
from .unotool import parseUrl

from .configuration import g_protocol
from .configuration import g_catalog
from .configuration import g_options
from .configuration import g_shutdown

Expand All @@ -57,7 +59,7 @@
class DocumentHandler(unohelper.Base,
XCloseListener,
XStorageChangeListener):
def __init__(self, ctx, lock, logger, url, name):
def __init__(self, ctx, lock, logger, url, index):
self._ctx = ctx
self._directory = 'database'
self._prefix = '.'
Expand All @@ -67,7 +69,7 @@ def __init__(self, ctx, lock, logger, url, name):
self._listening = False
self._path, self._folder = self._getDataBaseInfo(url)
self._url = url
self._name = name
self._index = index

@property
def URL(self):
Expand All @@ -80,7 +82,7 @@ def queryClosing(self, event, owner):
with self._lock:
document = event.Source
if self._closeDataBase(document):
self._removeFolder()
self.removeFolder()
self._url = None
self._logger.logprb(INFO, 'DocumentHandler', 'queryClosing()', 202, url)

Expand All @@ -95,7 +97,7 @@ def notifyStorageChange(self, document, storage):
with self._lock:
newpath, newfolder = self._getDataBaseInfo(url)
if self._switchDataBase(document, storage, newfolder):
self._removeFolder()
self.removeFolder()
self._path = newpath
self._folder = newfolder
self._url = url
Expand All @@ -112,28 +114,36 @@ def disposing(self, event):
self._url = None
self._logger.logprb(INFO, 'DocumentHandler', 'disposing()', 222, url)

# DocumentHandler getter methods
def getConnectionUrl(self, document, storage, url):
with self._lock:
sf = getSimpleFile(self._ctx)
if not sf.exists(self._path):
if storage.hasElements():
# FIXME: With OpenOffice getElementNames() return a String
# FIXME: if storage has no elements.
self._openDataBase(sf, storage)
else:
sf.createFolder(self._path)
# FIXME: With OpenOffice there is no Document in the info
# FIXME: parameter provided during the connection
if document is None:
document = self._getDocument(url)
# DocumentHandler setter methods
def setListener(self, document):
# FIXME: With OpenOffice there is no Document in the info
# FIXME: parameter provided during the connection
if document is None:
document = self._getDocument()
if document is not None:
# FIXME: We want to add the StorageChangeListener only once
if not self._listening:
document.addStorageChangeListener(self)
self._listening = True
# FIXME: If storage has been changed the closeListener has been removed
document.addCloseListener(self)
return self._getConnectionUrl()

def removeFolder(self):
sf = getSimpleFile(self._ctx)
if sf.isFolder(self._path):
sf.kill(self._path)

# DocumentHandler getter methods
def getConnectionUrl(self, storage):
with self._lock:
exist = storage.hasElements()
sf = getSimpleFile(self._ctx)
if not sf.exists(self._path):
sf.createFolder(self._path)
if exist:
count = self._extractStorage(sf, storage, self._path)
self._logger.logprb(INFO, 'DocumentHandler', 'getConnectionUrl()', 231, count)
return self._getConnectionUrl(exist)

# DocumentHandler private getter methods
def _getDataBaseInfo(self, location):
Expand Down Expand Up @@ -161,22 +171,21 @@ def _getDocumentName(self, title):
name, sep, extension = title.rpartition('.')
return name if sep else extension

def _getDocument(self, url):
def _getDocument(self):
document = None
interface = 'com.sun.star.frame.XStorable'
components = getDesktop(self._ctx).getComponents().createEnumeration()
while components.hasMoreElements():
component = components.nextElement()
if hasInterface(component, interface) and component.hasLocation() and component.getLocation() == url:
if hasInterface(component, interface) and component.hasLocation() and component.getLocation() == self._url:
document = component
break
return document

def _getFileUrl(self, name):
return '%s/%s' % (self._path, name)

def _getConnectionUrl(self):
return '%s%s/%s%s%s' % (g_protocol, self._path, self._name, g_options, g_shutdown)
def _getConnectionUrl(self, exist):
path = self._path[self._index:]
url = '%s%s/%s%s' % (g_protocol, path, g_catalog, g_shutdown)
return url if exist else url + g_options

def _getStorageName(self, name, oldname, newname):
return name.replace(oldname, newname)
Expand All @@ -185,70 +194,63 @@ def _closeDataBase(self, document):
try:
target = document.getDocumentSubStorage(self._directory, READWRITE)
service = 'com.sun.star.embed.FileSystemStorageFactory'
args = (self._path, READWRITE)
args = (self._path, SEEKABLEREAD)
source = createService(self._ctx, service).createInstanceWithArguments(args)
# FIXME: With OpenOffice getElementNames() return a String
# FIXME: if storage has no elements.
if source.hasElements():
for name in source.getElementNames():
if source.isStreamElement(name):
if target.hasByName(name):
target.removeElement(name)
self._logger.logprb(INFO, 'DocumentHandler', '_closeDataBase()', 231, name)
source.copyElementTo(name, target, name)
self._logger.logprb(INFO, 'DocumentHandler', '_closeDataBase()', 232, name)
target.commit()
target.dispose()
source.dispose()
count = self._copyStorage(source, target)
self._logger.logprb(INFO, 'DocumentHandler', '_closeDataBase()', 241, count)
document.store()
return True
except Exception as e:
self._logger.logprb(SEVERE, 'DocumentHandler', '_closeDataBase()', 233, self._url, traceback.format_exc())
self._logger.logprb(SEVERE, 'DocumentHandler', '_closeDataBase()', 242, self._url, traceback.format_exc())
return False

def _switchDataBase(self, document, storage, newname):
try:
target = storage.openStorageElement(self._directory, READWRITE)
service = 'com.sun.star.embed.FileSystemStorageFactory'
args = (self._path, READWRITE)
args = (self._path, SEEKABLEREAD)
source = createService(self._ctx, service).createInstanceWithArguments(args)
# FIXME: With OpenOffice getElementNames() return a String
# FIXME: if storage has no elements.
if source.hasElements():
for name in source.getElementNames():
if source.isStreamElement(name):
self._logger.logprb(INFO, 'DocumentHandler', '_switchDataBase()', 241, name)
self._moveStorage(source, target, name, newname)
self._logger.logprb(INFO, 'DocumentHandler', '_switchDataBase()', 242, name)
target.commit()
target.dispose()
source.dispose()
count = self._copyStorage(source, target)
self._logger.logprb(INFO, 'DocumentHandler', '_switchDataBase()', 251, count)
document.store()
return True
except Exception as e:
self._logger.logprb(SEVERE, 'DocumentHandler', '_switchDataBase()', 243, self._url, traceback.format_exc())
self._logger.logprb(SEVERE, 'DocumentHandler', '_switchDataBase()', 252, self._url, traceback.format_exc())
return False

# DocumentHandler private setter methods
def _openDataBase(self, sf, source):
def _copyStorage(self, source, target):
count = 0
for name in source.getElementNames():
url = self._getFileUrl(name)
if not sf.exists(url):
if source.isStreamElement(name):
if target.hasByName(name):
target.removeElement(name)
source.copyElementTo(name, target, name)
count += 1
else:
count += self._copyStorage(source.openStorageElement(name, SEEKABLEREAD),
target.openStorageElement(name, READWRITE))
target.commit()
target.dispose()
source.dispose()
return count

def _extractStorage(self, sf, source, url):
count = 0
if source.hasElements():
for name in source.getElementNames():
path = self._getPath(url, name)
if source.isStreamElement(name):
input = source.openStreamElement(name, SEEKABLEREAD).getInputStream()
sf.writeFile(url, input)
sf.writeFile(path, input)
input.closeInput()
count += 1
else:
sf.createFolder(path)
count += self._extractStorage(sf, source.openStorageElement(name, SEEKABLEREAD), path)
source.dispose()
return count

def _moveStorage(self, source, target, oldname, newname):
if target.hasByName(oldname):
target.removeElement(oldname)
name = self._getStorageName(oldname, self._folder, newname)
if target.hasByName(name):
target.removeElement(name)
source.copyElementTo(oldname, target, name)
def _getPath(self, path, name):
return '%s/%s' % (path, name)

def _removeFolder(self):
sf = getSimpleFile(self._ctx)
if sf.isFolder(self._path):
sf.kill(self._path)
41 changes: 22 additions & 19 deletions uno/lib/uno/embedded/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ class Driver(unohelper.Base,
XServiceInfo,
XDriver):

def __init__(self, ctx, lock, service, name, catalog, user):
def __init__(self, ctx, lock, service, name, index):
self._ctx = ctx
self._lock = lock
self._service = service
self._name = name
self._catalog = catalog
self._user = user
self._index = index
self._logger = getLogger(ctx, g_defaultlog, g_basename)
# FIXME: Driver is lazy loaded in connect() driver method to be able to throw
# FIXME: an exception if jdbcDriverOOo extension is not installed.
Expand All @@ -85,23 +84,27 @@ def __init__(self, ctx, lock, service, name, catalog, user):

# XDriver
def connect(self, url, infos):
# XXX: We need to test first if jdbcDriverOOo is installed...
driver = self._getDriver()
newinfos, document, storage, location = self._getConnectionInfo(infos)
if storage is None or location is None:
self._logException(112, url, ' ')
raise self._getException(1001, None, 111, url, '\n')
# XXX: Calling handler unpacks the database files
handler = self._getDocumentHandler(location)
path = handler.getConnectionUrl(storage)
self._logger.logprb(INFO, 'Driver', 'connect()', 113, location)
try:
newinfos, document, storage, location = self._getConnectionInfo(infos)
if storage is None or location is None:
self._logException(112, url, ' ')
raise self._getException(1001, None, 111, url, '\n')
handler = self._getDocumentHandler(location)
path = handler.getConnectionUrl(document, storage, location)
self._logger.logprb(INFO, 'Driver', 'connect()', 113, location)
connection = self._getDriver().connect(path, newinfos)
version = connection.getMetaData().getDriverVersion()
self._logger.logprb(INFO, 'Driver', 'connect()', 114, g_dbname, version, g_user)
return connection
except SQLException as e:
raise e
connection = driver.connect(path, newinfos)
except Exception as e:
self._logger.logprb(SEVERE, 'Driver', 'connect()', 115, str(e), traceback.format_exc())
handler.removeFolder()
raise e
# XXX: Connection has been done we can add close and change listener to document
handler.setListener(document)
version = connection.getMetaData().getDriverVersion()
self._logger.logprb(INFO, 'Driver', 'connect()', 114, g_dbname, version, g_user)
return connection

def acceptsURL(self, url):
accept = url.startswith(g_url)
Expand Down Expand Up @@ -155,8 +158,8 @@ def _getConnectionInfo(self, infos):
document = storage = url = None
service = getConfiguration(self._ctx, g_identifier).getByName('ConnectionService')
newinfos = {'Url': g_url, 'ConnectionService': service}
if self._user is not None:
newinfos['user'] = self._user
if g_user:
newinfos['user'] = g_user
for info in infos:
if info.Name == 'URL':
url = info.Value
Expand All @@ -183,7 +186,7 @@ def _getDocumentHandler(self, location):
with self._lock:
handler = self._getHandler(location)
if handler is None:
handler = DocumentHandler(self._ctx, self._lock, self._logger, location, self._catalog)
handler = DocumentHandler(self._ctx, self._lock, self._logger, location, self._index)
self._handlers.append(handler)
return handler

Expand Down
4 changes: 2 additions & 2 deletions uno/lib/uno/embedded/sdbc/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

class Driver(DriverBase):

def __init__(self, ctx, lock, service, name, catalog, user=None):
DriverBase.__init__(self, ctx, lock, service, name, catalog, user)
def __init__(self, ctx, lock, service, name, index=0):
DriverBase.__init__(self, ctx, lock, service, name, index)
self._services = ('com.sun.star.sdbc.Driver', )
self._logger.logprb(INFO, 'Driver', '__init__()', 101)

4 changes: 2 additions & 2 deletions uno/lib/uno/embedded/sdbcx/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Driver(DriverBase,
XCreateCatalog,
XDropCatalog):

def __init__(self, ctx, lock, service, name, catalog, user=None):
DriverBase.__init__(self, ctx, lock, service, name, catalog, user)
def __init__(self, ctx, lock, service, name, index=0):
DriverBase.__init__(self, ctx, lock, service, name, index)
self._services = ('com.sun.star.sdbc.Driver', 'com.sun.star.sdbcx.Driver')
self._logger.logprb(INFO, 'Driver', '__init__()', 101)

Expand Down
20 changes: 11 additions & 9 deletions uno/resource/embedded/Driver_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
221=Attempt to dispose document with Url: {}
222=The document with Url: {} has been disposed...

230=DocumentHandler._closeDataBase()
231=Attempt to move element with name: {}
232=The element with name: {} has been moved...
233=An exception occurred while closing the document: {}\nTraceback: {}

240=DocumentHandler._switchDataBase()
241=Attempt to move element with name: {}
242=The element with name: {} has been moved...
243=An exception occurred while saving the document: {}\nTraceback: {}
230=DocumentHandler.getConnectionUrl()
231=Opening the database, {} unzipped files
232=An exception occurred while opening the document: {}\nTraceback: {}

240=DocumentHandler._closeDataBase()
241=Database has been closed, {} files compressed
242=An exception occurred while closing the document: {}\nTraceback: {}

250=DocumentHandler._switchDataBase()
251=Database has been switched, {} files transfered
252=An exception occurred while saving the document: {}\nTraceback: {}
Loading

0 comments on commit 608bf4f

Please sign in to comment.