Skip to content

Commit

Permalink
First working Makefile for generating a Debian package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo committed Sep 19, 2019
1 parent 84b9fc6 commit ea8ed5c
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ ignore/
__pycache__/
.mypy_cache/
.idea

# Generated by Makefile
pxl.deb
package/usr/
package/usr/
package/usr/
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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



Empty file removed ignore/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions package/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Package: pxl
Version: 0
Architecture: all
Maintainer: IT Crowd <[email protected]>
Description: Manage photo albums on S3 buckets
4 changes: 4 additions & 0 deletions package/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions package/usr/bin/pxl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
/usr/lib/pxl/venv/bin/python /usr/lib/pxl/main.py "$@"

15 changes: 10 additions & 5 deletions pxl/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __main__ import __file__ as entrypoint_file # type: ignore
import click
import datetime
import functools
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ea8ed5c

Please sign in to comment.