Add examples for paths
This commit is contained in:
parent
20fbd98157
commit
b58b1ad093
|
@ -26,6 +26,7 @@ You can used **easymacro.py** with any extension or directly in your macros.
|
|||
|
||||
tools_for_debug.rst
|
||||
tools.rst
|
||||
paths.rst
|
||||
email.rst
|
||||
application.rst
|
||||
calc.rst
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
|
||||
Paths and files
|
||||
---------------
|
||||
|
||||
Remember, always import library.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import easymacro as app
|
||||
|
||||
|
||||
Get info path
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/myfile.ods'
|
||||
p = app.paths(path)
|
||||
|
||||
app.debug(p.path)
|
||||
app.debug(p.file_name)
|
||||
app.debug(p.name)
|
||||
app.debug(p.ext)
|
||||
app.debug(p.size)
|
||||
app.debug(p.url)
|
||||
|
||||
Or get information in a tuple
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/myfile.ods'
|
||||
p = app.paths(path)
|
||||
|
||||
app.msgbox(p.info)
|
||||
|
||||
|
||||
Exists path
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/test'
|
||||
app.msgbox(app.paths.exists(path))
|
||||
|
||||
|
||||
Path is file
|
||||
^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/myfile.ott'
|
||||
app.msgbox(app.paths.is_file(path))
|
||||
|
||||
|
||||
Path is dir
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau'
|
||||
app.msgbox(app.paths.is_dir(path))
|
||||
|
||||
|
||||
Get path home
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.home
|
||||
app.msgbox(path)
|
||||
|
||||
|
||||
Get path documents
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* Configurate in LibreOffice Paths
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.documents
|
||||
app.msgbox(path)
|
||||
|
||||
|
||||
Get path temp
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.temp_dir
|
||||
app.msgbox(path)
|
||||
|
||||
|
||||
Get path from LibreOffice configuration
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* Default get path documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.config()
|
||||
app.msgbox(path)
|
||||
|
||||
* All options in `API XPathSettings`_
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.config('Config')
|
||||
app.msgbox(path)
|
||||
|
||||
|
||||
Get path executable python
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path_python = app.paths.python
|
||||
app.msgbox(path_python)
|
||||
|
||||
|
||||
Save text data
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
* Default encoding is UTF8
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
data = """“Do you want to know who you are? Don't ask. Act!
|
||||
Action will delineate and define you.”
|
||||
|
||||
Thomas Jefferson
|
||||
"""
|
||||
|
||||
path = '/home/mau/temp.txt'
|
||||
app.paths.save(path, data)
|
||||
|
||||
* Change encoding
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
app.paths.save(path, data, 'iso-8859-1')
|
||||
|
||||
|
||||
Save binary data
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
data = b'Binary data'
|
||||
path = '/home/mau/temp.bin'
|
||||
app.paths.save_bin(path, data)
|
||||
|
||||
|
||||
Join paths
|
||||
^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path_home = app.paths.home
|
||||
file_name = 'test.ods'
|
||||
path = app.paths.join(path_home, file_name)
|
||||
|
||||
app.msgbox(path)
|
||||
|
||||
|
||||
Get a temporal path
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path_temp = app.paths.tmp()
|
||||
app.msgbox(path_temp)
|
||||
|
||||
* Get with extension.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path_temp = app.paths.tmp('.txt')
|
||||
app.msgbox(path_temp)
|
||||
|
||||
* Save data in a temporal path
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
data = """He who receives an idea from me,
|
||||
receives instruction himself without lessening mine;
|
||||
as he who lights his taper at mine,
|
||||
receives light without darkening me.
|
||||
|
||||
Thomas Jefferson
|
||||
"""
|
||||
path_tmp = app.paths.save_tmp(data)
|
||||
|
||||
app.msgbox(path_tmp)
|
||||
|
||||
|
||||
Get a temporal dir
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* All content and directory is deleted when exit context.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
data = """Do you want to know who you are? Don't ask. Act!
|
||||
Action will delineate and define you.
|
||||
|
||||
Thomas Jefferson
|
||||
"""
|
||||
|
||||
with app.paths.dir_tmp() as dt:
|
||||
app.debug(app.paths.exists(dt))
|
||||
path = app.paths.join(dt, 'test.txt')
|
||||
app.paths.save(path, data)
|
||||
|
||||
app.debug(app.paths.exists(dt))
|
||||
|
||||
|
||||
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html
|
|
@ -139,53 +139,6 @@ InputBox
|
|||
app.msgbox(result)
|
||||
|
||||
|
||||
Paths and files
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
* Get info path
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/myfile.ods'
|
||||
p = app.paths(path)
|
||||
|
||||
app.debug(p.path)
|
||||
app.debug(p.file_name)
|
||||
app.debug(p.name)
|
||||
app.debug(p.ext)
|
||||
app.debug(p.url)
|
||||
|
||||
Or get information in a tuple
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/myfile.ods'
|
||||
p = app.paths(path)
|
||||
|
||||
app.debug(p.info)
|
||||
|
||||
* Get path home
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.home
|
||||
app.debug(path)
|
||||
|
||||
* Get path documents
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.documents
|
||||
app.debug(path)
|
||||
|
||||
* Get path temp
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
path = app.paths.temp_dir
|
||||
app.debug(path)
|
||||
|
||||
|
||||
Date and times
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
|
|
Loading…
Reference in New Issue