platzky 0.2.17__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
platzky/plugin_loader.py CHANGED
@@ -1,8 +1,5 @@
1
1
  import importlib.util
2
2
  import logging
3
- import os
4
- import sys
5
- from os.path import abspath, dirname
6
3
 
7
4
  logger = logging.getLogger(__name__)
8
5
 
@@ -11,26 +8,7 @@ class PluginError(Exception):
11
8
  pass
12
9
 
13
10
 
14
- # TODO remove find_local_plugin after all plugins will be extracted
15
- def find_local_plugin(plugin_name):
16
- """Find plugin by name and return it as module.
17
- :param plugin_name: name of plugin to find
18
- :return: module of plugin
19
- """
20
- plugins_dir = os.path.join(dirname(abspath(__file__)), "plugins")
21
- module_name = plugin_name.removesuffix(".py")
22
- spec = importlib.util.spec_from_file_location(
23
- module_name, os.path.join(plugins_dir, plugin_name, "entrypoint.py")
24
- )
25
- assert spec is not None
26
- plugin = importlib.util.module_from_spec(spec)
27
- sys.modules[module_name] = plugin
28
- assert spec.loader is not None
29
- spec.loader.exec_module(plugin)
30
- return plugin
31
-
32
-
33
- def find_installed_plugin(plugin_name):
11
+ def find_plugin(plugin_name):
34
12
  """Find plugin by name and return it as module.
35
13
  :param plugin_name: name of plugin to find
36
14
  :raises PluginError: if plugin cannot be imported
@@ -45,22 +23,6 @@ def find_installed_plugin(plugin_name):
45
23
  ) from e
46
24
 
47
25
 
48
- def find_plugin(plugin_name):
49
- """Find plugin by name and return it as module.
50
- :param plugin_name: name of plugin to find
51
- :raises PluginError: if plugin cannot be found or imported
52
- :return: module of plugin
53
- """
54
- plugin = None
55
- try:
56
- plugin = find_local_plugin(plugin_name)
57
- except FileNotFoundError:
58
- logger.info(f"Local plugin {plugin_name} not found, trying installed version")
59
- plugin = find_installed_plugin(plugin_name)
60
-
61
- return plugin
62
-
63
-
64
26
  def plugify(app):
65
27
  """Load plugins and run their entrypoints.
66
28
  :param app: Flask app
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: platzky
3
- Version: 0.2.17
3
+ Version: 0.3.0
4
4
  Summary: Not only blog engine
5
5
  License: MIT
6
6
  Requires-Python: >=3.10,<4.0
@@ -14,10 +14,7 @@ platzky/locale/en/LC_MESSAGES/messages.po,sha256=WaZGlFAegKRq7CSz69dWKic-mKvQFhV
14
14
  platzky/locale/pl/LC_MESSAGES/messages.po,sha256=sUPxMKDeEOoZ5UIg94rGxZD06YVWiAMWIby2XE51Hrc,1624
15
15
  platzky/models.py,sha256=-IIlyeLzACeTUpzuzvzJYxtT57E6wRiERoRgXJYMMtY,1502
16
16
  platzky/platzky.py,sha256=A_ku8ZFseCde12vXL9PLNn9ybMszXDcBIqZbWj1rxMo,4996
17
- platzky/plugin_loader.py,sha256=kYLaBOc8MA4b0T2yhVpSxZsX1rTxfcAnyGJCNKPGBXY,2428
18
- platzky/plugins/google-tag-manager/entrypoint.py,sha256=Z4npXtmCdrSuUG_ZvFdPhUZg5QcwIPGQWj9Uw9dcm8A,1021
19
- platzky/plugins/redirections/entrypoint.py,sha256=yoqHsRLqRALdICs5_UMSREkfEo1Lbsjj9tqEA7dsseg,1555
20
- platzky/plugins/sendmail/entrypoint.py,sha256=16GszfLaYhVUSuCdL4SPVKYN9-mONp-hK5ZWSiLluPo,1215
17
+ platzky/plugin_loader.py,sha256=TkeBYa4DrkUZ2lSJtIY5YKJEgtJvOCiXHhav_K8RaWs,1162
21
18
  platzky/seo/seo.py,sha256=N_MmAA4KJZmmrDUh0hYNtD8ycOwpNKow4gVSAv8V3N4,2631
22
19
  platzky/static/blog.css,sha256=TrppzgQbj4UtuTufDCdblyNTVAqgIbhD66Cziyv_xnY,7893
23
20
  platzky/static/styles.css,sha256=U5ddGIK-VcGRJZ3BdOpMp0pR__k6rNEMsuQXkP4tFQ0,686
@@ -33,6 +30,6 @@ platzky/templates/post.html,sha256=GSgjIZsOQKtNx3cEbquSjZ5L4whPnG6MzRyoq9k4B8Q,1
33
30
  platzky/templates/robots.txt,sha256=2_j2tiYtYJnzZUrANiX9pvBxyw5Dp27fR_co18BPEJ0,116
34
31
  platzky/templates/sitemap.xml,sha256=iIJZ91_B5ZuNLCHsRtsGKZlBAXojOTP8kffqKLacgvs,578
35
32
  platzky/www_handler.py,sha256=pF6Rmvem1sdVqHD7z3RLrDuG-CwAqfGCti50_NPsB2w,725
36
- platzky-0.2.17.dist-info/METADATA,sha256=vY11shggzwZqaPt6-6Cize6KyLhL4T2yjftJXz-LstM,1643
37
- platzky-0.2.17.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
38
- platzky-0.2.17.dist-info/RECORD,,
33
+ platzky-0.3.0.dist-info/METADATA,sha256=EhwOCjLEsHFcLEyM-IQasGVn8VKRX1_ZIeht_vAuE38,1642
34
+ platzky-0.3.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
35
+ platzky-0.3.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.0.1
2
+ Generator: poetry-core 2.1.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,30 +0,0 @@
1
- def process(app, plugin_config):
2
- gtm_id = plugin_config["ID"]
3
-
4
- head_code = (
5
- """<!-- Google Tag Manager -->
6
- <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
7
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
8
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
9
- 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
10
- })(window,document,'script','dataLayer','"""
11
- + gtm_id
12
- + """');</script>
13
- <!-- End Google Tag Manager -->
14
- """
15
- )
16
- app.add_dynamic_head(head_code)
17
-
18
- body = (
19
- """<!-- Google Tag Manager (noscript) -->
20
- <noscript><iframe src="https://www.googletagmanager.com/ns.html?id="""
21
- + gtm_id
22
- + """
23
- "
24
- height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
25
- <!-- End Google Tag Manager (noscript) -->
26
- """
27
- )
28
- app.add_dynamic_body(body)
29
-
30
- return app
@@ -1,64 +0,0 @@
1
- from flask import redirect
2
- from gql import gql
3
- from pydantic import BaseModel
4
-
5
-
6
- def json_db_get_redirections(self):
7
- return self.data.get("redirections", {})
8
-
9
-
10
- def json_file_db_get_redirections(self):
11
- return json_db_get_redirections(self)
12
-
13
-
14
- def google_json_db_get_redirections(self):
15
- return self.data.get("redirections", {})
16
-
17
-
18
- def graph_ql_db_get_redirections(self):
19
- redirections = gql(
20
- """
21
- query MyQuery{
22
- redirections(stage: PUBLISHED){
23
- source
24
- destination
25
- }
26
- }
27
- """
28
- )
29
- return {
30
- x["source"]: x["destination"] for x in self.client.execute(redirections)["redirections"]
31
- }
32
-
33
-
34
- class Redirection(BaseModel):
35
- source: str
36
- destiny: str
37
-
38
-
39
- def parse_redirections(config: dict[str, str]) -> list[Redirection]:
40
- return [Redirection(source=source, destiny=destiny) for source, destiny in config.items()]
41
-
42
-
43
- def setup_routes(app, redirections):
44
- for redirection in redirections:
45
- func = redirect_with_name(
46
- redirection.destiny,
47
- code=301,
48
- name=f"{redirection.source}-{redirection.destiny}",
49
- )
50
- app.route(rule=redirection.source)(func)
51
-
52
-
53
- def redirect_with_name(destiny, code, name):
54
- def named_redirect(*args, **kwargs):
55
- return redirect(destiny, code, *args, **kwargs)
56
-
57
- named_redirect.__name__ = name
58
- return named_redirect
59
-
60
-
61
- def process(app, config: dict[str, str]) -> object:
62
- redirections = parse_redirections(config)
63
- setup_routes(app, redirections)
64
- return app
@@ -1,39 +0,0 @@
1
- import smtplib
2
-
3
- from pydantic import BaseModel, Field
4
-
5
-
6
- def send_mail(sender_email, password, smtp_server, port, receiver_email, subject, message):
7
- full_message = f"From: {sender_email}\nTo: {receiver_email}\nSubject: {subject}\n\n{message}"
8
- server = smtplib.SMTP_SSL(smtp_server, port)
9
- server.ehlo()
10
- server.login(sender_email, password)
11
- server.sendmail(sender_email, receiver_email, full_message)
12
- server.close()
13
-
14
-
15
- class SendMailConfig(BaseModel):
16
- user: str = Field(alias="sender_email")
17
- password: str = Field(alias="password")
18
- server: str = Field(alias="smtp_server")
19
- port: int = Field(alias="port")
20
- receiver: str = Field(alias="receiver_email")
21
- subject: str = Field(alias="subject")
22
-
23
-
24
- def process(app, config):
25
- plugin_config = SendMailConfig.model_validate(config)
26
-
27
- def notify(message):
28
- send_mail(
29
- sender_email=plugin_config.user,
30
- password=plugin_config.password,
31
- smtp_server=plugin_config.server,
32
- port=plugin_config.port,
33
- receiver_email=plugin_config.receiver,
34
- subject=plugin_config.subject,
35
- message=message,
36
- )
37
-
38
- app.add_notifier(notify)
39
- return app