dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
67 stars 25 forks source link

Absolute Path of .vsdx file #27

Closed mrspelf closed 2 years ago

mrspelf commented 3 years ago

Hi!

I like to open a file with an absolute path location.

from vsdx import VisioFile
filename = PROJECT_PATH+'/FILE.vsdx'
with VisioFile(filename) as vis:
       shape = vis.pages[0].find_shape_by_text('Hello World')
       shape.text.splitlines()[0]
       pass

I get then the following Error: OSError: [Errno 22] Invalid argument: './D:/PROJECT_PATH/FILE/visio/pages/_rels/pages.xml.rels'

OSError                                   Traceback (most recent call last)
<ipython-input-13-0745db2bd44b> in <module>
      9 print(filename)
     10 print(directory)
---> 11 with VisioFile(filename) as vis:
     12 # with VisioFile(filename):
     13     # shape = vis.pages[0].find_shape_by_text('Hello World')

~\AppData\Roaming\Python\Python39\site-packages\vsdx\__init__.py in __init__(self, filename, debug)
     67         self.pages = list()  # type: List[VisioFile.Page]  # list of Page objects, populated by open_vsdx_file()
     68         self.master_pages = list()  # type: List[VisioFile.Page]  # list of Page objects, populated by open_vsdx_file()
---> 69         self.open_vsdx_file()
     70 
     71     def __enter__(self):

~\AppData\Roaming\Python\Python39\site-packages\vsdx\__init__.py in open_vsdx_file(self)
     87 
     88         # load each page file into an ElementTree object
---> 89         self.load_pages()
     90         self.load_master_pages()
     91 

~\AppData\Roaming\Python\Python39\site-packages\vsdx\__init__.py in load_pages(self)
    100 
    101         rel_filename = rel_dir + 'pages.xml.rels'
--> 102         rels = file_to_xml(rel_filename).getroot()  # rels contains page filenames
    103         self.pages_xml_rels = file_to_xml(rel_filename)  # store pages.xml.rels so pages can be added or removed
    104         if self.debug:

~\AppData\Roaming\Python\Python39\site-packages\vsdx\__init__.py in file_to_xml(filename)
   1398     """Import a file as an ElementTree"""
   1399     try:
-> 1400         tree = ET.parse(filename)
   1401         return tree
   1402     except FileNotFoundError:

C:\Program Files\Python39\lib\xml\etree\ElementTree.py in parse(source, parser)
   1227     """
   1228     tree = ElementTree()
-> 1229     tree.parse(source, parser)
   1230     return tree
   1231 

C:\Program Files\Python39\lib\xml\etree\ElementTree.py in parse(self, source, parser)
    567         close_source = False
    568         if not hasattr(source, "read"):
--> 569             source = open(source, "rb")
    570             close_source = True
    571         try:

Can you help me? :-)

Have a nice day and thank you for this great library!

dave-howard commented 3 years ago

Hi mrspelf - thanks for raising this. I have only used relative paths to date, but using absolute paths is a totally valid use case. I will look into updating the package to support that. I'll add a note here when I have made some progress

mrspelf commented 3 years ago

Hi dave, sorry, i used the wrong button. This issue should not be closed yet. But thank you for your reply - I'm looking forward for your reply! :-)

dave-howard commented 2 years ago

Hi msrpelf - with v0.4.12 you should now be able to open/save usoing absolute or relative paths

Please let me know if that works for you, Thanks Dave

mrspelf commented 2 years ago

Dear Dave, it works for me, thank you for implementing and sharing!