Skip to content

Commit

Permalink
Merge pull request #48 from dschep/zipapp
Browse files Browse the repository at this point in the history
Package ntfy as a PEP441 style zipapp
  • Loading branch information
dschep committed Mar 30, 2016
2 parents 7c4400b + d2d1fe2 commit 7bf7f8b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.py[co]
*.egg-info
build
dist
/build
/dist
*travis.log
.eggs
htmlcov
Expand Down
7 changes: 7 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/python2
import sys

from ntfy.cli import main

if __name__ == '__main__':
sys.exit(main())
4 changes: 2 additions & 2 deletions ntfy/backends/linux.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from os import path

DEFAULT_ICON = path.join(path.split(path.split(__file__)[0])[0], 'icon.png')
from ..data import icon


def notify(title, message, icon=DEFAULT_ICON, **kwargs):
def notify(title, message, icon=icon.png, **kwargs):
try:
import dbus
except ImportError:
Expand Down
5 changes: 2 additions & 3 deletions ntfy/backends/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import struct
import time

DEFAULT_ICON = os.path.join(
os.path.split(os.path.split(__file__)[0])[0], 'icon.ico')
from ..data import icon


def notify(title, message, icon=DEFAULT_ICON, **kwargs):
def notify(title, message, icon=icon.ico, **kwargs):
"""
Optional parameters:
* ``icon`` - path to an ICO file to display instead of the ntfy icon
Expand Down
6 changes: 3 additions & 3 deletions ntfy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from . import __version__, notify
from .config import load_config, DEFAULT_CONFIG, OLD_DEFAULT_CONFIG
from .data import scripts


def run_cmd(args):
Expand Down Expand Up @@ -67,12 +68,11 @@ def watch_pid(args):


def auto_done(args):
shell_path = path.join(path.split(__file__)[0], 'shell_integration')
if emojize is not None and not args.no_emoji:
print('export AUTO_NTFY_DONE_EMOJI=true')
if args.shell == 'bash':
print('source {}/bash-preexec.sh'.format(shell_path))
print('source {}/auto-ntfy-done.sh'.format(shell_path))
print('source {}'.format(scripts['bash-preexec.sh']))
print('source {}'.format(scripts['auto-ntfy-done.sh']))
print("# To use ntfy's shell integration, run "
"this and and it to your shell's rc file:")
print('# eval "$(ntfy shell-integration)"')
Expand Down
28 changes: 28 additions & 0 deletions ntfy/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from os import path, makedirs
from pkgutil import get_data

from appdirs import user_data_dir

ntfy_data_dir = user_data_dir('ntfy', 'dschep')
if not path.isdir(ntfy_data_dir):
makedirs(ntfy_data_dir)


class icon(object):
png = None
ico = None
for fmt in ['png', 'ico']:
icon_path = path.abspath(path.join(ntfy_data_dir, 'icon.' + fmt))
setattr(icon, fmt, icon_path)
if not path.isfile(icon_path):
with open(icon_path, 'wb') as icon_file:
icon_file.write(get_data('ntfy', 'icon.' + fmt))

scripts = {}
for script in ['auto-ntfy-done.sh', 'bash-preexec.sh']:
script_path = path.abspath(path.join(ntfy_data_dir, script))
scripts[script] = script_path
if not path.isfile(script_path):
with open(script_path, 'wb') as script_file:
script_file.write(get_data('ntfy', path.join('shell_integration',
script)))
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PyYAML==3.11
appdirs==1.4.0
emoji==0.3.9
requests==2.9.1
8 changes: 8 additions & 0 deletions zipapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

rm -rf build/zipapp
mkdir -p build/zipapp dist
cp __main__.py build/zipapp
pip install --target=build/zipapp -r requirements.txt .
type -P python3.5 &> /dev/null && \
python3 -m zipapp -o dist/ntfy --python /usr/bin/python2.7 build/zipapp

0 comments on commit 7bf7f8b

Please sign in to comment.