Skip to content

Commit 95bf7eb

Browse files
sadsfaegrafuls
authored andcommitted
fix: small fix for notification templates.
We were incorrectly passing the ../xmlrpc.php service API endpoint to places where we wanted to reference var "wp_wiki" instead. Change-Id: Ic482ef751243f3ed92c43340f680bc424a44be52
1 parent 55d8023 commit 95bf7eb

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

conf/quads.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ircbot_port: 5050
4141
ircbot_channel: #yourchannel
4242

4343
# wordpress wiki
44-
wp_wiki: https://wiki.example.com/xmlrpc.php
44+
wp_wiki: https://wiki.example.com
4545
wp_username: wikiadmin
4646
wp_password: wikipassword
4747
# you will have to know your wordpress page ID for the main and assignment pages

quads/tools/regenerate_vlans_wiki.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33

44
from xmlrpc.client import ProtocolError
5-
from quads.tools.racks_wiki import update_wiki
5+
from quads.tools.wiki import Wiki
66
from quads.config import Config
77
from quads.model import Vlan, Cloud, Schedule
88
from tempfile import NamedTemporaryFile
@@ -78,8 +78,11 @@ def regenerate_vlans_wiki():
7878
render_vlans(_markdown)
7979
_markdown.seek(0)
8080
try:
81-
update_wiki(
82-
wp_url, wp_username, wp_password, page_title, page_id, _markdown.name
81+
wiki = Wiki(
82+
wp_url, wp_username, wp_password
83+
)
84+
wiki.update(
85+
page_title, page_id, _markdown.name
8386
)
8487
except ProtocolError as ex:
8588
logger.error(ex.errmsg)

quads/tools/regenerate_wiki.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from xmlrpc.client import ProtocolError
77
from git import Repo, InvalidGitRepositoryError
88
from quads.config import Config
9-
from quads.tools import create_input, create_input_assignments, racks_wiki
9+
from quads.tools import create_input, create_input_assignments
10+
from quads.tools.wiki import Wiki
1011
from quads.tools.regenerate_vlans_wiki import regenerate_vlans_wiki
1112

1213
wp_wiki = Config["wp_wiki"]
@@ -19,7 +20,6 @@
1920
wp_wiki_git_manage = Config["wp_wiki_git_manage"]
2021
wp_wiki_git_repo_path = Config["wp_wiki_git_repo_path"]
2122

22-
2323
logger = logging.getLogger(__name__)
2424

2525
if __name__ == "__main__":
@@ -40,10 +40,12 @@
4040
repo.remotes.origin.push()
4141

4242
try:
43-
racks_wiki.update_wiki(
43+
wiki = Wiki(
4444
url=wp_wiki,
4545
username=wp_username,
4646
password=wp_password,
47+
)
48+
wiki.update(
4749
_page_title=wp_wiki_main_title,
4850
_page_id=wp_wiki_main_page_id,
4951
_markdown=main_md,
@@ -68,10 +70,8 @@
6870
repo.remotes.origin.push()
6971

7072
try:
71-
racks_wiki.update_wiki(
72-
url=wp_wiki,
73-
username=wp_username,
74-
password=wp_password,
73+
wiki = Wiki(url=wp_wiki, username=wp_username, password=wp_password)
74+
wiki.update(
7575
_page_title=wp_wiki_assignments_title,
7676
_page_id=wp_wiki_assignments_page_id,
7777
_markdown=assignments_md,
Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python3
2+
import os
23

34
from wordpress_xmlrpc import Client, WordPressPage
45
from wordpress_xmlrpc.methods.posts import EditPost
@@ -8,38 +9,49 @@
89
import ssl
910

1011

11-
def update_wiki(url, username, password, _page_title, _page_id, _markdown):
12-
"""
13-
Update an existing wordpress page with generated markdown.
14-
Assumes you have a markdown file with content you want published
15-
to an existing wordpress page.
16-
requires: python-wordpress-xmlrpc or python3-wordpress-xmlrpc
17-
:param url: wordpress xmlrpc endpoint
18-
:param username: wordpress username
19-
:param password: wordpress password
20-
:param _page_title: post page title
21-
:param _page_id: post page id
22-
:param _markdown: path to markdown file for upload
23-
"""
24-
scheme = urlparse(url)[0]
25-
if scheme == "https":
26-
ssl._create_default_https_context = ssl._create_unverified_context
12+
class Wiki:
13+
def __init__(self, url, username, password):
14+
"""
15+
Wiki object initialization
2716
28-
wp = Client(url, username, password)
17+
:param url: wordpress url
18+
:param username: wordpress username
19+
:param password: wordpress password
20+
"""
21+
self.url = url
22+
self.username = username
23+
self.password = password
24+
self.endpoint = os.path.join(self.url, "xmlrpc.php")
2925

30-
# define pages variable
31-
page = WordPressPage()
32-
page.title = _page_title
26+
scheme = urlparse(self.url)[0]
27+
if scheme == "https":
28+
ssl._create_default_https_context = ssl._create_unverified_context
3329

34-
# page id can be found by viewing via wp-admin dashboard in URL
35-
page.id = _page_id
30+
def update(self, _page_title, _page_id, _markdown):
31+
"""
32+
Update an existing wordpress page with generated markdown.
33+
Assumes you have a markdown file with content you want published
34+
to an existing wordpress page.
35+
:param _page_title: post page title
36+
:param _page_id: post page id
37+
:param _markdown: path to markdown file for upload
38+
"""
3639

37-
# set local content file to read handle info into a string
38-
with open(_markdown, "r") as _file:
39-
page.content = _file.read()
40+
wp = Client(self.endpoint, self.username, self.password)
4041

41-
# post new content to the page
42-
wp.call(EditPost(page.id, page))
42+
# define pages variable
43+
page = WordPressPage()
44+
page.title = _page_title
45+
46+
# page id can be found by viewing via wp-admin dashboard in URL
47+
page.id = _page_id
48+
49+
# set local content file to read handle info into a string
50+
with open(_markdown, "r") as _file:
51+
page.content = _file.read()
52+
53+
# post new content to the page
54+
wp.call(EditPost(page.id, page))
4355

4456

4557
if __name__ == "__main__":
@@ -66,7 +78,7 @@ def update_wiki(url, username, password, _page_title, _page_id, _markdown):
6678
dest="wpurl",
6779
type=str,
6880
default=None,
69-
help="Specify wordpress URL. e.g. http://wiki.example.com/xmlrpc.php",
81+
help="Specify wordpress URL. e.g. http://wiki.example.com",
7082
required=True,
7183
)
7284
parser.add_argument(
@@ -103,4 +115,5 @@ def update_wiki(url, username, password, _page_title, _page_id, _markdown):
103115
page_title = args.pagetitle
104116
page_id = args.pageid
105117

106-
update_wiki(wp_url, wp_username, wp_password, page_title, page_id)
118+
wiki = Wiki(wp_url, wp_username, wp_password)
119+
wiki.update(page_title, page_id, markdown)

0 commit comments

Comments
 (0)