Kaydet (Commit) 57041602 authored tarafından Xisco Fauli's avatar Xisco Fauli

pywizards: simplify paths handling

Change-Id: I436ca81e180d595e018811823e8b77c8b675bef5
üst ebb26385
...@@ -81,7 +81,8 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): ...@@ -81,7 +81,8 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.agenda.readConfiguration(root, "cp_") self.agenda.readConfiguration(root, "cp_")
self.templateConsts = TemplateConsts self.templateConsts = TemplateConsts
self.initializePaths()
# initialize the agenda template # initialize the agenda template
self.agendaTemplate = AgendaDocument( self.agendaTemplate = AgendaDocument(
self.xMSF, self.agenda, self.resources, self.xMSF, self.agenda, self.resources,
...@@ -103,7 +104,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): ...@@ -103,7 +104,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.topicsControl = TopicsControl(self, self.xMSF, self.agenda) self.topicsControl = TopicsControl(self, self.xMSF, self.agenda)
self.initializePaths()
#special Control for setting the save Path: #special Control for setting the save Path:
self.insertPathSelectionControl() self.insertPathSelectionControl()
...@@ -143,15 +143,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): ...@@ -143,15 +143,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.myPathSelection.sDefaultFilter = "writer8_template" self.myPathSelection.sDefaultFilter = "writer8_template"
self.myPathSelection.addSelectionListener(self) self.myPathSelection.addSelectionListener(self)
def initializePaths(self):
try:
self.sTemplatePath = FileAccess.getOfficePath2(
self.xMSF, "Template", "share", "/wizard")
self.sUserTemplatePath = FileAccess.getOfficePath2(
self.xMSF, "Template", "user", "")
except NoValidPathException:
traceback.print_exc()
''' '''
bind controls to the agenda member (DataAware model) bind controls to the agenda member (DataAware model)
''' '''
...@@ -227,10 +218,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): ...@@ -227,10 +218,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
def initializeTemplates(self): def initializeTemplates(self):
try: try:
self.sTemplatePath = FileAccess.getOfficePath2( sAgendaPath = self.sTemplatePath + "/wizard/agenda"
self.xMSF, "Template", "share", "/wizard")
sAgendaPath = FileAccess.combinePaths(
self.xMSF, self.sTemplatePath, "/wizard/agenda")
self.agendaTemplates = FileAccess.getFolderTitles( self.agendaTemplates = FileAccess.getFolderTitles(
self.xMSF, "aw", sAgendaPath) self.xMSF, "aw", sAgendaPath)
return True return True
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
# the License at http://www.apache.org/licenses/LICENSE-2.0 . # the License at http://www.apache.org/licenses/LICENSE-2.0 .
# #
import traceback import traceback
from .NoValidPathException import NoValidPathException
from com.sun.star.ucb import CommandAbortedException
from com.sun.star.awt.VclWindowPeerAttribute import OK, YES_NO
''' '''
This class delivers static convenience methods This class delivers static convenience methods
...@@ -40,109 +36,6 @@ class FileAccess(object): ...@@ -40,109 +36,6 @@ class FileAccess(object):
self.filenameConverter = xmsf.createInstance( self.filenameConverter = xmsf.createInstance(
"com.sun.star.ucb.FileContentProvider") "com.sun.star.ucb.FileContentProvider")
@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(Helper.getUnoPropertyValue(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 @classmethod
def getFolderTitles(self, xMSF, FilterName, FolderName, resDict=None): def getFolderTitles(self, xMSF, FilterName, FolderName, resDict=None):
#Returns and ordered dict containing the template's name and path #Returns and ordered dict containing the template's name and path
...@@ -221,35 +114,22 @@ class FileAccess(object): ...@@ -221,35 +114,22 @@ class FileAccess(object):
''' '''
return the filename out of a system-dependent path return the filename out of a system-dependent path
@param path
@return
''' '''
@classmethod @classmethod
def getPathFilename(self, path): def getPathFilename(self, path):
return self.getFilename(path, File.separator) return self.getFilename(path, File.separator)
'''
@author rpiterman
@param path
@param pathSeparator
@return
'''
@classmethod @classmethod
def getFilename(self, path, pathSeparator = "/"): def getFilename(self, path, pathSeparator = "/"):
return path.split(pathSeparator)[-1] return path.split(pathSeparator)[-1]
''' '''
@param url
@return the parent dir of the given url.
if the path points to file, gives the directory in which the file is. if the path points to file, gives the directory in which the file is.
''' '''
@classmethod @classmethod
def getParentDir(self, url): def getParentDir(self, url):
while url[-1] == "/":
url = hello[:-1]
return url[:url.rfind("/")] return url[:url.rfind("/")]
@classmethod @classmethod
......
...@@ -59,8 +59,6 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -59,8 +59,6 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.lstPrivateStylePos = None self.lstPrivateStylePos = None
self.bSaveSuccess = False self.bSaveSuccess = False
self.filenameChanged = False self.filenameChanged = False
self.UserTemplatePath = ""
self.sTemplatePath = ""
@classmethod @classmethod
def main(self): def main(self):
...@@ -97,7 +95,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -97,7 +95,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.initializeSalutation() self.initializeSalutation()
self.initializeGreeting() self.initializeGreeting()
self.initializeCommunication() self.initializeCommunication()
self.__initializePaths() self.initializePaths()
#special Control for setting the save Path: #special Control for setting the save Path:
self.insertPathSelectionControl() self.insertPathSelectionControl()
...@@ -251,25 +249,14 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -251,25 +249,14 @@ class FaxWizardDialogImpl(FaxWizardDialog):
5, 97, 70, 205, 45, self.resources.reslblTemplatePath_value, 5, 97, 70, 205, 45, self.resources.reslblTemplatePath_value,
True, HelpIds.getHelpIdString(HID + 34), True, HelpIds.getHelpIdString(HID + 34),
HelpIds.getHelpIdString(HID + 35)) HelpIds.getHelpIdString(HID + 35))
self.myPathSelection.sDefaultDirectory = self.UserTemplatePath self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
self.myPathSelection.sDefaultName = "myFaxTemplate.ott" self.myPathSelection.sDefaultName = "myFaxTemplate.ott"
self.myPathSelection.sDefaultFilter = "writer8_template" self.myPathSelection.sDefaultFilter = "writer8_template"
self.myPathSelection.addSelectionListener(self) self.myPathSelection.addSelectionListener(self)
def __initializePaths(self):
try:
self.sTemplatePath = FileAccess.getOfficePath2(self.xMSF,
"Template", "share", "/wizard")
self.UserTemplatePath = FileAccess.getOfficePath2(self.xMSF,
"Template", "user", "")
except NoValidPathException:
traceback.print_exc()
def initializeTemplates(self, xMSF): def initializeTemplates(self, xMSF):
try: try:
self.sFaxPath = FileAccess.combinePaths(xMSF, self.sTemplatePath, self.sFaxPath = self.sTemplatePath + "/wizard/fax"
"/wizard/fax")
self.sWorkPath = FileAccess.getOfficePath2(xMSF, "Work", "", "")
self.BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus", self.BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus",
self.sFaxPath, self.resources.dictBusinessTemplate) self.sFaxPath, self.resources.dictBusinessTemplate)
self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri", self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri",
......
...@@ -99,7 +99,8 @@ class LetterWizardDialogImpl(LetterWizardDialog): ...@@ -99,7 +99,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
self.buildStep4() self.buildStep4()
self.buildStep5() self.buildStep5()
self.buildStep6() self.buildStep6()
self.__initializePaths()
self.initializePaths()
self.initializeSalutation() self.initializeSalutation()
self.initializeGreeting() self.initializeGreeting()
...@@ -768,19 +769,8 @@ class LetterWizardDialogImpl(LetterWizardDialog): ...@@ -768,19 +769,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
else: else:
return None return None
def __initializePaths(self):
try:
self.sTemplatePath = \
FileAccess.getOfficePath2(
self.xMSF, "Template", "share", "/wizard")
self.sUserTemplatePath = \
FileAccess.getOfficePath2(self.xMSF, "Template", "user", "")
except NoValidPathException:
traceback.print_exc()
def initializeTemplates(self, xMSF): def initializeTemplates(self, xMSF):
sLetterPath = FileAccess.combinePaths( sLetterPath = self.sTemplatePath + "/../common/wizard/letter"
xMSF, self.sTemplatePath, "/../common/wizard/letter")
self.BusinessFiles = \ self.BusinessFiles = \
FileAccess.getFolderTitles( FileAccess.getFolderTitles(
xMSF, "bus", sLetterPath, self.resources.dictBusinessTemplate) xMSF, "bus", sLetterPath, self.resources.dictBusinessTemplate)
......
...@@ -148,7 +148,7 @@ class TextDocument(object): ...@@ -148,7 +148,7 @@ class TextDocument(object):
myFieldHandler = TextFieldHandler(self.xMSF, self.xTextDocument) myFieldHandler = TextFieldHandler(self.xMSF, self.xTextDocument)
myFieldHandler.updateDocInfoFields() myFieldHandler.updateDocInfoFields()
return self.xTextDocument return self.xTextDocument
def getPageSize(self): def getPageSize(self):
try: try:
xNameAccess = self.xTextDocument.StyleFamilies xNameAccess = self.xTextDocument.StyleFamilies
......
...@@ -102,6 +102,15 @@ class WizardDialog(UnoDialog2): ...@@ -102,6 +102,15 @@ class WizardDialog(UnoDialog2):
traceback.print_exc() traceback.print_exc()
return -1 return -1
def initializePaths(self):
xPropertySet = \
self.xMSF.createInstance("com.sun.star.util.PathSettings")
self.sTemplatePath = \
xPropertySet.getPropertyValue("Template_user")[0]
self.sUserTemplatePath = \
xPropertySet.getPropertyValue("Template_writable")
def addRoadmap(self): def addRoadmap(self):
try: try:
iDialogHeight = self.xDialogModel.Height iDialogHeight = self.xDialogModel.Height
...@@ -353,8 +362,6 @@ class WizardDialog(UnoDialog2): ...@@ -353,8 +362,6 @@ class WizardDialog(UnoDialog2):
except Exception: except Exception:
traceback.print_exc() traceback.print_exc()
#TODO discuss with rp
def getNextAvailableStep(self): def getNextAvailableStep(self):
if self.isRoadmapComplete(): if self.isRoadmapComplete():
i = self.nNewStep + 1 i = self.nNewStep + 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment