summaryrefslogtreecommitdiff
path: root/wizards/com/sun
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2012-11-24 20:13:49 +0100
committerXisco Fauli <anistenis@gmail.com>2012-11-24 22:20:52 +0100
commit63510b3c69761ec1de3c1acd30cf6e4e3a55184a (patch)
treec3e5b767f5a3060905fe043e5b0ced77205a6c53 /wizards/com/sun
parente5f040bf7c73104ad472c4fd959dc6f8d96b57c2 (diff)
pywizards: better us os.path
Change-Id: Iae2bfba899ba23e743f72f5c675177771be66c7a
Diffstat (limited to 'wizards/com/sun')
-rw-r--r--wizards/com/sun/star/wizards/common/FileAccess.py204
-rw-r--r--wizards/com/sun/star/wizards/document/OfficeDocument.py9
-rw-r--r--wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py21
-rw-r--r--wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py4
4 files changed, 18 insertions, 220 deletions
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index 6440c51c78d7..28374da593c1 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -37,30 +37,11 @@ These Convenince methods include mainly Exception-handling.
class FileAccess(object):
- @classmethod
- def addOfficePath(self, xMSF, sPath, sAddPath):
- xSimpleFileAccess = None
- ResultPath = getOfficePath(xMSF, sPath, xSimpleFileAccess)
- '''
- As there are several conventions about the look of Url
- (e.g. with " " or with "%20") you cannot make a
- simple String comparison to find out, if a path
- is already in "ResultPath
- '''
- PathList = JavaTools.ArrayoutofString(ResultPath, ";")
- MaxIndex = PathList.length - 1
- CompAddPath = JavaTools.replaceSubString(sAddPath, "", "/")
- i = 0
- while i <= MaxIndex:
- CurPath = JavaTools.convertfromURLNotation(PathList[i])
- CompCurPath = JavaTools.replaceSubString(CurPath, "", "/")
- if CompCurPath.equals(CompAddPath):
- return
-
- i += 1
- ResultPath += ";" + sAddPath
- return
-
+ def __init__(self, xmsf):
+ #get the file identifier converter
+ self.filenameConverter = xmsf.createInstance(
+ "com.sun.star.ucb.FileContentProvider")
+
@classmethod
def deleteLastSlashfromUrl(self, _sPath):
if _sPath.endswith("/"):
@@ -148,18 +129,6 @@ class FileAccess(object):
return ResultPath
@classmethod
- def isPathValid(self, xMSF, _sPath):
- bExists = False
- try:
- xUcbInterface = xMSF.createInstance(
- "com.sun.star.ucb.SimpleFileAccess")
- bExists = xUcbInterface.exists(_sPath)
- except Exception:
- traceback.print_exc()
-
- return bExists
-
- @classmethod
def combinePaths(self, xMSF, _sFirstPath, _sSecondPath):
bexists = False
ReturnPath = ""
@@ -238,14 +207,6 @@ class FileAccess(object):
return sTitle
- def __init__(self, xmsf):
- #get a simple file access...
- self.fileAccess = xmsf.createInstance(
- "com.sun.star.ucb.SimpleFileAccess")
- #get the file identifier converter
- self.filenameConverter = xmsf.createInstance(
- "com.sun.star.ucb.FileContentProvider")
-
def getURL(self, path, childPath=None):
try:
f = open(path, 'w')
@@ -265,101 +226,6 @@ class FileAccess(object):
parentURL + string)
'''
- @author rpiterman
- @param filename
- @return the extension of the given filename.
- '''
-
- @classmethod
- def getExtension(self, filename):
- p = filename.indexOf(".")
- if p == -1:
- return ""
- else:
- while p > -1:
- filename = filename.substring(p + 1)
- p = filename.indexOf(".")
-
- return filename
-
- '''
- @author rpiterman
- @param s
- @return
- '''
-
- def mkdir(self, s):
- try:
- self.fileAccess.createFolder(s)
- return True
- except Exception:
- traceback.print_exc()
-
- return False
-
- '''
- @author rpiterman
- @param filename
- @param def what to return in case of an exception
- @return true if the given file exists or not.
- if an exception accures, returns the def value.
- '''
-
- def exists(self, filename, defe):
- try:
- return self.fileAccess.exists(filename)
- except Exception:
- traceback.print_exc()
-
- return defe
-
- '''
- @author rpiterman
- @param filename
- @return
- '''
-
- def isDirectory(self, filename):
- try:
- return self.fileAccess.isFolder(filename)
- except Exception:
- traceback.print_exc()
-
- return False
-
- '''
- lists the files in a given directory
- @author rpiterman
- @param dir
- @param includeFolders
- @return
- '''
-
- def listFiles(self, dir, includeFolders):
- try:
- return self.fileAccess.getFolderContents(dir, includeFolders)
- except Exception:
- traceback.print_exc()
-
- return range(0)
-
- '''
- @author rpiterman
- @param file
- @return
- '''
-
- def delete(self, file):
- try:
- self.fileAccess.kill(file)
- return True
- except Exception:
- traceback.print_exc()
-
- return False
-
-
- '''
return the filename out of a system-dependent path
@param path
@return
@@ -380,38 +246,6 @@ class FileAccess(object):
def getFilename(self, path, pathSeparator = "/"):
return path.split(pathSeparator)[-1]
- @classmethod
- def getBasename(self, path, pathSeparator):
- filename = self.getFilename(path, pathSeparator)
- sExtension = getExtension(filename)
- basename = filename.substring(0, filename.length() - \
- (sExtension.length() + 1))
- return basename
-
- '''
- @author rpiterman
- @param source
- @param target
- @return
- '''
-
- def copy(self, source, target):
- try:
- self.fileAccess.copy(source, target)
- return True
- except Exception:
- traceback.print_exc()
-
- return False
-
- def getLastModified(self, url):
- try:
- return self.fileAccess.getDateTimeModified(url)
- except Exception:
- traceback.print_exc()
-
- return None
-
'''
@param url
@return the parent dir of the given url.
@@ -424,34 +258,6 @@ class FileAccess(object):
url = hello[:-1]
return url[:url.rfind("/")]
- def createNewDir(self, parentDir, name):
- s = self.getNewFile(parentDir, name, "")
- if self.mkdir(s):
- return s
- else:
- return None
-
- def getNewFile(self, parentDir, name, extension):
- i = 0
- temp = True
- while temp:
- filename = self.filename(name, extension, i)
- url = parentDir + "/" + filename
- temp = self.exists(url, True)
- i += 1
- return url
-
- @classmethod
- def filename(self, name, ext, i):
- stringI = ""
- stringExt = ""
- if i != 0:
- stringI = str(i)
- if ext != "":
- stringExt = "." + ext
-
- return name + stringI + stringExt
-
@classmethod
def connectURLs(self, urlFolder, urlFilename):
stringFolder = ""
diff --git a/wizards/com/sun/star/wizards/document/OfficeDocument.py b/wizards/com/sun/star/wizards/document/OfficeDocument.py
index 9c443ef05e66..96148b737868 100644
--- a/wizards/com/sun/star/wizards/document/OfficeDocument.py
+++ b/wizards/com/sun/star/wizards/document/OfficeDocument.py
@@ -277,15 +277,6 @@ class OfficeDocument(object):
"com.sun.star.document.TypeDetection")
return typeDetect.getByName(type)
- '''
- returns the count of slides in a presentation,
- or the count of pages in a draw document.
- @param model a presentation or a draw document
- @return the number of slides/pages in the given document.
- '''
-
- def getSlideCount(self, model):
- return model.getDrawPages().getCount()
def showMessageBox(
self, xMSF, windowServiceName, windowAttribute, MessageText):
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index c084938aa389..f3a1975f6257 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -16,6 +16,7 @@
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
import traceback
+import os.path
from .FaxWizardDialog import FaxWizardDialog, Helper, PropertyNames, uno, HID
from .CGFaxWizard import CGFaxWizard
from .FaxDocument import FaxDocument
@@ -150,7 +151,8 @@ class FaxWizardDialogImpl(FaxWizardDialog):
try:
fileAccess = FileAccess(self.xMSF)
self.sPath = self.myPathSelection.getSelectedPath()
- if not self.sPath:
+ print os.path.exists(self.sPath)
+ if not self.sPath or not os.path.exists(self.sPath):
self.myPathSelection.triggerPathPicker()
self.sPath = self.myPathSelection.getSelectedPath()
@@ -159,15 +161,14 @@ class FaxWizardDialogImpl(FaxWizardDialog):
#it is coming from a saved session, check if the
# file exists and warn the user.
if not self.filenameChanged:
- if fileAccess.exists(self.sPath, True):
- answer = SystemDialog.showMessageBox(
- self.xMSF, "MessBox", YES_NO + DEF_NO,
- self.resources.resOverwriteWarning,
- self.xUnoDialog.Peer)
- if answer == 3:
- # user said: no, do not overwrite...
- endWizard = False
- return False
+ answer = SystemDialog.showMessageBox(
+ self.xMSF, "MessBox", YES_NO + DEF_NO,
+ self.resources.resOverwriteWarning,
+ self.xUnoDialog.Peer)
+ if answer == 3:
+ # user said: no, do not overwrite...
+ endWizard = False
+ return False
self.myFaxDoc.setWizardTemplateDocInfo( \
self.resources.resFaxWizardDialog_title,
diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
index 9e93916aa347..0ea4d122c212 100644
--- a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
@@ -16,6 +16,7 @@
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
import traceback
+import os.path
from .LetterWizardDialog import LetterWizardDialog, Helper, \
PropertyNames, uno, HelpIds, HID
from .LetterDocument import LetterDocument, BusinessPaperObject
@@ -169,13 +170,12 @@ class LetterWizardDialogImpl(LetterWizardDialog):
try:
fileAccess = FileAccess(self.xMSF)
self.sPath = self.myPathSelection.getSelectedPath()
- if not self.sPath:
+ if not self.sPath or not os.path.exists(self.sPath):
self.myPathSelection.triggerPathPicker()
self.sPath = self.myPathSelection.getSelectedPath()
self.sPath = fileAccess.getURL(self.sPath)
if not self.filenameChanged:
- if fileAccess.exists(self.sPath, True):
answer = SystemDialog.showMessageBox(
self.xMSF, "MessBox", YES_NO + DEF_NO,
self.resources.resOverwriteWarning,