Merge branch 'master' of git.dennogumi.org:einar/scripts
This commit is contained in:
		
				commit
				
					
						cf04867735
					
				
			
		
					 3 changed files with 22 additions and 17 deletions
				
			
		|  | @ -9,13 +9,18 @@ from subprocess import call | ||||||
| import shutil | import shutil | ||||||
| from typing import List | from typing import List | ||||||
| 
 | 
 | ||||||
| from atomicwrites import atomic_write, AtomicWriter | from atomicwrites import atomic_write | ||||||
| import frontmatter | import frontmatter | ||||||
| from git import Repo | from git import Repo | ||||||
| import sarge | import pytz | ||||||
| from slugify import slugify | from slugify import slugify | ||||||
|  | import toml | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| POST_PATH = "content/post" | 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: | 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.") |         print("hugo executable not found in PATH.") | ||||||
|         return |         return | ||||||
| 
 | 
 | ||||||
|     cmd = [hugo_cmd, "new", "-k", "posts", "--quiet"] |  | ||||||
|     title = new_post_title(post_title) |     title = new_post_title(post_title) | ||||||
|     path = Path(POST_PATH) / title |     path = Path(POST_PATH) / title | ||||||
|     cmd.append(str(path)) |     shutil.copy(TEMPLATE_PATH, path) | ||||||
|     print(" ".join(cmd)) |  | ||||||
| 
 | 
 | ||||||
|     pid = sarge.run(cmd) |     with open(CONFIG) as handle: | ||||||
|  |         site_config = toml.load(handle) | ||||||
| 
 | 
 | ||||||
|     if pid.returncode != 0: |     featured_image = site_config["params"]["featured_image"] | ||||||
|         return |  | ||||||
| 
 | 
 | ||||||
|     header = frontmatter.load(path) |     header = frontmatter.load(path) | ||||||
| 
 | 
 | ||||||
|  | @ -80,6 +83,10 @@ def create_post(post_title: str, tags: List[str] = None, | ||||||
|     header["draft"] = draft |     header["draft"] = draft | ||||||
|     header["comments"] = comments |     header["comments"] = comments | ||||||
|     header["title"] = post_title |     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) |     frontmatter.dump(header, path) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,7 +10,6 @@ from urllib.parse import quote | ||||||
| 
 | 
 | ||||||
| import git | import git | ||||||
| import requests | import requests | ||||||
| import sarge |  | ||||||
| 
 | 
 | ||||||
| API_URL = "https://invent.kde.org/api/v4/projects/" | API_URL = "https://invent.kde.org/api/v4/projects/" | ||||||
| OBS_URL = "https://api.opensuse.org/trigger/runservice" | 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) |     result = requests.post(OBS_URL, params=parameters, headers=header) | ||||||
| 
 | 
 | ||||||
|     if not result: |     if not result: | ||||||
|         logging.error("Error during service run, package %s, error code %s, url %s", |         logging.error( | ||||||
|                       package_name, result.status_code, result.url) |             "Error during service run, package %s, error code %s, url %s", | ||||||
|  |             package_name, result.status_code, result.url) | ||||||
|         return False |         return False | ||||||
| 
 | 
 | ||||||
|     logging.debug("Package %s complete", package_name) |     logging.debug("Package %s complete", package_name) | ||||||
|  | @ -105,7 +105,6 @@ def update_package(hash_data, package_name, | ||||||
|         return |         return | ||||||
| 
 | 
 | ||||||
|     remote_hash = get_remote_hash(repo_name, branch) |     remote_hash = get_remote_hash(repo_name, branch) | ||||||
|     repo_hashes = hash_data.get(obs_repository) |  | ||||||
| 
 | 
 | ||||||
|     if hash_data.get(obs_repository) is None: |     if hash_data.get(obs_repository) is None: | ||||||
|         logging.debug("No prior data - initializing empty") |         logging.debug("No prior data - initializing empty") | ||||||
|  | @ -155,7 +154,7 @@ def commit_changes(cache_file, repo_home): | ||||||
| 
 | 
 | ||||||
|     repo = git.Repo(repo_home) |     repo = git.Repo(repo_home) | ||||||
|     repo.index.add([cache_file]) |     repo.index.add([cache_file]) | ||||||
|     repo.index.commit("Update caches") |     repo.index.commit("[OBS unstable update bot] Update caches") | ||||||
|     origin = repo.remotes["origin"] |     origin = repo.remotes["origin"] | ||||||
|     origin.pull(rebase=True) |     origin.pull(rebase=True) | ||||||
|     origin.push() |     origin.push() | ||||||
|  |  | ||||||
|  | @ -6,8 +6,6 @@ | ||||||
| 
 | 
 | ||||||
| from enum import Enum | from enum import Enum | ||||||
| import fileinput | import fileinput | ||||||
| import sys |  | ||||||
| import select |  | ||||||
| 
 | 
 | ||||||
| import drymail  # Vendored | import drymail  # Vendored | ||||||
| 
 | 
 | ||||||
|  | @ -44,6 +42,9 @@ def main(): | ||||||
|         elif "unexpected error occurred" in line: |         elif "unexpected error occurred" in line: | ||||||
|             state = State.error |             state = State.error | ||||||
| 
 | 
 | ||||||
|  |     if state is State.no_action: | ||||||
|  |         return | ||||||
|  | 
 | ||||||
|     text = "\n".join(text) |     text = "\n".join(text) | ||||||
|     subject = SUBJECT.format(str(state)) |     subject = SUBJECT.format(str(state)) | ||||||
|     message = drymail.Message( |     message = drymail.Message( | ||||||
|  | @ -54,8 +55,6 @@ def main(): | ||||||
|         text=text |         text=text | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     client = drymail.SMTPMailer( |     client = drymail.SMTPMailer( | ||||||
|         host='localhost') |         host='localhost') | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue