Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cp-templates/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
action="store_true",
help="Show debugging statements (prints to stderr)",
)
parser.add_argument("input", nargs="?", type=argparse.FileType("r"), default="-")
parser.add_argument("input", nargs="?", default="-")

opts = parser.parse_args()
stream = opts.input # input stream
stream = sys.stdin if opts.input == "-" else open(opts.input) # input stream


def debug(*args: Any):
Expand Down
8 changes: 4 additions & 4 deletions py-scripts/cal2discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from calendar import TextCalendar
from typing import Any, List, Tuple

import humanize
import humanize # ty: ignore[unresolved-import]
import pytz
import recurring_ical_events
import recurring_ical_events # ty: ignore[unresolved-import]
import requests
import yaml
from discord_webhook import DiscordEmbed, DiscordWebhook
from icalendar import Calendar, Event
from discord_webhook import DiscordEmbed, DiscordWebhook # ty: ignore[unresolved-import]
from icalendar import Calendar, Event # ty: ignore[unresolved-import]

parser = argparse.ArgumentParser()
parser.add_argument("config")
Expand Down
32 changes: 25 additions & 7 deletions py-scripts/demacro.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import subprocess
import sys
from pathlib import Path

TMP = "/tmp/demacro"
os.system("mkdir -p %s" % TMP)
os.makedirs(TMP, exist_ok=True)

arg = sys.argv[1]
if ".tex" in arg:
Expand Down Expand Up @@ -35,13 +37,29 @@
print(line.strip(), file=g)
elif doc_started:
print(line.strip(), file=g)
os.system("cp -f *.tex " + TMP)
os.system("cp -f ~/dotfiles/py-scripts/demacro-private.sty " + TMP)
subprocess.run("cp -f *.tex " + TMP, shell=True, check=True)
subprocess.run(
["cp", "-f", Path("~/dotfiles/py-scripts/demacro-private.sty").expanduser(), TMP],
check=True,
)
with open("%s/demacro-private.sty" % TMP, "a") as f:
print("\n" + preamble, file=f)
os.chdir(TMP)
os.system("~/dotfiles/py-scripts/de-macro source.tex")
os.system("python3 ~/dotfiles/py-scripts/latex2wp.py source-clean.tex")
subprocess.run(
[Path("~/dotfiles/py-scripts/de-macro").expanduser(), "source.tex"], check=True
)
subprocess.run(
[
"python3",
Path("~/dotfiles/py-scripts/latex2wp.py").expanduser(),
"source-clean.tex",
],
check=True,
)
os.chdir(current_dir)
os.system("cp -f %s/source-clean.html %s.html" % (TMP, file_root_name))
os.system("cp -f %s/source-clean.tex %s.clean" % (TMP, file_root_name))
subprocess.run(
["cp", "-f", "%s/source-clean.html" % TMP, "%s.html" % file_root_name], check=True
)
subprocess.run(
["cp", "-f", "%s/source-clean.tex" % TMP, "%s.clean" % file_root_name], check=True
)
4 changes: 2 additions & 2 deletions py-scripts/orch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
OTIS_WEB_TOKEN = os.getenv("OTIS_WEB_TOKEN")
assert OTIS_WEB_TOKEN is not None

yaml.SafeDumper.orig_represent_str = yaml.SafeDumper.represent_str # type: ignore
setattr(yaml.SafeDumper, "orig_represent_str", yaml.SafeDumper.represent_str)


def repr_str(dumper, data):
if "\n" in data:
data = data.replace("\r", "")
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.orig_represent_str(data)
return getattr(dumper, "orig_represent_str")(data)


yaml.add_representer(str, repr_str, Dumper=yaml.SafeDumper)
Expand Down
63 changes: 35 additions & 28 deletions py-scripts/oscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ def quadratic_mean(S):
parser.add_argument(
"files",
nargs="*",
type=argparse.FileType("r"),
default=[sys.stdin],
default=None,
help="File to read; default to sys.stdin if not provided.",
)
parser.add_argument(
"-o",
"--output",
nargs="?",
const=sys.stdout,
const="-",
default=None,
type=argparse.FileType("w"),
type=str,
help="Print output to this file (only works with one filename), pass with no argument for stdout.",
)
parser.add_argument(
Expand Down Expand Up @@ -371,28 +370,36 @@ def clean_name(s):


if __name__ == "__main__":
files = args.files
assert len(files) == 1 or (args.output is None and args.name is None), (
"can't write multiple inputs to a single output"
)

if len(files) == 1:
f = files[0]
if f == sys.stdin:
if args.output is None:
args.output = sys.stdout
name = args.name or "competition"
else:
name = args.name or clean_name(os.path.basename(f.name))

if args.output is None:
with open(os.path.splitext(f.name)[0] + ".oscar.tex", "w") as o:
main(f, o, name)
else:
main(f, args.output, name)

filenames = args.files
assert (
filenames is None
or len(filenames) == 1
or (args.output is None and args.name is None)
), "can't write multiple inputs to a single output"

if not filenames:
# stdin
outfile = (
sys.stdout
if args.output == "-"
else (open(args.output, "w") if args.output else sys.stdout)
)
main(sys.stdin, outfile, args.name or "competition")
elif len(filenames) == 1:
filename = filenames[0]
name = args.name or clean_name(os.path.basename(filename))
with open(filename) as f:
if args.output == "-":
main(f, sys.stdout, name)
elif args.output is not None:
with open(args.output, "w") as o:
main(f, o, name)
else:
with open(os.path.splitext(filename)[0] + ".oscar.tex", "w") as o:
main(f, o, name)
else:
for f in files:
name = clean_name(os.path.basename(f.name))
with open(os.path.splitext(f.name)[0] + ".oscar.tex", "w") as o:
main(f, o, clean_name(name))
for filename in filenames:
name = clean_name(os.path.basename(filename))
with open(filename) as f:
with open(os.path.splitext(filename)[0] + ".oscar.tex", "w") as o:
main(f, o, clean_name(name))
4 changes: 2 additions & 2 deletions ty.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[rules]
unresolved-import = "ignore"
[src]
exclude = ["config/i3/3kon"]
3 changes: 3 additions & 0 deletions venueQ/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from venueQ.venueQ import Data, VenueQNode, VenueQRoot, logger

__all__ = ["Data", "VenueQNode", "VenueQRoot", "logger"]
4 changes: 2 additions & 2 deletions venueQ/venueQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import yaml

yaml.SafeDumper.orig_represent_str = yaml.SafeDumper.represent_str # type: ignore
setattr(yaml.SafeDumper, "orig_represent_str", yaml.SafeDumper.represent_str)


def repr_str(dumper: yaml.SafeDumper, data: str) -> yaml.ScalarNode:
if "\n" in data:
data = data.replace("\r", "")
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.orig_represent_str(data) # type: ignore
return getattr(dumper, "orig_represent_str")(data)


yaml.add_representer(str, repr_str, Dumper=yaml.SafeDumper)
Expand Down
Loading