Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
syabruk committed Aug 23, 2012
0 parents commit fb1c67e
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
*.pyo
.DS_Store
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
All the works are available under the MIT license. **Except** for
‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such is
copyright of Apple.

Copyright (C) 2012 Vlad Syabruk <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
graft pync/vendor
include README.md LICENSE
global-exclude .DS_Store
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pync
====

A simple Python wrapper around the [`terminal-notifier`][HOMEPAGE] command-line
tool, which allows you to send User Notifications to the Notification Center on
Mac OS X 10.8, or higher.


Installation
------------

```
$ python setup.py install
```

Usage
-----

For full information on all the options, see the tool’s [README][README].

Examples are:

```python
from pync import Notifier

Notifier.notify('Hello World')
Notifier.notify('Hello World', title='Python')
Notifier.notify('Hello World', group=os.getpid())
Notifier.notify('Hello World', activate='com.apple.Safari')
Notifier.notify('Hello World', open='http://github.com/')
Notifier.notify('Hello World', execute='say "OMG"')

Notifier.remove(os.getpid())

Notifier.list(os.getpid())
```


License
-------

All the works are available under the MIT license. **Except** for
‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such is
copyright of Apple.

See [LICENSE][LICENSE] for details.

[HOMEPAGE]: https://github.com/alloy/terminal-notifier
[README]: https://github.com/alloy/terminal-notifier/blob/master/README.markdown
[LICENSE]: https://github.com/setem/pync/blob/master/LICENSE
Empty file added __init__.py
Empty file.
97 changes: 97 additions & 0 deletions pync/TerminalNotifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import platform
import subprocess
import itertools
import time
from datetime import datetime
from dateutil.parser import parse

LIST_FIELDS = ["group", "title", "sublitle", "message", "delivered_at"]

class TerminalNotifier(object):
def __init__(self):
"""
Raises if not supported on the current platform or if terminal-notifier.app does not find.
"""
self.bin_path = os.path.join(os.path.dirname(__file__), "vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier")
if not os.access(self.bin_path, os.X_OK):
os.chmod(self.bin_path, 111)
if not self.is_available:
raise Exception("pync is only supported on Mac OS X 10.8, or higher.")
if not os.path.exists(self.bin_path):
raise Exception("terminal-notifier.app does not exist.")

def notify(self, message, **kwargs):
"""
Sends a User Notification.
The available options are `title`, `group`, `activate`, `open`, and
`execute`. For a description of each option see:
https://github.com/alloy/terminal-notifier/blob/master/README.markdown
Examples are:
Notifier = TerminalNotifier()
Notifier.notify('Hello World')
Notifier.notify('Hello World', title='Python')
Notifier.notify('Hello World', group=os.getpid())
Notifier.notify('Hello World', activate='com.apple.Safari')
Notifier.notify('Hello World', open='http://github.com/')
Notifier.notify('Hello World', execute='say "OMG"')
"""
args = ['-message', message]
args += itertools.chain.from_iterable([("-%s" % arg, str(key)) for arg, key in kwargs.items()])
self.execute(args)

def execute(self, verbose):
output = subprocess.Popen([self.bin_path,] + verbose, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if output.returncode:
raise Exception("Some error during subprocess call.")
return output

def remove(self, group="ALL"):
"""
Removes a notification that was previously sent with the specified
‘group’ ID, if one exists.
If no ‘group’ ID is given, all notifications are removed.
"""
self.execute(["-remove", group])

def list(self, group="ALL"):
"""
If a ‘group’ ID is given, and a notification for that group exists,
returns a dict with details about the notification.
If no ‘group’ ID is given, an array of hashes describing all
notifications.
If no information is available this will return [].
"""
output = self.execute(["-list", group]).communicate()[0]
res = list()
for line in output.splitlines()[1:-1]:
res.append(dict(zip(LIST_FIELDS, line.split("\t"))))
try:
res[-1]["delivered_at"] = parse(res[-1]["delivered_at"])
except ValueError:
pass

return res

@staticmethod
def is_available(self):
""" Returns wether or not the current platform is Mac OS X 10.8, or higher."""
return platform.system() == "Darwin" and platform.mac_ver()[0] >= '10.8'

Notifier = TerminalNotifier()

if __name__ == '__main__':
Notifier.notify("Notification from %s" % __file__, open="http://github.com")

3 changes: 3 additions & 0 deletions pync/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "1.0"

from TerminalNotifier import Notifier
52 changes: 52 additions & 0 deletions pync/vendor/terminal-notifier.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12A269</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>terminal-notifier</string>
<key>CFBundleIconFile</key>
<string>Terminal</string>
<key>CFBundleIdentifier</key>
<string>nl.superalloy.oss.terminal-notifier</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>terminal-notifier</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>7</string>
<key>DTCompiler</key>
<string></string>
<key>DTPlatformBuild</key>
<string>4F243</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>12A264</string>
<key>DTSDKName</key>
<string>macosx10.8</string>
<key>DTXcode</key>
<string>0440</string>
<key>DTXcodeBuild</key>
<string>4F243</string>
<key>LSMinimumSystemVersion</key>
<string>10.8</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2012 Eloy Durán. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Binary file not shown.
1 change: 1 addition & 0 deletions pync/vendor/terminal-notifier.app/Contents/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPL????
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw9840\paperh8400
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b\fs24 \cf0 Engineering:
\b0 \
Some people\
\

\b Human Interface Design:
\b0 \
Some other people\
\

\b Testing:
\b0 \
Hopefully not nobody\
\

\b Documentation:
\b0 \
Whoever\
\

\b With special thanks to:
\b0 \
Mom\
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Resources/Terminal.icns</key>
<data>
Oq9GtJM1DqcGF1JCHiEgb0hoN6I=
</data>
<key>Resources/en.lproj/Credits.rtf</key>
<dict>
<key>hash</key>
<data>
YKJIFIsxneJuNkJNJQIcJIjiPOg=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/InfoPlist.strings</key>
<dict>
<key>hash</key>
<data>
MiLKDDnrUKr4EmuvhS5VQwxHGK8=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/MainMenu.nib</key>
<dict>
<key>hash</key>
<data>
N1QqAM17vgDk7XNtv27koaE4IhE=
</data>
<key>optional</key>
<true/>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
</dict>
</plist>
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from setuptools import setup, find_packages

file_contents = []
for file_name in ('README.md',):
path = os.path.join(os.path.dirname(__file__), file_name)
file_contents.append(open(path).read())
long_description = '\n\n'.join(file_contents)

setup(name = 'pync',
version = '1.0',
description = 'Python Wrapper for Mac OS 10.8 Notification Center',
long_description = long_description,
author = 'Vladislav Syabruk',
author_email = '[email protected]',
url = 'https://github.com/setem/pync',
download_url = 'https://github.com/downloads/setem/pync/pync_1.0.zip',
license = "MIT",
platforms = "MacOS X",
keywords = "mac notification center wrapper",
zip_safe = True,
include_package_data = True,
install_requires = [
'python-dateutil>=2.0'
],
packages = find_packages(),
)

0 comments on commit fb1c67e

Please sign in to comment.