summaryrefslogtreecommitdiff
path: root/wizards/com/sun
diff options
context:
space:
mode:
authorJavier Fernandez <jfernandez@igalia.com>2013-05-03 14:25:54 +0000
committerJavier Fernandez <jfernandez@igalia.com>2013-05-08 09:36:39 +0000
commitd6f1c31e8aa2b84f11a6b96fd2ca69136908cfd9 (patch)
tree9e4beef77194e5a728e46be1941939291419606a /wizards/com/sun
parent8583086da2b982699e254126585a4d9abdf23766 (diff)
PyWebWizard: Fixing bugs and implementation of mising features.
New utility I/O methods. Change-Id: I8532d289582d9ed4b25568801617e33e4df41a5b
Diffstat (limited to 'wizards/com/sun')
-rw-r--r--wizards/com/sun/star/wizards/common/FileAccess.py221
-rw-r--r--wizards/com/sun/star/wizards/common/UCB.py41
2 files changed, 234 insertions, 28 deletions
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index c6957678b9fe..0e67851d7640 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -17,6 +17,8 @@
#
import traceback
+from os import sep as FileSeparator
+
'''
This class delivers static convenience methods
to use with ucb SimpleFileAccess service.
@@ -35,8 +37,113 @@ class FileAccess(object):
#get the file identifier converter
self.filenameConverter = xmsf.createInstance(
"com.sun.star.ucb.FileContentProvider")
+ self.xInterface = xmsf.createInstance(
+ "com.sun.star.ucb.SimpleFileAccess")
@classmethod
+ def deleteLastSlashfromUrl(self, _sPath):
+ if _sPath.endswith("/"):
+ return _sPath[:-1]
+ else:
+ return _sPath
+
+ '''
+ Further information on arguments value see in OO Developer Guide,
+ chapter 6.2.7
+ @param xMSF
+ @param sPath
+ @param xSimpleFileAccess
+ @return the respective path of the office application.
+ A probable following "/" at the end is trimmed.
+ '''
+
+ @classmethod
+ def getOfficePath(self, xMSF, sPath, xSimpleFileAccess):
+ try:
+ ResultPath = ""
+ xInterface = xMSF.createInstance("com.sun.star.util.PathSettings")
+ ResultPath = str(getattr(xInterface, sPath))
+ ResultPath = self.deleteLastSlashfromUrl(ResultPath)
+ return ResultPath
+ except Exception:
+ traceback.print_exc()
+ return ""
+
+ '''
+ Further information on arguments value see in OO Developer Guide,
+ chapter 6.2.7
+ @param xMSF
+ @param sPath
+ @param sType use "share" or "user". Set to ""
+ f not needed eg for the WorkPath;
+ In the return Officepath a possible slash at the end is cut off
+ @param sSearchDir
+ @return
+ @throws NoValidPathException
+ '''
+
+ @classmethod
+ def getOfficePath2(self, xMSF, sPath, sType, sSearchDir):
+ #This method currently only works with sPath="Template"
+ bexists = False
+ try:
+ xPathInterface = xMSF.createInstance(
+ "com.sun.star.util.PathSettings")
+ ResultPath = ""
+ ReadPaths = ()
+ xUcbInterface = xMSF.createInstance(
+ "com.sun.star.ucb.SimpleFileAccess")
+ Template_writable = xPathInterface.getPropertyValue(
+ sPath + "_writable")
+ Template_internal = xPathInterface.getPropertyValue(
+ sPath + "_internal")
+ Template_user = xPathInterface.getPropertyValue(
+ sPath + "_user")
+ if not hasattr(Template_internal, '__dict__'):
+ ReadPaths = ReadPaths + Template_internal
+ if not hasattr(Template_user, '__dict__'):
+ ReadPaths = ReadPaths + Template_user
+ ReadPaths = ReadPaths + (Template_writable,)
+ if sType.lower() == "user":
+ ResultPath = Template_writable
+ bexists = True
+ else:
+ #find right path using the search sub path
+ for i in ReadPaths:
+ tmpPath = i + sSearchDir
+ if xUcbInterface.exists(tmpPath):
+ ResultPath = i
+ bexists = True
+ break
+
+ ResultPath = self.deleteLastSlashfromUrl(ResultPath)
+ except Exception:
+ traceback.print_exc()
+ ResultPath = ""
+
+ if not bexists:
+ raise NoValidPathException (xMSF, "")
+ return ResultPath
+
+ @classmethod
+ def combinePaths(self, xMSF, _sFirstPath, _sSecondPath):
+ bexists = False
+ ReturnPath = ""
+ try:
+ xUcbInterface = xMSF.createInstance(
+ "com.sun.star.ucb.SimpleFileAccess")
+ ReturnPath = _sFirstPath + _sSecondPath
+ bexists = xUcbInterface.exists(ReturnPath)
+ except Exception:
+ traceback.print_exc()
+ return ""
+
+ if not bexists:
+ raise NoValidPathException (xMSF, "")
+
+ return ReturnPath
+
+ @classmethod
def getFolderTitles(self, xMSF, FilterName, FolderName, resDict=None):
#Returns and ordered dict containing the template's name and path
@@ -112,13 +219,106 @@ class FileAccess(object):
return self.filenameConverter.getSystemPathFromFileURL(
parentURL + string)
+ def copy(self, source, target):
+ try:
+ self.xInterface.copy(source, target)
+ return True
+ except Exception:
+ traceback.print_exc()
+ return False
+
+ def exists(self, filename, default):
+ try:
+ return self.xInterface.exists(filename)
+ except Exception:
+ traceback.print_exc()
+ return default
+
+ def isDirectory(self, filename):
+ try:
+ return self.xInterface.isFolder(filename)
+ except Exception:
+ traceback.print_exc()
+ return False
+
+ def getLastModified(self, url):
+ try:
+ return self.xInterface.getDateTimeModified(url)
+ except Exception:
+ traceback.print_exc()
+ return None
+
+ def delete(self, filename):
+ try:
+ self.xInterface.kill(filename)
+ return True
+ except Exception:
+ traceback.print_exc()
+ return False
+
+ # lists the files in a given directory
+ # @param dir
+ # @param includeFolders
+ # @return
+ def listFiles(self, folder, includeFolders):
+ try:
+ return self.xInterface.getFolderContents(folder, includeFolders)
+ except Exception:
+ traceback.print_exc()
+ return [""]
+
+ #
+ # @param s
+ # @return
+ def mkdir(self, s):
+ try:
+ self.xInterface.createFolder(s)
+ return True
+ except Exception:
+ traceback.print_exc()
+ return False
+
+ def createNewDir(self, parentDir, name):
+ s = self.getNewFile(parentDir, name, "")
+ if (self.mkdir(s)):
+ return s
+ else:
+ return None
+
+ def getSize(self, url):
+ try:
+ return self.xInterface.getSize(url)
+ except Exception:
+ traceback.print_exc()
+ return -1
+
+ def getNewFile(self, parentDir, name, extension):
+ i = 0
+ url = ""
+ while (True):
+ filename = self.filename(name, extension, i)
+ url = self.getURL(parentDir, filename)
+ if (not self.exists(url, True)):
+ break
+ i += 1
+ return url
+
+ def getURL(self, parentPath, childPath):
+ parent = self.filenameConverter.getSystemPathFromFileURL(parentPath);
+ path = parent + "/" + childPath
+ return self.filenameConverter.getFileURLFromSystemPath(parentPath, path)
+
+ def getURL1(self, path):
+ f = "/"
+ return self.filenameConverter.getFileURLFromSystemPath(path, f)
+
'''
return the filename out of a system-dependent path
'''
@classmethod
def getPathFilename(self, path):
- return self.getFilename(path, File.separator)
+ return self.getFilename(path, FileSeparator)
@classmethod
def getFilename(self, path, pathSeparator = "/"):
@@ -143,3 +343,22 @@ class FileAccess(object):
if urlFilename.startswith("/"):
stringFileName = urlFilename[1:]
return urlFolder + stringFolder + stringFileName
+
+ # @param filename
+ # @return the extension of the given filename.
+ @classmethod
+ def getExtension(self, filename):
+ p = filename.find(".")
+ if (p == -1):
+ return ""
+ else:
+ while (True):
+ filename = filename[(p+1):]
+ p = filename.find(".")
+ if (p == -1):
+ break
+ return filename
+
+ @classmethod
+ def filename(self, name, ext, i):
+ return name + ("" if (i == 0) else str(i)) + ("" if (ext == "") else ("." + ext))
diff --git a/wizards/com/sun/star/wizards/common/UCB.py b/wizards/com/sun/star/wizards/common/UCB.py
index a7c3ff13a9b2..3689b1465019 100644
--- a/wizards/com/sun/star/wizards/common/UCB.py
+++ b/wizards/com/sun/star/wizards/common/UCB.py
@@ -30,13 +30,6 @@ from com.sun.star.ucb.NameClash import OVERWRITE
from com.sun.star.ucb import OpenCommandArgument2
from com.sun.star.ucb.OpenMode import ALL
from com.sun.star.ucb.TransferCommandOperation import COPY
-#from com.sun.star.ucb import XCommandProcessor
-#from com.sun.star.ucb import XContentAccess
-#from com.sun.star.ucb import XContentIdentifier
-from com.sun.star.ucb import XContentIdentifierFactory
-from com.sun.star.ucb import XContentProvider
-#from com.sun.star.ucb import XDynamicResultSet
-#from com.sun.star.uno import UnoRuntime
# This class is used to copy the content of a folder to
@@ -71,12 +64,9 @@ class UCB(object):
def copy1(self, sourceDir, targetDir, verifier):
files = self.listFiles(sourceDir, verifier)
for i in range(len(files)):
- self.copy2(sourceDir, files[i], targetDir)
+ self.copy3(sourceDir, files[i], targetDir)
def copy2(self, sourceDir, filename, targetDir, targetName):
- #sourceDir = "file:///home/javi/intel-libreoffice/install/share/config/" + sourceDir[7:]
- print ("WARNING !!! copy2 - sourcedir, filenName :", sourceDir, filename)
- print ("WARNING !!! copy2 - targetDir, targetName :", targetDir, targetName)
if (not self.fa.exists(targetDir, True)):
self.fa.xInterface.createFolder(targetDir)
self.executeCommand(self.ucb, "globalTransfer", self.copyArg(sourceDir, filename, targetDir, targetName))
@@ -135,10 +125,16 @@ class UCB(object):
# obtain XContentAccess interface for child content access and XRow for properties
while (True):
# Obtain URL of child.
- aId = xResultSet.queryContentIdentifierString()
- # First column: Title (column numbers are 1-based!)
- aTitle = xResultSet.getString(1)
- if (len(aTitle) == 0 and xResultSet.wasNull()):
+ if (hasattr(xResultSet, "queryContentIdentifierString")):
+ aId = xResultSet.queryContentIdentifierString()
+ aTitle = FileAccess.getFilename(aId)
+ elif (hasattr(xResultSet, "getString")):
+ # First column: Title (column numbers are 1-based!)
+ aTitle = xResultSet.getString(1)
+ else:
+ aTitle = ""
+ #if (len(aTitle) == 0 and xResultSet.wasNull()):
+ if (len(aTitle) == 0):
# ignore
pass
else:
@@ -153,12 +149,12 @@ class UCB(object):
return files
def getContentProperty(self, content, propName, classType):
- pv = []
- pv[0] = Property()
+ pv = [Property()]
pv[0].Name = propName
pv[0].Handle = -1
- row = self.executeCommand(content, "getPropertyValues", pv)
+ row = self.executeCommand(content, "getPropertyValues",
+ uno.Any("[]com.sun.star.beans.Property", tuple(pv)))
if (isinstance(classType, str)):
return row.getString(1)
elif (isinstance(classType, bool)):
@@ -172,16 +168,7 @@ class UCB(object):
def getContent(self, path):
try:
- print ("WARNING !!! getContent - path: ", path)
- #if (path.startswith("/")):
- # s = "file://" + path
- #elif (path.startswith("file://")):
- # s = path
- #else:
- # s = "file:///home/javi/intel-libreoffice/install/share/config/" + path[7:]
- #ident = self.ucb.createContentIdentifier(s)
ident = self.ucb.createContentIdentifier(path)
- print ("WARNING !!! getContent - ident: ", ident.getContentIdentifier())
return self.ucb.queryContent(ident)
except Exception:
traceback.print_exc()