From ea8ed5c9d3d2db8efc77d60abf0dbf4c71ee46cc Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 19 Sep 2019 12:17:27 +0200 Subject: [PATCH] First working Makefile for generating a Debian package. --- .gitignore | 6 ++++++ Makefile | 23 +++++++++++++++++++++++ ignore/.gitkeep | 0 package/DEBIAN/control | 5 +++++ package/DEBIAN/prerm | 4 ++++ package/usr/bin/pxl | 3 +++ pxl/cli.py | 15 ++++++++++----- 7 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Makefile delete mode 100644 ignore/.gitkeep create mode 100644 package/DEBIAN/control create mode 100755 package/DEBIAN/prerm create mode 100755 package/usr/bin/pxl diff --git a/.gitignore b/.gitignore index 7a9574d..a23420d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ ignore/ __pycache__/ .mypy_cache/ .idea + +# Generated by Makefile +pxl.deb +package/usr/ +package/usr/ +package/usr/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3ea9f12 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# Builds the pxl package with dpkg-deb from the /package directory to pxl.deb + +SHELL := /bin/bash +build: + rm -rf package/usr/lib/pxl + mkdir -p package/usr/lib/pxl + cp main.py package/usr/lib/pxl/ + cp -r pxl package/usr/lib/pxl/ + cp -r design package/usr/lib/pxl/ + python3.7 -m venv package/usr/lib/pxl/venv; + \ + source package/usr/lib/pxl/venv/bin/activate; \ + pipenv sync; \ + deactivate; \ + \ + dpkg-deb -b package/ pxl.deb + @echo "You can now install pxl by running 'sudo dpkg -i pxl.deb'" + +clean: + rm -rf package/usr/lib/pxl + + + diff --git a/ignore/.gitkeep b/ignore/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/package/DEBIAN/control b/package/DEBIAN/control new file mode 100644 index 0000000..fea32a1 --- /dev/null +++ b/package/DEBIAN/control @@ -0,0 +1,5 @@ +Package: pxl +Version: 0 +Architecture: all +Maintainer: IT Crowd +Description: Manage photo albums on S3 buckets diff --git a/package/DEBIAN/prerm b/package/DEBIAN/prerm new file mode 100755 index 0000000..ac07b87 --- /dev/null +++ b/package/DEBIAN/prerm @@ -0,0 +1,4 @@ +#!/bin/sh + +# Remove generate files (forced to ignore non 0 exit code when folder does not exist) +rm -rf /usr/lib/pxl/ignore diff --git a/package/usr/bin/pxl b/package/usr/bin/pxl new file mode 100755 index 0000000..f45fb5b --- /dev/null +++ b/package/usr/bin/pxl @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +/usr/lib/pxl/venv/bin/python /usr/lib/pxl/main.py "$@" + diff --git a/pxl/cli.py b/pxl/cli.py index 66c9b3c..4d7fa2c 100644 --- a/pxl/cli.py +++ b/pxl/cli.py @@ -1,3 +1,4 @@ +from __main__ import __file__ as entrypoint_file # type: ignore import click import datetime import functools @@ -17,6 +18,8 @@ import pxl.state as state import pxl.upload as upload +entrypoint = Path(entrypoint_file).parent + @click.group(name="pxl") def cli() -> None: @@ -134,9 +137,11 @@ def upload_cmd(dir_name: str, force: bool) -> None: @cli.command("build") def build_cmd() -> None: """Build a static site based on current state.""" - click.echo("Building site...", err=True) - output_dir = Path.cwd() / "ignore" / "build" - design_dir = Path.cwd() / "design" + output_dir = Path(entrypoint) / "ignore" / "build" + output_dir.mkdir(parents=True, exist_ok=True) + + click.echo(f"Building site to {output_dir}...", err=True) + design_dir = Path(entrypoint) / "design" cfg = config.load() with upload.client(cfg) as client: @@ -170,7 +175,7 @@ def build_cmd() -> None: @click.option("--bind", default="", help="Address to bind on (default: all interfaces)") def preview_cmd(port: int, bind: str) -> None: """Run a local webserver on build output""" - output_dir = Path.cwd() / "ignore" / "build" + output_dir = Path(entrypoint) / "ignore" / "build" if not output_dir.is_dir(): click.echo("No output to serve. Please run `pxl build` first.", err=True) sys.exit(1) @@ -203,7 +208,7 @@ def deploy_cmd() -> None: click.echo("Config not initialized. Please run `pxl init` first.", err=False) sys.exit(1) - output_dir = Path.cwd() / "ignore" / "build" + output_dir = Path(entrypoint) / "ignore" / "build" if not output_dir.is_dir(): click.echo("No output to deploy. Please run `pxl build` first.", err=False) sys.exit(1)