Commit graph libervia-backend/sat/memory/memory.py
Author SHA1 Message Date
Goffi
d2685ba11b refactoring: renamed sat package to libervia.backend 2023-06-02 11:49:51 +02:00
Goffi
6a6f15707a massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
2023-04-08 13:54:42 +02:00
Goffi
f160577a65 core: fix and renamed getLocalPath -> get_local_path:
- renaming is following global methods renaming to use snake_case
- for reasons lost in the mists of time, a `profile` argument was used while checking if
  `client` is set is enough, and `client.profile` was escaped but actually not used in the
  path.
2022-10-10 15:23:59 +02:00
Goffi
c8df7104eb core (memory): fileDelete is now async, fix coroutine issue 2022-05-16 14:37:58 +02:00
Goffi
c8025a52eb core: method to know if a profile/entity is an admin:
the new `is_admin` SatXMPPEntity property tell if it's an administrator.

Admin JIDs are retrieve on init, so they can be looked after when profle is not available
(notably when a component handle a request and has only a JID available). The new
`memory.isAdminJID` method is then used.
2022-05-15 14:14:52 +02:00
Goffi
8ae38a1131 core (memory/sqla): database migration using Alembic:
Alembic database migration tool, which is the recommended one for SQLAlchemy has been
integrated. When a database is created, it will be used to stamp to current (head)
revision, otherwise, DB will be checked to see if it needs to be updated, and upgrade will
be triggered if necessary.
2021-06-25 17:55:23 +02:00
Goffi
97df5f8be3 core: various changes and fixes to work with new storage and D-Bus bridge:
- fixes coroutines handling in various places
- fixes types which are not serialised by Tx DBus
- XEP-0384: call storage methods in main thread in XEP: Python OMEMO's Promise use thread
  which prevent the use of AsyncIO loop. To work around that, callLater is used to launch
  storage method in main thread. This is a temporary workaround, as Python OMEMO should
  get rid of Promise implementation and threads soon.
2021-06-03 15:21:43 +02:00
Goffi
a5f225e1ea core (memory/storage): backend storage is now based on SQLAlchemy 2021-06-03 15:20:47 +02:00
Goffi
06054ceeaf core (memory, sqlite): new fileGetUsedSpace method 2021-05-05 15:37:21 +02:00
Goffi
18cbbee1a5 memory: new getFilesOwner method:
this method is used by `getFiles` and `setFile` and fill `owner` when it's missing to
avoid getting accidentally files from other users.

`owner` is not filled in some case (no client, `file_id` or `parent` specified) and an
exception is raised if a component has neither `owner` nor `peer_jid` specified.
2021-04-16 18:32:37 +02:00
Goffi
018d09caaa Renamed the project from "Salut à Toi" to "Libervia":
This renaming follows the decision taken at the General Assemblee of January 27th 2021 (cf.
https://repos.goffi.org/sat_docs/raw-file/tip/association/2021-01-27%20-%20compte%20rendu%20de%20l%27AG%20extraordinaire.pdf)
2021-03-20 20:42:04 +01:00
Goffi
dc86957043 date update 2021-03-19 15:45:14 +01:00
Goffi
0250053e19 core (memory/memory): added getCachePath method to get a cache dir from a namespace. 2020-09-28 17:00:14 +02:00
Goffi
f3bb26f9d9 core (memory/memory): public_id should not be used when creating parent dirs 2020-09-17 23:07:12 +02:00
Goffi
280f86881a core (memory/memory): fixed directory creation in setFile 2020-09-17 21:40:23 +02:00
Goffi
a82f7108a2 core (memory/memory): use str for path in getFiles and setFile to allow use of Path instances 2020-09-17 16:34:22 +02:00
Goffi
35920d53af core (memory/memory): fixed assignations 2020-09-05 20:20:05 +02:00
Goffi
ba8496ae36 plugin XEP-0264: only log "fix orientation" when the option is used 2020-08-25 08:52:46 +02:00
Goffi
ea5e0a46f5 core (memory): setFileAccessModel implementation:
this method let change read permission using access model similar to what is used with
Pubsub.
2020-08-01 16:07:39 +02:00
Goffi
97375ee1db core (memory): getFileAffiliations and setFileAffiliations implementations:
those methods allow to change files permissions using affiliations similar to the ones
used with PubSub.
2020-08-01 16:06:12 +02:00
Goffi
800fbd3f7c core (memory): files are now public by default except for those in root directory:
using public permissions by default makes permissions change more easy as we don't have to
recursively change all permissions of sub files when changing directory. Root directories
are private by default.
2020-08-01 16:02:41 +02:00
Goffi
cb49365811 memory: new "affiliation" metadata for files:
this affiliation is similar to pubsub affiliation, for now only `owner` is used.
Affiliation is set when possible (peer_jid is set notably).
2020-07-17 12:58:57 +02:00
Goffi
4e48a889c0 core (memory): fixed recursive file deletion + log an error and continue when deleting a missing file 2020-06-19 14:55:30 +02:00
Goffi
d1521dde4b core (memory/sqlite): new database schema (v9):
this new schema brings the new `public_id` column, which will be used to serve files via
HTTP, splits `mime_type` in 2 (`media_type` and `media_subtype`) to make indexing/media
filtering easier, and fixes indexes for `files` table.
2020-05-29 21:50:49 +02:00
Goffi
a1eb68c1e7 core: replaced sat shell script by a python script:
the backend is now launched by `sat.core.launcher`, and the script is generated during
installation with a new entry point in `setup.py`.
2020-05-25 15:50:01 +02:00
Goffi
88072e0453 core, frontends: avatar refactoring:
/!\ huge commit

Avatar logic has been reworked around the IDENTITY plugin: plugins able to handle avatar
or other identity related metadata (like nicknames) register to IDENTITY plugin in the
same way as for other features like download/upload. Once registered, IDENTITY plugin will
call them when suitable in order of priority, and handle caching.

Methods to manage those metadata from frontend now use serialised data.

For now `avatar` and `nicknames` are handled:

- `avatar` is now a dict with `path` + metadata like `media_type`, instead of just a string
  path
- `nicknames` is now a list of nicknames in order of priority. This list is never empty,
  and `nicknames[0]` should be the preferred nickname to use by frontends in most cases.
  In addition to contact specified nicknames, user set nickname (the one set in roster) is
  used in priority when available.

Among the side changes done with this commit, there are:

- a new `contactGet` bridge method to get roster metadata for a single contact
- SatPresenceProtocol.send returns a Deferred to check when it has actually been sent
- memory's methods to handle entities data now use `client` as first argument
- metadata filter can be specified with `getIdentity`
- `getAvatar` and `setAvatar` are now part of the IDENTITY plugin instead of XEP-0054 (and
  there signature has changed)
- `isRoom` and `getBareOrFull` are now part of XEP-0045 plugin
- jp avatar/get command uses `xdg-open` first when available for `--show` flag
- `--no-cache` has been added to jp avatar/get and identity/get
- jp identity/set has been simplified, explicit options (`--nickname` only for now) are
  used instead of `--field`. `--field` may come back in the future if necessary for extra
  data.
- QuickContactList `SetContact` now handle None as a value, and doesn't use it to delete the
  metadata anymore
- improved cache handling for `metadata` and `nicknames` in quick frontend
- new `default` argument in QuickContactList `getCache`
2020-04-14 21:00:33 +02:00
Goffi
5a467b15d5 core, bridge: new devicesInfosGet method to get infos on known devices of an entity 2020-03-06 18:19:03 +01:00
Goffi
6a7d247754 core: use serialised dict for extra in messageNew and historyGet 2020-02-18 18:13:17 +01:00
Goffi
d684685e24 bridge: added methods to let frontends store/retrieve/delete private data 2020-02-10 22:01:53 +01:00
Goffi
d0741de2ad core (memory/crypto): replaced PyCrypto by cryptography:
`PyCrypto` is unmaintained for years but was used in SàT for password hashing. This patch
fixes that by replacing `PyCrypto` by the reference `cryptography` module which is well
maintained.

The behaviour stays the same (except that previously async `hash`, `encrypt` and `decrypt`
methods are now synchronous, as they are quick and using a deferToThread may actually be
more resource intensive than using blocking methods).

It is planed to improve `memory.crypto` by using more up-to-date cryptography/hashing
algorithms in the future.

PyCrypto is no more a dependency of SàT
2020-02-09 23:50:26 +01:00
Goffi
ec5a51bebb core: log filenames of read config files 2020-01-29 19:42:02 +01:00
Goffi
e1a44cf4e4 fixed shebangs 2020-01-29 10:07:00 +01:00
Goffi
a39349fe64 dates update 2020-01-29 09:50:54 +01:00
Goffi
f496dfc640 core (memory): avoid session locking if profileAuthenticate is called twice quickly 2020-01-27 19:52:49 +01:00
Goffi
87659cf0f0 core (memory/params): added extra argument to filter out params notably in getParamsUI:
In some case, it may be desirable for a frontend to not expose some parameters to user
(e.g. it is the case on Android with the `autoconnect_backend` parameter). An new `extra`
parameter has been added to a couple of parameters method for that: it can contain the
`ignore` key with a list of [category, name] of parameters to skip.
2020-01-25 21:08:40 +01:00
Goffi
f7aad247c2 misc: don't import memory in launch script:
launch script was importing a method from memory (fixLocalDir), but memory is importing
twisted.internet.reactor which can result to a ReactorAlreadyInstalledError.

This patch fixes it by moving fixLocalDir to tools/config.

The launch script is now using /usr/bin/env.
2019-10-08 12:10:26 +02:00
Goffi
76aadbb3fb jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
2019-09-25 08:56:41 +02:00
Goffi
b039dc4572 tools (config), memory: renamed SafeConfigParser following Python 3 port 2019-08-16 17:06:43 +02:00
Goffi
fbfe96c505 Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time

This patch port backend, bridge and frontends to Python 3.

Roughly this has been done this way:

- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
  to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
2019-08-13 19:08:41 +02:00
Goffi
5e43c6c98c core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
an old hardcoded value was used in several places to detect if an entity is a MUC, but this
value was not valid anymore. This has been fixed, and ENTITY_TYPE_MUC constant is now used
instead. This fixes message type autodetection for "groupchat" messages.

fixes 300
2019-07-09 09:06:45 +02:00
Goffi
80da9a6591 core (memory, memory/sqlite): implemented fileDelete 2019-04-28 08:55:13 +02:00
Goffi
cad0d4b0e2 core (memory): raise PermissionError directly instead of using failureFailure, as it could not be catched correctly in every case. 2019-04-28 08:55:13 +02:00
Goffi
a46dda1e12 memory: minor style change 2019-04-26 11:57:26 +02:00
Goffi
5e2426c065 core (memory), plugin XEP-0329, plugin invitation: minor style improvments 2019-04-14 08:21:51 +02:00
Goffi
8e338bf913 date update 2019-01-12 12:25:31 +01:00
Goffi
7a9ee35cfc misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext) 2019-01-11 11:13:15 +01:00
Goffi
a29893ac1f core: minor style/typos fixes 2018-12-01 10:04:17 +01:00
Goffi
744cb0c503 code style reformatting using black 2018-06-27 20:14:46 +02:00
Goffi
4d4d594c60 core: discoFindByFeatures now return only available resources 2018-05-25 10:52:01 +02:00
Goffi
80ef13612b core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor

sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
2018-04-02 19:44:50 +02:00
Renamed from src/memory/memory.py (Browse further)