Add method post
This commit is contained in:
parent
d787c5e8dc
commit
f3e23f77cf
|
@ -1,3 +1,7 @@
|
||||||
|
v 0.3.0 [23-Apr-2023]
|
||||||
|
---------------------
|
||||||
|
- Add method post
|
||||||
|
|
||||||
v 0.2.0 [23-Sep-2022]
|
v 0.2.0 [23-Sep-2022]
|
||||||
---------------------
|
---------------------
|
||||||
- Add DrawPage.
|
- Add DrawPage.
|
||||||
|
|
|
@ -11,7 +11,6 @@ from .easydrawpage import LOGalleries
|
||||||
def __getattr__(name):
|
def __getattr__(name):
|
||||||
classes = {
|
classes = {
|
||||||
'active': LODocuments().active,
|
'active': LODocuments().active,
|
||||||
'active_sheet': LODocuments().active.active,
|
|
||||||
'clipboard': ClipBoard,
|
'clipboard': ClipBoard,
|
||||||
'cmd': LOMain.commands,
|
'cmd': LOMain.commands,
|
||||||
'color': Color(),
|
'color': Color(),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import uno
|
||||||
import unohelper
|
import unohelper
|
||||||
from com.sun.star.io import IOException, XOutputStream
|
from com.sun.star.io import IOException, XOutputStream
|
||||||
from .easymain import (log,
|
from .easymain import (log,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from .easydoc import LODrawImpress
|
from .easydoc import LODrawImpress
|
||||||
|
from .easydrawpage import LODrawPage
|
||||||
|
|
||||||
|
|
||||||
class LODraw(LODrawImpress):
|
class LODraw(LODrawImpress):
|
||||||
|
@ -8,3 +9,11 @@ class LODraw(LODrawImpress):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
super().__init__(obj)
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
if isinstance(index, int):
|
||||||
|
page = self.obj.DrawPages[index]
|
||||||
|
else:
|
||||||
|
page = self.obj.DrawPages.getByName(index)
|
||||||
|
return LODrawPage(page)
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
from com.sun.star.awt import Size, Point
|
from com.sun.star.awt import Size, Point
|
||||||
|
|
||||||
from .easymain import BaseObject, create_instance, set_properties
|
from .easymain import (
|
||||||
|
BaseObject,
|
||||||
|
create_instance,
|
||||||
|
dict_to_property,
|
||||||
|
set_properties)
|
||||||
from .easyshape import LOShape
|
from .easyshape import LOShape
|
||||||
|
from .easydoc import IOStream
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_WH = 3000
|
DEFAULT_WH = 3000
|
||||||
|
@ -218,19 +223,20 @@ class LODrawPage(BaseObject):
|
||||||
y = args.get('Y', 1000)
|
y = args.get('Y', 1000)
|
||||||
name = args.get('Name', f'image{index}')
|
name = args.get('Name', f'image{index}')
|
||||||
|
|
||||||
image = self.create_instance('com.sun.star.drawing.GraphicObjectShape')
|
image = self._create_instance('com.sun.star.drawing.GraphicObjectShape')
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
image.GraphicURL = _P.to_url(path)
|
image.GraphicURL = _P.to_url(path)
|
||||||
else:
|
else:
|
||||||
gp = create_instance('com.sun.star.graphic.GraphicProvider')
|
gp = create_instance('com.sun.star.graphic.GraphicProvider')
|
||||||
properties = dict_to_property({'InputStream': path})
|
stream = IOStream.input(path)
|
||||||
|
properties = dict_to_property({'InputStream': stream})
|
||||||
image.Graphic = gp.queryGraphic(properties)
|
image.Graphic = gp.queryGraphic(properties)
|
||||||
|
|
||||||
self.obj.add(image)
|
self.obj.add(image)
|
||||||
image.Size = Size(w, h)
|
image.Size = Size(w, h)
|
||||||
image.Position = Point(x, y)
|
image.Position = Point(x, y)
|
||||||
image.Name = name
|
image.Name = name
|
||||||
return LOShape(self.obj[index], index)
|
return LOShape(self.obj[index])
|
||||||
|
|
||||||
|
|
||||||
class LOGalleryItem(BaseObject):
|
class LOGalleryItem(BaseObject):
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import csv
|
||||||
import datetime
|
import datetime
|
||||||
import getpass
|
import getpass
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
@ -144,6 +149,7 @@ day = get_app_config(node, 'DD')
|
||||||
DATE_OFFSET = datetime.date(year, month, day).toordinal()
|
DATE_OFFSET = datetime.date(year, month, day).toordinal()
|
||||||
|
|
||||||
_info_debug = f"Python: {sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
|
_info_debug = f"Python: {sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
|
||||||
|
# ~ doc
|
||||||
INFO_DEBUG = f"{NAME} v{VERSION} {LANGUAGE}\n\n{_info_debug}"
|
INFO_DEBUG = f"{NAME} v{VERSION} {LANGUAGE}\n\n{_info_debug}"
|
||||||
|
|
||||||
|
|
||||||
|
@ -501,16 +507,21 @@ class LOMain():
|
||||||
node = PropertyValue(Name='nodepath', Value=node_name)
|
node = PropertyValue(Name='nodepath', Value=node_name)
|
||||||
update = cp.createInstanceWithArguments(service, (node,))
|
update = cp.createInstanceWithArguments(service, (node,))
|
||||||
|
|
||||||
|
m = create_instance('mytools.Mri')
|
||||||
|
m.inspect(update)
|
||||||
|
|
||||||
result = True
|
result = True
|
||||||
try:
|
try:
|
||||||
if disable:
|
if disable:
|
||||||
new_node = update.createInstanceWithArguments(())
|
new_node = update.createInstanceWithArguments(())
|
||||||
new_node.setPropertyValue('Command', command)
|
new_node.setPropertyValue('Command', command)
|
||||||
update.insertByName(NEW_NODE_NAME, new_node)
|
if not update.hasByName(NEW_NODE_NAME):
|
||||||
|
update.insertByName(NEW_NODE_NAME, new_node)
|
||||||
else:
|
else:
|
||||||
update.removeByName(NEW_NODE_NAME)
|
update.removeByName(NEW_NODE_NAME)
|
||||||
update.commitChanges()
|
update.commitChanges()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -1225,19 +1236,28 @@ class Paths(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def zip(cls, source: Union[str, tuple, list], target: str='') -> str:
|
def zip(cls, source: Union[str, tuple, list], target: str='') -> str:
|
||||||
|
"""Zip files or directories
|
||||||
|
|
||||||
|
:param source: Path source file or directory or list of files.
|
||||||
|
:type source: str or tuple or list
|
||||||
|
:param target: Path target
|
||||||
|
:type target: str
|
||||||
|
:return: Path target
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
path_zip = target
|
path_zip = target
|
||||||
if not isinstance(source, (tuple, list)):
|
if not isinstance(source, (tuple, list)):
|
||||||
path, _, name, _ = _P(source).info
|
path = Paths(source)
|
||||||
start = len(path) + 1
|
start = len(path.path) + 1
|
||||||
if not target:
|
if not target:
|
||||||
path_zip = f'{path}/{name}.zip'
|
path_zip = f'{path.path}/{path.name}.zip'
|
||||||
|
|
||||||
if isinstance(source, (tuple, list)):
|
if isinstance(source, (tuple, list)):
|
||||||
files = [(f, f[len(_P(f).path)+1:]) for f in source]
|
files = [(f, f[len(Paths(f).path)+1:]) for f in source]
|
||||||
elif _P.is_file(source):
|
elif Paths.is_file(source):
|
||||||
files = ((source, source[start:]),)
|
files = ((source, source[start:]),)
|
||||||
else:
|
else:
|
||||||
files = [(f, f[start:]) for f in _P.walk(source)]
|
files = [(f, f[start:]) for f in Paths.walk(source)]
|
||||||
|
|
||||||
compression = zipfile.ZIP_DEFLATED
|
compression = zipfile.ZIP_DEFLATED
|
||||||
with zipfile.ZipFile(path_zip, 'w', compression=compression) as z:
|
with zipfile.ZipFile(path_zip, 'w', compression=compression) as z:
|
||||||
|
@ -1247,9 +1267,20 @@ class Paths(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unzip(cls, source: str, target: str='', members=None, pwd=None):
|
def unzip(cls, source: str, target: str='', members=None, pwd=None):
|
||||||
|
"""Unzip files
|
||||||
|
|
||||||
|
:param source: Path source file zip.
|
||||||
|
:type source: str
|
||||||
|
:param target: Path target folder for extrac content zip.
|
||||||
|
:type target: str
|
||||||
|
:param members: Tuple of files in zip for extract.
|
||||||
|
:type members: tuple
|
||||||
|
:param pwd: Password of zip.
|
||||||
|
:type pwd: str
|
||||||
|
"""
|
||||||
path = target
|
path = target
|
||||||
if not target:
|
if not target:
|
||||||
path = _P(source).path
|
path = Paths(source).path
|
||||||
with zipfile.ZipFile(source) as z:
|
with zipfile.ZipFile(source) as z:
|
||||||
if not pwd is None:
|
if not pwd is None:
|
||||||
pwd = pwd.encode()
|
pwd = pwd.encode()
|
||||||
|
@ -1259,7 +1290,14 @@ class Paths(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def zip_content(cls, path: str):
|
def zip_content(cls, path: str) -> list:
|
||||||
|
"""Get files in zip
|
||||||
|
|
||||||
|
:param path: Path source file zip.
|
||||||
|
:type path: str
|
||||||
|
:return: Content files
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
with zipfile.ZipFile(path) as z:
|
with zipfile.ZipFile(path) as z:
|
||||||
names = z.namelist()
|
names = z.namelist()
|
||||||
return names
|
return names
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import csv
|
import csv
|
||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json as jsonpy
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
|
@ -75,12 +75,14 @@ __all__ = [
|
||||||
'error',
|
'error',
|
||||||
'errorbox',
|
'errorbox',
|
||||||
'info',
|
'info',
|
||||||
|
'question',
|
||||||
'mri',
|
'mri',
|
||||||
'msgbox',
|
'msgbox',
|
||||||
'render',
|
'render',
|
||||||
'save_log',
|
'save_log',
|
||||||
'set_app_config',
|
'set_app_config',
|
||||||
'sleep',
|
'sleep',
|
||||||
|
'warning',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +146,7 @@ def save_log(path: str, data: Any) -> bool:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, 'a') as f:
|
with open(path, 'a') as f:
|
||||||
f.write(f'{str(Dates.now())} - ')
|
f.write(f'{str(Dates.now)} - ')
|
||||||
pprint(data, stream=f)
|
pprint(data, stream=f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(e)
|
error(e)
|
||||||
|
@ -293,7 +295,10 @@ def errorbox(message: Any, title: str=TITLE) -> int:
|
||||||
|
|
||||||
|
|
||||||
def sleep(seconds: int):
|
def sleep(seconds: int):
|
||||||
"""Sleep
|
"""Sleep for seconds
|
||||||
|
|
||||||
|
:param seconds: Seconds for sleep.
|
||||||
|
:type seconds: int
|
||||||
"""
|
"""
|
||||||
time.sleep(seconds)
|
time.sleep(seconds)
|
||||||
return
|
return
|
||||||
|
@ -708,8 +713,7 @@ class Email():
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def send(self, message):
|
def send(self, message):
|
||||||
# ~ file_name = 'attachment; filename={}'
|
email = MIMEMultipart()
|
||||||
email = MIMEMultipart('alternative')
|
|
||||||
email['From'] = self._sender
|
email['From'] = self._sender
|
||||||
email['To'] = message['to']
|
email['To'] = message['to']
|
||||||
email['Cc'] = message.get('cc', '')
|
email['Cc'] = message.get('cc', '')
|
||||||
|
@ -728,7 +732,6 @@ class Email():
|
||||||
paths = (paths,)
|
paths = (paths,)
|
||||||
for path in paths:
|
for path in paths:
|
||||||
fn = Paths(path).file_name
|
fn = Paths(path).file_name
|
||||||
# ~ print('NAME', fn)
|
|
||||||
part = MIMEBase('application', 'octet-stream')
|
part = MIMEBase('application', 'octet-stream')
|
||||||
part.set_payload(Paths.read_bin(path))
|
part.set_payload(Paths.read_bin(path))
|
||||||
encoders.encode_base64(part)
|
encoders.encode_base64(part)
|
||||||
|
@ -788,8 +791,8 @@ class Email():
|
||||||
|
|
||||||
:param server: Configuration for send emails
|
:param server: Configuration for send emails
|
||||||
:type server: dict
|
:type server: dict
|
||||||
:param server: Dictionary con message or list of messages
|
:param messages: Dictionary con message or list of messages
|
||||||
:type server: dict or iterator
|
:type messages: dict or iterator
|
||||||
"""
|
"""
|
||||||
if isinstance(messages, dict):
|
if isinstance(messages, dict):
|
||||||
messages = (messages,)
|
messages = (messages,)
|
||||||
|
@ -1026,13 +1029,22 @@ class Timer(object):
|
||||||
|
|
||||||
class URL(object):
|
class URL(object):
|
||||||
"""Class for simple url open
|
"""Class for simple url open
|
||||||
|
|
||||||
|
`See mureq <https://github.com/slingamn/mureq>`_
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls, url: str, **kwargs):
|
def get(cls, url: str, **kwargs):
|
||||||
return mureq.get(url, **kwargs)
|
return mureq.get(url, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def post(cls, url: str, body=None, **kwargs):
|
def post(cls, url: str, body=None, json=None, **kwargs):
|
||||||
|
if json:
|
||||||
|
body = jsonpy.dumps(json).encode()
|
||||||
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
if 'headers' in kwargs:
|
||||||
|
kwargs['headers'].update(headers)
|
||||||
|
else:
|
||||||
|
kwargs['headers'] = headers
|
||||||
return mureq.post(url, body, **kwargs)
|
return mureq.post(url, body, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
OS = 'Linux'
|
OS = 'Linux'
|
||||||
DESKTOP = 'gnome'
|
DESKTOP = 'gnome'
|
||||||
PC = 'oficina'
|
PC = 'oficina'
|
||||||
USER = 'mau'
|
USER = 'elmau'
|
||||||
IS_WIN = False
|
IS_WIN = False
|
||||||
IS_MAC = False
|
IS_MAC = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue