Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'refactor-launcher' into integration

  • Loading branch information...
commit fda9d20957adad4d3592baa1a9d34af9a9e7a64a 2 parents a46e684 + 315a16b
@multani authored
View
6 run-sonata
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+import sonata.launcher
+
+if __name__ == '__main__':
+ sonata.launcher.run()
View
3  run-tests
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+python setup.py test
View
28 setup.py
@@ -2,7 +2,7 @@
import os, glob, shutil
-from distutils.core import setup, Extension
+from setuptools import setup, Extension
from sonata.version import version
@@ -46,9 +46,6 @@ def rmgeneric(path, __func__):
print "generating", mofile
os.system("msgfmt %s -o %s" % (pofile, mofile))
-# Copy script "sonata" file to sonata dir:
-shutil.copyfile("sonata.py", "sonata/sonata")
-
versionfile = open("sonata/genversion.py","wt")
versionfile.write("""
# generated by setup.py
@@ -56,6 +53,12 @@ def rmgeneric(path, __func__):
""" % version)
versionfile.close()
+
+tests_require = [
+ 'unittest2',
+]
+
+
setup(name='Sonata',
version=version,
description='GTK+ client for the Music Player Daemon (MPD).',
@@ -78,7 +81,6 @@ def rmgeneric(path, __func__):
extra_compile_args=capture("pkg-config --cflags gtk+-2.0 pygtk-2.0").split(),
extra_link_args=capture("pkg-config --libs gtk+-2.0 pygtk-2.0").split()
),],
- scripts = ['sonata/sonata'],
data_files=[('share/sonata', ['README', 'CHANGELOG', 'TODO', 'TRANSLATORS']),
('share/applications', ['sonata.desktop']),
('share/pixmaps', glob.glob('sonata/pixmaps/*')),
@@ -107,7 +109,17 @@ def rmgeneric(path, __func__):
('share/locale/sl/LC_MESSAGES', ['mo/sl/sonata.mo']),
('share/locale/zh_TW/LC_MESSAGES', ['mo/zh_TW/sonata.mo']),
('share/locale/uk/LC_MESSAGES', ['mo/uk/sonata.mo'])],
- )
+ entry_points={
+ 'console_scripts': [
+ 'sonata=sonata.launcher:run',
+ ]
+ },
+ test_suite='sonata.tests',
+ tests_require=tests_require,
+ extras_require={
+ 'test': tests_require,
+ },
+)
# Cleanup (remove /build, /mo, and *.pyc files:
print "Cleaning up..."
@@ -129,10 +141,6 @@ def rmgeneric(path, __func__):
except:
pass
try:
- os.remove("sonata/sonata")
-except:
- pass
-try:
os.remove("sonata/genversion.py")
os.remove("sonata/genversion.pyc")
except:
View
166 sonata.py
@@ -1,166 +0,0 @@
-#!/usr/bin/env python
-"""Sonata is a simple GTK+ client for the Music Player Daemon.
-"""
-
-__author__ = "Scott Horowitz"
-__email__ = "stonecrest@gmail.com"
-__license__ = """
-Sonata, an elegant GTK+ client for the Music Player Daemon
-Copyright 2006-2008 Scott Horowitz <stonecrest@gmail.com>
-
-This file is part of Sonata.
-
-Sonata is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-Sonata is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-
-import sys, platform, locale, gettext, os
-
-# XXX insert the correct sonata package dir in sys.path
-
-try:
- import sonata
-except ImportError:
- sys.stderr.write("Python failed to find the sonata modules.\n")
- sys.stderr.write("\nSearched in the following directories:\n" +
- "\n".join(sys.path) + "\n")
- sys.stderr.write("\nPerhaps Sonata is improperly installed?\n")
- sys.exit(1)
-
-try:
- from sonata.version import version
-except ImportError:
- sys.stderr.write("Python failed to find the sonata modules.\n")
- sys.stderr.write("\nAn old or incomplete installation was " +
- "found in the following directory:\n" +
- os.path.dirname(sonata.__file__) + "\n")
- sys.stderr.write("\nPerhaps you want to delete it?\n")
- sys.exit(1)
-
-# XXX check that version.VERSION is what this script was installed for
-
-
-## Apply global fixes:
-
-# the following line is to fix python-zsi 2.0 and thus lyrics in ubuntu:
-# https://bugs.launchpad.net/ubuntu/+source/zsi/+bug/208855
-sys.path.append('/usr/lib/python2.5/site-packages/oldxml')
-
-# hint for gnome.init to set the process name to 'sonata'
-if platform.system() == 'Linux':
- sys.argv[0] = 'sonata'
-
-# apply as well:
- try:
- import ctypes
- libc = ctypes.CDLL('libc.so.6')
- PR_SET_NAME = 15
- libc.prctl(PR_SET_NAME, sys.argv[0], 0, 0, 0)
- except Exception: # if it fails, it fails
- pass
-
-
-## Apply locale and translation:
-
-from sonata import misc
-misc.setlocale()
-
-# let gettext install _ as a built-in for all modules to see
-# XXX what's the correct way to find the localization?
-try:
- gettext.install('sonata', os.path.join(sonata.__file__.split('/lib')[0], 'share', 'locale'), unicode=1)
-except:
- print "Warning: trying to use an old translation"
- gettext.install('sonata', '/usr/share/locale', unicode=1)
-gettext.textdomain('sonata')
-
-
-## Check initial dependencies:
-
-# Test python version:
-if sys.version_info < (2,5):
- sys.stderr.write("Sonata requires Python 2.5 or newer. Aborting...\n")
- sys.exit(1)
-
-try:
- import mpd
-except:
- sys.stderr.write("Sonata requires python-mpd. Aborting...\n")
- sys.exit(1)
-
-
-## Initialize the plugin system:
-
-from sonata.pluginsystem import pluginsystem
-pluginsystem.find_plugins()
-pluginsystem.notify_of('enablables',
- lambda plugin, cb: cb(True),
- lambda plugin, cb: cb(False))
-
-
-## Load the command line interface:
-
-from sonata import cli
-args = cli.Args()
-args.parse(sys.argv)
-
-## Deal with GTK:
-
-if not args.skip_gui:
- # importing gtk does sys.setdefaultencoding("utf-8"), sets locale etc.
- import gtk
- if gtk.pygtk_version < (2, 12, 0):
- sys.stderr.write("Sonata requires PyGTK 2.12.0 or newer. Aborting...\n")
- sys.exit(1)
- # fix locale
- misc.setlocale()
-else:
- class FakeModule(object):
- pass
- # make sure the ui modules aren't imported
- for m in 'gtk', 'pango', 'sonata.ui', 'sonata.breadcrumbs':
- if m in sys.modules:
- print "Warning: module %s imported in CLI mode" % m
- else:
- sys.modules[m] = FakeModule()
- # like gtk, set utf-8 encoding of str objects
- reload(sys) # hack access to setdefaultencoding
- sys.setdefaultencoding("utf-8")
-
-
-## Global init:
-
-from socket import setdefaulttimeout as socketsettimeout
-socketsettimeout(5)
-
-if not args.skip_gui:
- gtk.gdk.threads_init()
-
- # we don't use gtk.LinkButton, but gtk.AboutDialog does;
- # in gtk 2.16.0 without this, the about uri opens doubly:
- gtk.link_button_set_uri_hook(lambda *args:None)
-
-## CLI actions:
-
-args.execute_cmds()
-
-
-## Load the main application:
-
-from sonata import main
-
-app = main.Base(args)
-try:
- app.main()
-except KeyboardInterrupt:
- pass
View
170 sonata/launcher.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+"""Sonata is a simple GTK+ client for the Music Player Daemon.
+"""
+
+__author__ = "Scott Horowitz"
+__email__ = "stonecrest@gmail.com"
+__license__ = """
+Sonata, an elegant GTK+ client for the Music Player Daemon
+Copyright 2006-2008 Scott Horowitz <stonecrest@gmail.com>
+
+This file is part of Sonata.
+
+Sonata is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+Sonata is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import sys, platform, locale, gettext, os
+
+
+def run():
+ """Main entry point of Sonata"""
+
+ # XXX insert the correct sonata package dir in sys.path
+
+ try:
+ import sonata
+ except ImportError:
+ sys.stderr.write("Python failed to find the sonata modules.\n")
+ sys.stderr.write("\nSearched in the following directories:\n" +
+ "\n".join(sys.path) + "\n")
+ sys.stderr.write("\nPerhaps Sonata is improperly installed?\n")
+ sys.exit(1)
+
+ try:
+ from sonata.version import version
+ except ImportError:
+ sys.stderr.write("Python failed to find the sonata modules.\n")
+ sys.stderr.write("\nAn old or incomplete installation was " +
+ "found in the following directory:\n" +
+ os.path.dirname(sonata.__file__) + "\n")
+ sys.stderr.write("\nPerhaps you want to delete it?\n")
+ sys.exit(1)
+
+ # XXX check that version.VERSION is what this script was installed for
+
+
+ ## Apply global fixes:
+
+ # the following line is to fix python-zsi 2.0 and thus lyrics in ubuntu:
+ # https://bugs.launchpad.net/ubuntu/+source/zsi/+bug/208855
+ sys.path.append('/usr/lib/python2.5/site-packages/oldxml')
+
+ # hint for gnome.init to set the process name to 'sonata'
+ if platform.system() == 'Linux':
+ sys.argv[0] = 'sonata'
+
+ # apply as well:
+ try:
+ import ctypes
+ libc = ctypes.CDLL('libc.so.6')
+ PR_SET_NAME = 15
+ libc.prctl(PR_SET_NAME, sys.argv[0], 0, 0, 0)
+ except Exception: # if it fails, it fails
+ pass
+
+
+ ## Apply locale and translation:
+
+ from sonata import misc
+ misc.setlocale()
+
+ # let gettext install _ as a built-in for all modules to see
+ # XXX what's the correct way to find the localization?
+ try:
+ gettext.install('sonata', os.path.join(sonata.__file__.split('/lib')[0], 'share', 'locale'), unicode=1)
+ except:
+ print "Warning: trying to use an old translation"
+ gettext.install('sonata', '/usr/share/locale', unicode=1)
+ gettext.textdomain('sonata')
+
+
+ ## Check initial dependencies:
+
+ # Test python version:
+ if sys.version_info < (2,5):
+ sys.stderr.write("Sonata requires Python 2.5 or newer. Aborting...\n")
+ sys.exit(1)
+
+ try:
+ import mpd
+ except:
+ sys.stderr.write("Sonata requires python-mpd. Aborting...\n")
+ sys.exit(1)
+
+
+ ## Initialize the plugin system:
+
+ from sonata.pluginsystem import pluginsystem
+ pluginsystem.find_plugins()
+ pluginsystem.notify_of('enablables',
+ lambda plugin, cb: cb(True),
+ lambda plugin, cb: cb(False))
+
+
+ ## Load the command line interface:
+
+ from sonata import cli
+ args = cli.Args()
+ args.parse(sys.argv)
+
+ ## Deal with GTK:
+
+ if not args.skip_gui:
+ # importing gtk does sys.setdefaultencoding("utf-8"), sets locale etc.
+ import gtk
+ if gtk.pygtk_version < (2, 12, 0):
+ sys.stderr.write("Sonata requires PyGTK 2.12.0 or newer. Aborting...\n")
+ sys.exit(1)
+ # fix locale
+ misc.setlocale()
+ else:
+ class FakeModule(object):
+ pass
+ # make sure the ui modules aren't imported
+ for m in 'gtk', 'pango', 'sonata.ui', 'sonata.breadcrumbs':
+ if m in sys.modules:
+ print "Warning: module %s imported in CLI mode" % m
+ else:
+ sys.modules[m] = FakeModule()
+ # like gtk, set utf-8 encoding of str objects
+ reload(sys) # hack access to setdefaultencoding
+ sys.setdefaultencoding("utf-8")
+
+
+ ## Global init:
+
+ from socket import setdefaulttimeout as socketsettimeout
+ socketsettimeout(5)
+
+ if not args.skip_gui:
+ gtk.gdk.threads_init()
+
+ # we don't use gtk.LinkButton, but gtk.AboutDialog does;
+ # in gtk 2.16.0 without this, the about uri opens doubly:
+ gtk.link_button_set_uri_hook(lambda *args:None)
+
+ ## CLI actions:
+
+ args.execute_cmds()
+
+
+ ## Load the main application:
+
+ from sonata import main
+
+ app = main.Base(args)
+ try:
+ app.main()
+ except KeyboardInterrupt:
+ pass
View
23 sonata/tests/__init__.py
@@ -0,0 +1,23 @@
+import doctest
+import unittest2
+
+
+DOCTEST_FLAGS = (
+ doctest.ELLIPSIS |
+ doctest.NORMALIZE_WHITESPACE |
+ doctest.REPORT_NDIFF
+)
+
+
+class TestSonata(unittest2.TestCase):
+ def test_dummy(self):
+ # TODO: replace with a test which does something once we start to have
+ # tests!
+ pass
+
+
+def additional_tests():
+ return unittest2.TestSuite(
+ # TODO: add files which use doctests here
+ #doctest.DocFileSuite('../audioscrobbler.py', optionflags=DOCTEST_FLAGS),
+ )
Please sign in to comment.
Something went wrong with that request. Please try again.