aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Matthijs <axxo@gentoo.org>2005-12-25 19:02:16 +0000
committerThomas Matthijs <axxo@gentoo.org>2005-12-25 19:02:16 +0000
commit18ef04521e452ea3da9b1ccaad0642c7844c9fae (patch)
treeb8ed6df42d51d0837cc760f8e38424ea73f9b38b
parentdont default to ecj (diff)
downloadjava-config-18ef04521e452ea3da9b1ccaad0642c7844c9fae.tar.gz
java-config-18ef04521e452ea3da9b1ccaad0642c7844c9fae.tar.bz2
java-config-18ef04521e452ea3da9b1ccaad0642c7844c9fae.zip
add some useless comments, and make it python-updater proof
svn path=/java-config-ng/branches/axxo/; revision=1680
-rw-r--r--MANIFEST.in1
-rw-r--r--setup.py8
-rwxr-xr-xsrc/depend-java-query3
-rwxr-xr-xsrc/gjl3
-rwxr-xr-xsrc/java-config19
-rw-r--r--src/java_config/EnvironmentManager.py8
-rw-r--r--src/java_config/FileParser.py10
-rw-r--r--src/java_config/Package.py17
-rw-r--r--src/java_config/VM.py3
-rw-r--r--src/java_config/VersionManager.py21
10 files changed, 74 insertions, 19 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
index ea4ba9b..688e3fb 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,4 +2,5 @@ recursive-include man/ *
recursive-include config/ *
include src/*.bash
include src/eselect/*.eselect
+include src/java_config/*.py
diff --git a/setup.py b/setup.py
index 27be40e..6cd0cc8 100644
--- a/setup.py
+++ b/setup.py
@@ -2,10 +2,11 @@
from distutils.core import setup
import os
+from os import listdir
setup (
name = 'java-config',
- version = '2.0.18',
+ version = '2.0.19',
description = 'java enviroment configuration tool',
long_description = \
"""
@@ -16,10 +17,11 @@ setup (
maintainer = 'Gentoo Java Herd',
maintainer_email = 'java@gentoo.org',
url = 'http://www.gentoo.org',
- packages = ['java_config'],
- package_dir = { 'java_config' : 'src/java_config' },
+ #packages = ['java_config'],
+ #package_dir = { 'java_config' : 'src/java_config' },
scripts = ['src/java-config','src/depend-java-query','src/run-java-tool', 'src/gjl'],
data_files = [
+ ('share/java-config/pym/java_config/', ['src/java_config/'+file for file in listdir('src/java_config/')] ),
('share/man/man1', ['man/java-config.1']),
('share/java-config/launcher', ['src/launcher.bash']),
('share/eselect/modules', ['src/eselect/java.eselect']),
diff --git a/src/depend-java-query b/src/depend-java-query
index 7b62946..60f5b7b 100755
--- a/src/depend-java-query
+++ b/src/depend-java-query
@@ -5,6 +5,9 @@
# Distributed under the terms of the GNU General Public License v2
# $Header: $
+import sys
+sys.path = ['/usr/share/java-config/pym']+sys.path
+
from java_config import __version__
from java_config.OutputFormatter import OutputFormatter
from java_config.EnvironmentManager import EnvironmentManager
diff --git a/src/gjl b/src/gjl
index f261df8..500de7c 100755
--- a/src/gjl
+++ b/src/gjl
@@ -5,6 +5,9 @@
# Distributed under the terms of the GNU General Public License v2
# $Header: $
+import sys
+sys.path = ['/usr/share/java-config/pym']+sys.path
+
from java_config import __version__
from java_config.OutputFormatter import *
from java_config.EnvironmentManager import *
diff --git a/src/java-config b/src/java-config
index 73e4fe2..e479b19 100755
--- a/src/java-config
+++ b/src/java-config
@@ -5,6 +5,9 @@
# Distributed under the terms of the GNU General Public License v2
# $Header: $
+import sys
+sys.path = ['/usr/share/java-config/pym']+sys.path
+
from java_config import __version__
from java_config.OutputFormatter import OutputFormatter
from java_config.EnvironmentManager import EnvironmentManager
@@ -24,20 +27,20 @@ def version(option, opt, value, parser):
def nocolor(option, opt, value, parser):
printer.setColorOutputStatus(False)
-def jdk_command(command):
+def get_command(command):
try:
printer._print(manager.get_active_vm().find_exec(command))
except PermissionError:
fatalError("The " + command + " executable was not found in the Java path")
def java(option, opt, value, parser):
- jdk_command('java')
+ get_command('java')
def javac(option, opt, value, parser):
- jdk_command('javac')
+ get_command('javac')
def jar(option, opt, value, parser):
- jdk_command('jar')
+ get_command('jar')
def print_java_home():
try:
@@ -149,6 +152,7 @@ def set_user_vm(option, opt, value, parser):
except PermissionError:
fatalError("You do not have enough permissions to set the VM!")
+# Deprecated
def system_classpath_target():
# TODO: MAKE THIS MODULAR!! (compnerd)
return [{'file': '/etc/env.d/21java-classpath', 'format': '%s=%s\n' }]
@@ -159,7 +163,7 @@ def user_classpath_target():
{'file': os.path.join(os.environ.get("HOME"), '.gentoo/java-env-classpath'), 'format': 'export %s=%s\n' },
{'file': os.path.join(os.environ.get("HOME"), '.gentoo/java-env-classpath.csh'), 'format': 'setenv %s %s\n' }
]
-
+# Deprecated
def set_system_classpath(option, opt, value, parser):
deprecation_notice()
if os.getuid() is 0:
@@ -173,6 +177,7 @@ def set_system_classpath(option, opt, value, parser):
else:
fatalError("You do not have enough permissions to set the system classpath!")
+# Deprecated
def set_user_classpath(option, opt, value, parser):
deprecation_notice()
pkgs = value.split(',')
@@ -183,6 +188,7 @@ def set_user_classpath(option, opt, value, parser):
user_update_env()
+# Deprecated
def append_system_classpath(option, opt, value, parser):
deprecation_notice()
if os.getuid() is 0:
@@ -196,6 +202,7 @@ def append_system_classpath(option, opt, value, parser):
else:
fatalError("You do not have enough permissioins to append to the system classpath!")
+# Deprecated
def append_user_classpath(option, opt, value, parser):
deprecation_notice()
pkgs = value.split(',')
@@ -206,6 +213,7 @@ def append_user_classpath(option, opt, value, parser):
user_update_env()
+# Deprecated
def clean_system_classpath(option, opt, value, parser):
deprecation_notice()
if os.getuid() is 0:
@@ -214,6 +222,7 @@ def clean_system_classpath(option, opt, value, parser):
else:
fatalError("You do not have enough permissions to clean the system classpath!")
+# Deprecated
def clean_user_classpath(option, opt, value, parser):
deprecation_notice()
manager.clean_classpath(user_classpath_target())
diff --git a/src/java_config/EnvironmentManager.py b/src/java_config/EnvironmentManager.py
index ff8e177..26debcc 100644
--- a/src/java_config/EnvironmentManager.py
+++ b/src/java_config/EnvironmentManager.py
@@ -15,12 +15,15 @@ from sets import Set
import os, re, sys
class EnvironmentManager:
+ """This is the central class, which manages all information from the 'environment'"""
virtual_machines = None
packages = None
virtuals = None
active = None
+ # Location of the vm ev files
vms_path = '/etc/env.d/java/'
+ # Location of the package env files to load
pkg_path = '/usr/share/*/package.env'
def __init__(self):
@@ -30,6 +33,7 @@ class EnvironmentManager:
return self
def load_vms(self):
+ """Load all the vm files, and check for correctness"""
self.virtual_machines = {}
if os.path.isdir(self.vms_path):
@@ -49,7 +53,7 @@ class EnvironmentManager:
continue
except InvalidVMError, ex:
printer = OutputFormatter()
- printer._printAlert("Old vm configuration file found: %s\nPlease update the vm package associated with the file\n(%s)" % ( conf, ex ))
+ printer._printAlert("Invalid vm configuration file found: %s\nJava-config 2 requires some new variables, please update all your jdk/jre: file\n(%s)" % ( conf, ex ))
continue
self.virtual_machines[count] = vm
@@ -250,6 +254,7 @@ class EnvironmentManager:
self.write_classpath(targets, classpath)
def get_old_classpath(self, target):
+ """Returns the current set classpath in the file"""
oldClasspath = ''
if os.path.isfile(target['file']):
try:
@@ -302,6 +307,7 @@ class EnvironmentManager:
return True
+# Singleton hack
EnvironmentManager = EnvironmentManager()
# vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/java_config/FileParser.py b/src/java_config/FileParser.py
index d16b1d7..0a47b05 100644
--- a/src/java_config/FileParser.py
+++ b/src/java_config/FileParser.py
@@ -9,6 +9,10 @@ import os
class FileParser:
+ """
+ Parse some basic key=value configuration files.
+ Values are passed to the pair function.
+ """
def parse(self, file):
if not os.path.isfile(file):
raise InvalidConfigError(file)
@@ -50,6 +54,9 @@ class FileParser:
pass
class EnvFileParser(FileParser):
+ """
+ Stores the configuation in a dictionary
+ """
def __init__(self, file):
self.config = {}
self.parse(file)
@@ -61,6 +68,9 @@ class EnvFileParser(FileParser):
return self.config.copy()
class PrefsFileParser(FileParser):
+ """
+ Stores it in a list.
+ """
def __init__(self, file):
self.config = []
self.parse(file)
diff --git a/src/java_config/Package.py b/src/java_config/Package.py
index fe74f09..e4555f5 100644
--- a/src/java_config/Package.py
+++ b/src/java_config/Package.py
@@ -7,7 +7,10 @@
from FileParser import *
class Package:
- def __init__(self, name,file = None):
+ """
+ Class represeting an installed java package
+ """
+ def __init__(self, name, file = None):
self._file = file
self._name = name
if self._file:
@@ -31,18 +34,27 @@ class Package:
return "No Description"
def classpath(self):
+ """
+ Returns this package's classpath
+ """
if self._config.has_key("CLASSPATH"):
return self._config["CLASSPATH"]
else:
return None
def query(self, var):
+ """
+ Return the value of the requested var form the env file
+ """
if self._config.has_key(var):
return self._config[var]
else:
return None
def deps(self):
+ """
+ Return all packages this package depeds on
+ """
depstr = self.query("DEPEND")
if depstr:
return [dep.split("@") for dep in depstr.split(":")]
@@ -50,6 +62,9 @@ class Package:
return []
def provides(self):
+ """
+ Return the virtuals this package provides
+ """
pv = self.query('PROVIDES')
if pv:
return pv.split(" ")
diff --git a/src/java_config/VM.py b/src/java_config/VM.py
index e9f300d..b779288 100644
--- a/src/java_config/VM.py
+++ b/src/java_config/VM.py
@@ -12,6 +12,7 @@ from string import upper
class VM:
+ # Dont accept env files without these variables
needed_vars = [ "JAVA_HOME", "PROVIDES_TYPE", "PROVIDES_VERSION" ]
def __init__(self, file):
@@ -42,7 +43,7 @@ class VM:
return self.file
def name(self):
- # TODO: MAKE THIS MODULAR!
+ # TODO: MAKE THIS MODULAR!a (compnerd)
return self.file.split("/etc/env.d/java/20")[-1]
def is_jre(self):
diff --git a/src/java_config/VersionManager.py b/src/java_config/VersionManager.py
index 5a96ee9..9626e59 100644
--- a/src/java_config/VersionManager.py
+++ b/src/java_config/VersionManager.py
@@ -18,6 +18,9 @@ import os.path
# Does however do the right thing for the only types of deps we should see
# Ignore blockers: portage doesn't support them in a way that is usefull for us
class VersionManager:
+ """
+ Used to parse dependency stringsa, and find the best/prefered vm to use.
+ """
#atom_parser = re.compile(r"([~!<>=]*)virtual/(jre|jdk)-([0-9\.]+)")
atom_parser = re.compile(r"([<>=]+)virtual/(jre|jdk)-([0-9\.*]+)")
pref_files = ['/etc/java-config/jdk.conf', '/usr/share/java-config/config/jdk-defaults.conf']
@@ -37,6 +40,7 @@ class VersionManager:
return self._prefs
def parse_depend(self, atoms):
+ """Filter the dep string for usefull information"""
matched_atoms = []
matches = self.atom_parser.findall(atoms)
@@ -103,21 +107,21 @@ class VersionManager:
prefs = self.get_prefs()
- low = self.get_lowest(atoms)
+ low = self.get_lowest(atoms) # Lowest vm version we can use
for atom in matched_atoms:
for pref in prefs:
- if pref[0] == low or pref[0] == "*":
- for vm in pref[1]:
- gvm = self.find_vm(vm, atom)
+ if pref[0] == low or pref[0] == "*": # We have a configured preference for this version
+ for vm in pref[1]: # Loop over the prefered once, and check if they are valid
+ gvm = self.find_vm(vm, atom)
if gvm:
- if need_virtual:
- if gvm.provides(need_virtual):
+ if need_virtual: # Package we are finding a vm for needs a virtual
+ if gvm.provides(need_virtual): # we provide the virtual ourself good!
return gvm
else:
- if EnvironmentManager().have_provider(need_virtual):
+ if EnvironmentManager().have_provider(need_virtual): # We have a package available that provides it, will use that
return gvm
else:
- return gvm
+ return gvm # use it!
low = self.get_lowest_atom(matched_atoms)
vm = self.find_vm("", low)
@@ -137,6 +141,7 @@ class VersionManager:
return None
def version_cmp(self, version1, version2):
+ #Parly stolen from portage.py
if version1 == version2:
return 0