There is now pyanaconda/version.py.in module with a __version__
variable, which automatically gets the Anaconda version from
automake during build and is saved as pyanaconda/version.py.
As a side effect, the absence of compiled isys no longer crashes
"anaconda --help". Also "anaconda --version" on freshly
cloned/unpackaged Anaconda now correctly returns "anaconda unknown".
Signed-off-by: Martin Kolman <mkolman(a)redhat.com>
---
.gitignore | 1 +
anaconda | 18 ++++++-----
configure.ac | 1 +
pyanaconda/Makefile.am | 2 +-
pyanaconda/exception.py | 5 +--
pyanaconda/isys/Makefile.am | 4 +--
pyanaconda/isys/__init__.py | 3 --
pyanaconda/isys/isys.c | 6 ----
pyanaconda/startup_utils.py | 77 +++++++++++++++++++++++++++++++++++++++++++++
pyanaconda/version.py.in | 1 +
10 files changed, 95 insertions(+), 23 deletions(-)
create mode 100644 pyanaconda/startup_utils.py
create mode 100644 pyanaconda/version.py.in
diff --git a/.gitignore b/.gitignore
index 6d84d21..1f46374 100644
--- a/.gitignore
+++ b/.gitignore
@@ -92,3 +92,4 @@ widgets/gtk-doc.make
widgets/src/gettext.h
anaconda.po
data/liveinst/gnome/fedora-welcome.po
+pyanaconda/version.py
diff --git a/anaconda b/anaconda
index a77c426..13f5310 100755
--- a/anaconda
+++ b/anaconda
@@ -251,11 +251,13 @@ def symlink_updates(dest_dir, update_dir):
continue
os.symlink(dest_path, update_path)
-def getAnacondaVersion():
- # Using _isys here so we don't drag in the logging stuff, which is always
- # complicated.
- from pyanaconda import _isys
- return _isys.getAnacondaVersion()
+def getAnacondaVersionString():
+ # we are importing the startup module directly so that it can be replaced
+ # by updates image, if it was replaced before the updates image can be
+ # loaded, it could not be easily replaced
+ from pyanaconda import startup_utils
+ return startup_utils.get_anaconda_version_string()
+
def parseArguments(argv=None, boot_cmdline=None):
from pyanaconda.anaconda_argparse import AnacondaArgumentParser
@@ -279,7 +281,7 @@ def parseArguments(argv=None, boot_cmdline=None):
# If this seems like too much trouble, *don't add a new option*!
# Version
- ap.add_argument('--version', action='version', version="%(prog)s
" + getAnacondaVersion())
+ ap.add_argument('--version', action='version', version="%(prog)s
" + getAnacondaVersionString())
# Interface
ap.add_argument("-C", "--cmdline", dest="display_mode",
action="store_const", const="c",
@@ -818,7 +820,7 @@ if __name__ == "__main__":
if "RUNKS" in flags.cmdline:
opts.display_mode = 'c'
- log.info("%s %s", sys.argv[0], getAnacondaVersion())
+ log.info("%s %s", sys.argv[0], getAnacondaVersionString())
# TODO: uncomment this when we're sure that we're doing the right thing
# with flags.cmdline *everywhere* it appears...
@@ -840,7 +842,7 @@ if __name__ == "__main__":
from pyanaconda import keyboard
from pyanaconda.iutil import ProxyString, ProxyStringError
- verdesc = "%s for %s %s" % (getAnacondaVersion(),
+ verdesc = "%s for %s %s" % (getAnacondaVersionString(),
product.productName, product.productVersion)
if product.isFinal:
print("anaconda %s started." % verdesc)
diff --git a/configure.ac b/configure.ac
index 20a99e1..83f14b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -204,6 +204,7 @@ AC_CONFIG_FILES([Makefile
po/Makefile.in
scripts/Makefile
pyanaconda/Makefile
+ pyanaconda/version.py
pyanaconda/isys/Makefile
pyanaconda/packaging/Makefile
pyanaconda/ui/Makefile
diff --git a/pyanaconda/Makefile.am b/pyanaconda/Makefile.am
index ae1159c..eeac1ae 100644
--- a/pyanaconda/Makefile.am
+++ b/pyanaconda/Makefile.am
@@ -24,4 +24,4 @@ MAINTAINERCLEANFILES = Makefile.in
# anaconda Python code
pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
anacondadir = $(pkgpyexecdir)
-anaconda_PYTHON = $(srcdir)/*.py
+anaconda_PYTHON = $(sort $(wildcard $(srcdir)/*.py $(builddir)/version.py))
diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index 7ce9026..3335054 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -24,7 +24,7 @@
from meh import Config
from meh.handler import ExceptionHandler
from meh.dump import ReverseExceptionDump
-from pyanaconda import isys, iutil, kickstart
+from pyanaconda import iutil, kickstart
import sys
import os
import shutil
@@ -41,6 +41,7 @@ from pyanaconda.constants import THREAD_EXCEPTION_HANDLING_TEST
from pyanaconda.threads import threadMgr
from pyanaconda.i18n import _
from pyanaconda import flags
+from pyanaconda import startup_utils
from gi.repository import GLib
@@ -228,7 +229,7 @@ def initExceptionHandling(anaconda):
fileList.extend([anaconda.opts.ksfile])
conf = Config(programName="anaconda",
- programVersion=isys.getAnacondaVersion(),
+ programVersion=startup_utils.get_anaconda_version_string(),
programArch=os.uname()[4],
attrSkipList=["_intf._actions",
"_intf._currentAction._xklwrapper",
diff --git a/pyanaconda/isys/Makefile.am b/pyanaconda/isys/Makefile.am
index bd3e36f..c787f60 100644
--- a/pyanaconda/isys/Makefile.am
+++ b/pyanaconda/isys/Makefile.am
@@ -21,13 +21,11 @@ pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
dist_noinst_HEADERS = $(srcdir)/*.h
-ISYS_CFLAGS =
-DVERSION_RELEASE='"$(PACKAGE_VERSION)-$(PACKAGE_RELEASE)"'
-
isysdir = $(pkgpyexecdir)/isys
isys_PYTHON = $(srcdir)/*.py
pkgpyexec_LTLIBRARIES = _isys.la
-_isys_la_CFLAGS = $(PYTHON_CFLAGS) $(ISYS_CFLAGS)
+_isys_la_CFLAGS = $(PYTHON_CFLAGS)
_isys_la_LDFLAGS = -module -avoid-version
_isys_la_LIBADD = $(PYTHON_LIBS)
_isys_la_SOURCES = isys.c
diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
index c985b3e..aa8c978 100644
--- a/pyanaconda/isys/__init__.py
+++ b/pyanaconda/isys/__init__.py
@@ -106,9 +106,6 @@ def isLpaeAvailable():
return False
-def getAnacondaVersion():
- return _isys.getAnacondaVersion()
-
def set_system_time(secs):
"""
Set system time to time given as a number of seconds since the Epoch.
diff --git a/pyanaconda/isys/isys.c b/pyanaconda/isys/isys.c
index c9a7ff5..23fb77f 100644
--- a/pyanaconda/isys/isys.c
+++ b/pyanaconda/isys/isys.c
@@ -31,13 +31,11 @@
static PyObject * doSync(PyObject * s, PyObject * args);
static PyObject * doSegvHandler(PyObject *s, PyObject *args);
-static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args);
static PyObject * doSetSystemTime(PyObject *s, PyObject *args);
static PyMethodDef isysModuleMethods[] = {
{ "sync", (PyCFunction) doSync, METH_VARARGS, NULL},
{ "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL },
- { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS,
NULL },
{ "set_system_time", (PyCFunction) doSetSystemTime, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL }
} ;
@@ -76,10 +74,6 @@ static PyObject * doSegvHandler(PyObject *s, PyObject *args) {
exit(1);
}
-static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args) {
- return Py_BuildValue("s", VERSION_RELEASE);
-}
-
static PyObject * doSetSystemTime(PyObject *s, PyObject *args) {
struct timeval tv;
tv.tv_usec = 0;
diff --git a/pyanaconda/startup_utils.py b/pyanaconda/startup_utils.py
new file mode 100644
index 0000000..2d84b4b
--- /dev/null
+++ b/pyanaconda/startup_utils.py
@@ -0,0 +1,77 @@
+#
+# startup.py - code used during early startup with minimal dependencies
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties 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., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Martin Kolman <mkolman(a)redhat.com>
+#
+import imp
+
+
+def module_exists(module_path):
+ """Report is a given module exists in the current module import pth or
not.
+ Supports checking bot modules ("foo") os submodules
("foo.bar.baz")
+
+ :param str module_path: (sub)module identifier
+
+ :returns: True if (sub)module exists in path, False if not
+ :rtype: bool
+ """
+
+ module_path_components = module_path.split(".")
+ module_name = module_path_components.pop()
+ parent_module_path = None
+ if module_path_components:
+ #the path specifies a submodule ("bar.foo")
+ # we need to chain-import all the modules in the submodule path before
+ # we can check if the submodule itself exists
+ parent_module_path = None
+ for name in module_path_components:
+ module_info = imp.find_module(name, parent_module_path)
+ module = imp.load_module(name, *module_info)
+ if module:
+ parent_module_path = module.__path__
+ else: # one of the parents was not found, abort search
+ return False
+ # if we got this far we should have either some path or the module is
+ # not a submodule and the default set of paths will be used (path=None)
+ try:
+ # if the module is not found imp raise an ImportError
+ imp.find_module(module_name, parent_module_path)
+ return True
+ except ImportError:
+ return False
+
+
+def get_anaconda_version_string():
+ """Return a string describing current Anaconda version.
+ If the current version can't be determined the string
+ "unknown" will be returned.
+
+ :returns: string describing Anaconda version
+ :rtype: str
+ """
+
+ # we are importing the version module directly so that we don't drag in any
+ # non-necessary stuff; we also need to handle the possibility of the
+ # import itself failing
+ if module_exists("pyanaconda.version"):
+ from pyanaconda import version
+ return version.__version__
+ else:
+ return "unknown"
+
diff --git a/pyanaconda/version.py.in b/pyanaconda/version.py.in
new file mode 100644
index 0000000..8b5161a
--- /dev/null
+++ b/pyanaconda/version.py.in
@@ -0,0 +1 @@
+__version__ = "@PACKAGE_VERSION@-@PACKAGE_RELEASE@"
--
1.9.0