1
0
Fork 0

Merge branch 'master' of git.dennogumi.org:einar/scripts

This commit is contained in:
Luca Beltrame 2021-08-29 16:56:53 +02:00
commit cf04867735
3 changed files with 22 additions and 17 deletions

View file

@ -9,13 +9,18 @@ from subprocess import call
import shutil
from typing import List
from atomicwrites import atomic_write, AtomicWriter
from atomicwrites import atomic_write
import frontmatter
from git import Repo
import sarge
import pytz
from slugify import slugify
import toml
POST_PATH = "content/post"
TEMPLATE_PATH = "archetypes/post.blank.md"
CONFIG = "config.toml"
TIMEZONE = pytz.timezone("Europe/Rome")
def new_post_title(title: str) -> str:
@ -59,16 +64,14 @@ def create_post(post_title: str, tags: List[str] = None,
print("hugo executable not found in PATH.")
return
cmd = [hugo_cmd, "new", "-k", "posts", "--quiet"]
title = new_post_title(post_title)
path = Path(POST_PATH) / title
cmd.append(str(path))
print(" ".join(cmd))
shutil.copy(TEMPLATE_PATH, path)
pid = sarge.run(cmd)
with open(CONFIG) as handle:
site_config = toml.load(handle)
if pid.returncode != 0:
return
featured_image = site_config["params"]["featured_image"]
header = frontmatter.load(path)
@ -80,6 +83,10 @@ def create_post(post_title: str, tags: List[str] = None,
header["draft"] = draft
header["comments"] = comments
header["title"] = post_title
header["featured_image"] = featured_image
date = datetime.now(tz=TIMEZONE)
# '2021-01-09 02:14:57+01:00'
header["date"] = date.isoformat(timespec="seconds", sep=" ")
frontmatter.dump(header, path)

View file

@ -10,7 +10,6 @@ from urllib.parse import quote
import git
import requests
import sarge
API_URL = "https://invent.kde.org/api/v4/projects/"
OBS_URL = "https://api.opensuse.org/trigger/runservice"
@ -86,8 +85,9 @@ def trigger_update(repository, package_name, token):
result = requests.post(OBS_URL, params=parameters, headers=header)
if not result:
logging.error("Error during service run, package %s, error code %s, url %s",
package_name, result.status_code, result.url)
logging.error(
"Error during service run, package %s, error code %s, url %s",
package_name, result.status_code, result.url)
return False
logging.debug("Package %s complete", package_name)
@ -105,7 +105,6 @@ def update_package(hash_data, package_name,
return
remote_hash = get_remote_hash(repo_name, branch)
repo_hashes = hash_data.get(obs_repository)
if hash_data.get(obs_repository) is None:
logging.debug("No prior data - initializing empty")
@ -155,7 +154,7 @@ def commit_changes(cache_file, repo_home):
repo = git.Repo(repo_home)
repo.index.add([cache_file])
repo.index.commit("Update caches")
repo.index.commit("[OBS unstable update bot] Update caches")
origin = repo.remotes["origin"]
origin.pull(rebase=True)
origin.push()

View file

@ -6,8 +6,6 @@
from enum import Enum
import fileinput
import sys
import select
import drymail # Vendored
@ -44,6 +42,9 @@ def main():
elif "unexpected error occurred" in line:
state = State.error
if state is State.no_action:
return
text = "\n".join(text)
subject = SUBJECT.format(str(state))
message = drymail.Message(
@ -54,8 +55,6 @@ def main():
text=text
)
client = drymail.SMTPMailer(
host='localhost')