Skip to content

Commit

Permalink
Dump local helper dev scripts in case it's useful to someone else
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Sep 5, 2023
1 parent 84c9db0 commit 72a81d2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
overdrive-libby-plugin-v*.zip
calibre-plugin/commit.txt

.env
Expand Down
64 changes: 64 additions & 0 deletions bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Replaces old version number for the new one
import argparse
import re
from pathlib import Path

version_sub_re = re.compile(r"__version__ = \(\d+, \d+, \d+\)")
version_re = re.compile(r"\d+\.\d+\.\d+")


def version_num(value: str):
if not version_re.match(value):
raise argparse.ArgumentTypeError(
f'"{value}" is an invalid version number format'
)
return value


def run(src_file: str, new_version: str):
temp_path = Path(f"{src_file}.temp")
src_path = Path(src_file)
with src_path.open("r", encoding="utf-8") as f_in, temp_path.open(
"w", encoding="utf-8"
) as f_out:
while True:
line = f_in.readline()
if not line:
break
mobj = version_sub_re.search(line)
if not mobj:
f_out.write(line)
continue
version_tuple = new_version.split(".")
new_line = version_sub_re.sub(
f'__version__ = ({", ".join(version_tuple)})',
line,
)
print(
f"{src_file}:\n"
f"* before:\t{line.strip()}"
f"\n* after:\t{new_line.strip()}"
)
f_out.write(new_line)
temp_path.rename(src_file)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Bump version")
parser.add_argument(
"new_version", type=version_num, help="New version number. Format d.d.d"
)

args = parser.parse_args()
src_files = ("calibre-plugin/__init__.py",)
for src in src_files:
run(src, args.new_version)

print(f'\nROLLBACK git commands:\ngit restore {" ".join(src_files)}\n')

print(
f'COMMIT git commands:\ngit add -u {" ".join(src_files)} calibre-plugin/translations/ translate.sh'
)
print(f"git commit -m 'Bump version to {args.new_version}'")
print(f"git tag --sign -a 'v{args.new_version}' -m 'Release v{args.new_version}'")
print("git push && git push --tags\n")
12 changes: 12 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Helper bash script to update versions and prompt for commands to run - macOS
# Does not commit to git because we usually have to also update screenshots, readme, changelog, etc
if [[ -z "$1" ]]; then
echo "Please specify a version number, e.g. 0.1.2"
exit
fi

version="$1"

python3 bump_version.py "$version" && \
sed -i '' -e "s/'[0-9]*\.[0-9]*\.[0-9]*'/'${version}'/g" translate.sh && \
sh translate.sh "$version"
8 changes: 8 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Helper bash script to start calibre debug with the latest plugin code loaded - macOS
for f in calibre-plugin/translations/*.po
do
echo "Building ${f%\.po} into ${f%\.po}.mo"
msgfmt -o "${f%\.po}.mo" "${f%\.po}"
done
echo "$(git rev-parse HEAD)" > calibre-plugin/commit.txt
calibre-debug -s; calibre-customize -b calibre-plugin; CALIBRE_OVERRIDE_LANG=en calibre-debug -g
7 changes: 7 additions & 0 deletions local_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Helper bash script to bundle a dev zip for local testing - macOS
version="$(git rev-parse HEAD)"
rm -f overdrive-libby-plugin-v*.zip
echo "$(git rev-parse HEAD)" > calibre-plugin/commit.txt
cd calibre-plugin && \
zip --quiet -r ../"overdrive-libby-plugin-v${version::7}.$(date +%H%M%S).zip" ./* && \
cd ..
1 change: 1 addition & 0 deletions translate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Helper bash script to update and build translations files - macOS
if [[ -z "$1" ]]; then
version='0.1.8'
else
Expand Down

0 comments on commit 72a81d2

Please sign in to comment.