From dfa1fc0d77f46a373e85a19448403da95faa27a9 Mon Sep 17 00:00:00 2001 From: Adam Stokes Date: Tue, 21 Feb 2012 01:28:12 +0000 Subject: policies: Make sure policies are included during build There was no previous Makefile for including any additional policy files. Also updated upstream directory in toplevel Makefile and altered the @SOSVERSION@ string replacing to work properly instead of zeroing out the init file Signed-off-by: Adam Stokes --- Makefile | 6 ++--- sos/__init__.py | 74 --------------------------------------------------- sos/__init__.py.in | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ sos/policies/Makefile | 20 ++++++++++++++ 4 files changed, 97 insertions(+), 77 deletions(-) delete mode 100644 sos/__init__.py create mode 100644 sos/__init__.py.in create mode 100644 sos/policies/Makefile diff --git a/Makefile b/Makefile index 1e1b249a..bbe6d251 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ NAME = sos VERSION = $(shell echo `awk '/^Version:/ {print $$2}' sos.spec`) RELEASE = $(shell echo `awk '/^Release:/ {gsub(/\%.*/,""); print $2}' sos.spec`) -REPO = http://svn.fedorahosted.org/svn/sos +REPO = http://github.com/sosreport -SUBDIRS = po sos sos/plugins +SUBDIRS = po sos sos/plugins sos/policies PYFILES = $(wildcard *.py) # OS X via brew # MSGCAT = /usr/local/Cellar/gettext/0.18.1.1/bin/msgcat @@ -47,7 +47,7 @@ install: install -m644 LICENSE README TODO $(DESTDIR)/usr/share/$(NAME)/. install -m644 $(NAME).conf $(DESTDIR)/etc/$(NAME).conf install -m644 gpgkeys/rhsupport.pub $(DESTDIR)/usr/share/$(NAME)/. - sed 's/@SOSVERSION@/$(VERSION)/g' < sos/__init__.py > sos/__init__.py + sed 's/@SOSVERSION@/$(VERSION)/g' sos/__init__.py.in > sos/__init__.py for d in $(SUBDIRS); do make DESTDIR=`cd $(DESTDIR); pwd` -C $$d install; [ $$? = 0 ] || exit 1; done $(NAME)-$(VERSION).tar.gz: clean gpgkey diff --git a/sos/__init__.py b/sos/__init__.py deleted file mode 100644 index f703a834..00000000 --- a/sos/__init__.py +++ /dev/null @@ -1,74 +0,0 @@ -## Copyright 2010 Red Hat, Inc. -## Author: Adam Stokes - -## This program 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 2 of the License, or -## (at your option) any later version. - -## This program 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, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -""" -This module houses the i18n setup and message function. The default is to use -gettext to internationalize messages. If the client calls set_i18n and passes a -path to a resource bundle the _ method will be changed to use java -ResourceBundle code to present messages. -""" - -__version__ = "@SOSVERSION@" - -import gettext -gettext_dir = "/usr/share/locale" -gettext_app = "sos" - -gettext.bindtextdomain(gettext_app, gettext_dir) - -def _default(msg): - return gettext.dgettext(gettext_app, msg) - -_sos = _default - -def _get_classloader(jarfile): - """Makes a new classloader loaded with the jarfile. This is useful since it - seems very difficult to get jars added to the correct classpath for - ResourceBundle.getBundle to find.""" - from java.net import URLClassLoader, URL - from java.io import File - import jarray - - file_ = File(jarfile) - ary = jarray.array([file_.toURL()], URL) - classloader = URLClassLoader.newInstance(ary) - return classloader - -def set_i18n(path=None, basename="sos.po.sos"): - """Use this method to change the default i18n behavior from gettext to java - ResourceBundle.getString. This is really only useful when using jython. - Path is expected to be the path to a jarfile that contains the translation - files (.properties)""" - - # Since we are trying to modify the module-level _sos variable - # we have to declare it global - global _sos - - try: - from java.util import ResourceBundle, Locale - - rb = ResourceBundle.getBundle(basename, - Locale.getDefault(), _get_classloader(path)) - - def _java(msg): - try: - return rb.getString(msg).encode('utf-8') - except: - return msg - _sos = _java - except: - pass diff --git a/sos/__init__.py.in b/sos/__init__.py.in new file mode 100644 index 00000000..f703a834 --- /dev/null +++ b/sos/__init__.py.in @@ -0,0 +1,74 @@ +## Copyright 2010 Red Hat, Inc. +## Author: Adam Stokes + +## This program 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 2 of the License, or +## (at your option) any later version. + +## This program 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, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +""" +This module houses the i18n setup and message function. The default is to use +gettext to internationalize messages. If the client calls set_i18n and passes a +path to a resource bundle the _ method will be changed to use java +ResourceBundle code to present messages. +""" + +__version__ = "@SOSVERSION@" + +import gettext +gettext_dir = "/usr/share/locale" +gettext_app = "sos" + +gettext.bindtextdomain(gettext_app, gettext_dir) + +def _default(msg): + return gettext.dgettext(gettext_app, msg) + +_sos = _default + +def _get_classloader(jarfile): + """Makes a new classloader loaded with the jarfile. This is useful since it + seems very difficult to get jars added to the correct classpath for + ResourceBundle.getBundle to find.""" + from java.net import URLClassLoader, URL + from java.io import File + import jarray + + file_ = File(jarfile) + ary = jarray.array([file_.toURL()], URL) + classloader = URLClassLoader.newInstance(ary) + return classloader + +def set_i18n(path=None, basename="sos.po.sos"): + """Use this method to change the default i18n behavior from gettext to java + ResourceBundle.getString. This is really only useful when using jython. + Path is expected to be the path to a jarfile that contains the translation + files (.properties)""" + + # Since we are trying to modify the module-level _sos variable + # we have to declare it global + global _sos + + try: + from java.util import ResourceBundle, Locale + + rb = ResourceBundle.getBundle(basename, + Locale.getDefault(), _get_classloader(path)) + + def _java(msg): + try: + return rb.getString(msg).encode('utf-8') + except: + return msg + _sos = _java + except: + pass diff --git a/sos/policies/Makefile b/sos/policies/Makefile new file mode 100644 index 00000000..8fd6a1bf --- /dev/null +++ b/sos/policies/Makefile @@ -0,0 +1,20 @@ +PYTHON=python +PACKAGE = $(shell basename `pwd`) +PYFILES = $(wildcard *.py) +PYVER := $(shell $(PYTHON) -c 'import sys; print "%.3s" %(sys.version)') +PYSYSDIR := $(shell $(PYTHON) -c 'import sys; print sys.prefix') +PYLIBDIR = $(PYSYSDIR)/lib/python$(PYVER) +PKGDIR = $(PYLIBDIR)/site-packages/sos/$(PACKAGE) + +all: + echo "nada" + +clean: + rm -f *.pyc *.pyo *~ + +install: + mkdir -p $(DESTDIR)/$(PKGDIR) + for p in $(PYFILES) ; do \ + install -m 755 $$p $(DESTDIR)/$(PKGDIR)/$$p; \ + done + $(PYTHON) -c "import compileall; compileall.compile_dir('$(DESTDIR)/$(PKGDIR)', 1, '$(PYDIR)', 1)" -- cgit