Fix in copy method

This commit is contained in:
Mauricio Baeza 2021-06-28 22:59:16 -05:00
parent 33c2b18c33
commit 80691ad797
9 changed files with 265 additions and 11 deletions

View File

@ -18,10 +18,12 @@ LibreOffice SDK 7.0+
#### but, don't make the mistake of many of *thinking only in gratis software* that so much damage has done to **Free Software**.
This extension have a cost of maintenance of 10 euros every year.
This extension have a cost of maintenance of 1 euros every year.
BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d`
MONERO: `48ygK6NuuNAfwWfeAbeK8YP2ryPqxMAsUZBnfAhaHVkoHZ48JRYiQKKFd5GFMmaytyUpfxnyA95pWavjRgPUuKv1TUTvhkd`
BTC: `3FhiXcXmAesmQzrNEngjHFnvaJRhU1AGWV`
ETH: `0x61a4f614a30ff686445751ed8328b82b77ecfc69`
@ -33,8 +35,6 @@ You have others cryptos, welcome too!
## Extensions develop with ZAZ
* https://gitlab.com/mauriciobaeza/zaz-barcode
* https://gitlab.com/mauriciobaeza/zaz-favorite
* https://gitlab.com/mauriciobaeza/zaz-easymacro
* https://gitlab.com/mauriciobaeza/zaz-pip
* https://gitlab.com/mauriciobaeza/zaz-inspect
* https://git.cuates.net/elmau/zaz-pip
* https://git.cuates.net/elmau/zaz-favorites
* https://git.cuates.net/elmau/zaz-functions

Binary file not shown.

Binary file not shown.

View File

@ -432,7 +432,7 @@ This method use `os.walk`
app.debug(f)
Get install path from id extension
Get install path extension from id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
@ -446,4 +446,90 @@ Get install path from id extension
24/06/2021 21:47:29 - DEBUG - /home/mau/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu20665x29msz.tmp_/ZAZEasyMacro_v0.1.0.oxt
Verify if application exists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
app_name = 'nosoffice'
app.msgbox(app.paths.exists_app(app_name))
app_name = 'soffice'
app.msgbox(app.paths.exists_app(app_name))
Open any type file
^^^^^^^^^^^^^^^^^^
Open with default application in OS.
.. code-block:: python
path = '/home/mau/Downloads/file.pdf'
app.paths.open(path)
path = '/home/mau/Projects/libre_office/zaz/doc/build/index.html'
app.paths.open(path)
Save and read json
^^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/data.json'
data = {
'type': 'calc',
'name': 'myfile.ods',
}
app.paths.to_json(path, data)
data = app.paths.from_json(path)
app.msgbox(data)
Save and read csv
^^^^^^^^^^^^^^^^^
You can used the same way that `python csv`_
.. code-block:: python
path = '/home/mau/data.csv'
data = (
(1, 'one', app.now()),
(2, 'two', app.now()),
(3, 'three', app.now()),
)
app.paths.to_csv(path, data)
data = app.paths.from_csv(path)
app.msgbox(data)
Copy files
^^^^^^^^^^
Copy with the same name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
path_new = app.paths.copy(path, target)
app.msgbox(path_new)
Copy with other name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
new_name = 'other_name.png'
path_new = app.paths.copy(path, target, name)
app.msgbox(path_new)
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html
.. _python csv: https://docs.python.org/3.7/library/csv.html

View File

@ -105,7 +105,12 @@
<li class="toctree-l2"><a class="reference internal" href="paths.html#delete-files-and-directories">Delete files and directories</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-files">Get files</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-directories">Get directories</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-install-path-from-id-extension">Get install path from id extension</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-install-path-extension-from-id">Get install path extension from id</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#verify-if-application-exists">Verify if application exists</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#open-any-type-file">Open any type file</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#save-and-read-json">Save and read json</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#save-and-read-csv">Save and read csv</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#copy-files">Copy files</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="email.html">Email</a><ul>

View File

@ -420,8 +420,8 @@
</pre></div>
</div>
</section>
<section id="get-install-path-from-id-extension">
<h2>Get install path from id extension<a class="headerlink" href="#get-install-path-from-id-extension" title="Permalink to this headline"></a></h2>
<section id="get-install-path-extension-from-id">
<h2>Get install path extension from id<a class="headerlink" href="#get-install-path-extension-from-id" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">id_ext</span> <span class="o">=</span> <span class="s1">&#39;net.elmau.zaz.EasyMacro&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_id</span><span class="p">(</span><span class="n">id_ext</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
@ -431,6 +431,77 @@
</pre></div>
</div>
</section>
<section id="verify-if-application-exists">
<h2>Verify if application exists<a class="headerlink" href="#verify-if-application-exists" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app_name</span> <span class="o">=</span> <span class="s1">&#39;nosoffice&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">exists_app</span><span class="p">(</span><span class="n">app_name</span><span class="p">))</span>
<span class="n">app_name</span> <span class="o">=</span> <span class="s1">&#39;soffice&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">exists_app</span><span class="p">(</span><span class="n">app_name</span><span class="p">))</span>
</pre></div>
</div>
</section>
<section id="open-any-type-file">
<h2>Open any type file<a class="headerlink" href="#open-any-type-file" title="Permalink to this headline"></a></h2>
<p>Open with default application in OS.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Downloads/file.pdf&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Projects/libre_office/zaz/doc/build/index.html&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="save-and-read-json">
<h2>Save and read json<a class="headerlink" href="#save-and-read-json" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/data.json&#39;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;calc&#39;</span><span class="p">,</span>
<span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;myfile.ods&#39;</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">to_json</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_json</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="save-and-read-csv">
<h2>Save and read csv<a class="headerlink" href="#save-and-read-csv" title="Permalink to this headline"></a></h2>
<p>You can used the same way that <a class="reference external" href="https://docs.python.org/3.7/library/csv.html">python csv</a></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/data.csv&#39;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;two&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;three&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_csv</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="copy-files">
<h2>Copy files<a class="headerlink" href="#copy-files" title="Permalink to this headline"></a></h2>
<p>Copy with the same name</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/image.png&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Pictures&#39;</span>
<span class="n">path_new</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">path_new</span><span class="p">)</span>
</pre></div>
</div>
<p>Copy with other name</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/image.png&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Pictures&#39;</span>
<span class="n">new_name</span> <span class="o">=</span> <span class="s1">&#39;other_name.png&#39;</span>
<span class="n">path_new</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">path_new</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>

File diff suppressed because one or more lines are too long

View File

@ -446,4 +446,90 @@ Get install path extension from id
24/06/2021 21:47:29 - DEBUG - /home/mau/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu20665x29msz.tmp_/ZAZEasyMacro_v0.1.0.oxt
Verify if application exists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
app_name = 'nosoffice'
app.msgbox(app.paths.exists_app(app_name))
app_name = 'soffice'
app.msgbox(app.paths.exists_app(app_name))
Open any type file
^^^^^^^^^^^^^^^^^^
Open with default application in OS.
.. code-block:: python
path = '/home/mau/Downloads/file.pdf'
app.paths.open(path)
path = '/home/mau/Projects/libre_office/zaz/doc/build/index.html'
app.paths.open(path)
Save and read json
^^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/data.json'
data = {
'type': 'calc',
'name': 'myfile.ods',
}
app.paths.to_json(path, data)
data = app.paths.from_json(path)
app.msgbox(data)
Save and read csv
^^^^^^^^^^^^^^^^^
You can used the same way that `python csv`_
.. code-block:: python
path = '/home/mau/data.csv'
data = (
(1, 'one', app.now()),
(2, 'two', app.now()),
(3, 'three', app.now()),
)
app.paths.to_csv(path, data)
data = app.paths.from_csv(path)
app.msgbox(data)
Copy files
^^^^^^^^^^
Copy with the same name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
path_new = app.paths.copy(path, target)
app.msgbox(path_new)
Copy with other name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
new_name = 'other_name.png'
path_new = app.paths.copy(path, target, name)
app.msgbox(path_new)
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html
.. _python csv: https://docs.python.org/3.7/library/csv.html

View File

@ -6600,6 +6600,11 @@ class Paths(object):
@classmethod
def image(cls, path):
# ~ sfa = create_instance('com.sun.star.ucb.SimpleFileAccess')
# ~ stream = sfa.openFileRead(cls.to_url(path))
# ~ debug(type(stream), stream)
# ~ Name = "InputStream"
# ~ Value = stream
gp = create_instance('com.sun.star.graphic.GraphicProvider')
image = gp.queryGraphic((
PropertyValue(Name='URL', Value=cls.to_url(path)),
@ -6611,6 +6616,7 @@ class Paths(object):
p, f, n, e = _P(source).info
if target:
p = target
e = f'.{e}'
if name:
e = ''
n = name