aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/jdk-defaults.conf6
-rw-r--r--config/jdk.conf6
-rwxr-xr-xdepend-java-query3
-rw-r--r--src/EnvironmentManager.py7
-rw-r--r--src/PreferenceManager.py135
-rw-r--r--src/PrefsFileParser.py31
-rw-r--r--src/VM.py7
-rw-r--r--src/versionator.py5
8 files changed, 78 insertions, 122 deletions
diff --git a/config/jdk-defaults.conf b/config/jdk-defaults.conf
index e466fd2..0f654fc 100644
--- a/config/jdk-defaults.conf
+++ b/config/jdk-defaults.conf
@@ -1,4 +1,4 @@
# This files contain the default support jdk's
-1.3 gentoo-sdk blackdown-jdk sun-jdk
-1.4 gentoo-sdk blackdown-jdk sun-jdk
-1.5 gentoo-sdk blackdown-jdk sun-jdk
+1.3= gentoo-sdk blackdown-jdk sun-jdk
+1.4= gentoo-sdk blackdown-jdk sun-jdk
+1.5= gentoo-sdk blackdown-jdk sun-jdk
diff --git a/config/jdk.conf b/config/jdk.conf
index 2e81a81..86c2317 100644
--- a/config/jdk.conf
+++ b/config/jdk.conf
@@ -4,6 +4,6 @@
#
# example:
-1.3 sun-jdk-1.4
-1.4 blackdown-jdk
-1.5 sun-jdk
+1.3=sun-jdk-1.4
+1.4=blackdown-jdk
+1.5=sun-jdk
diff --git a/depend-java-query b/depend-java-query
index 24d12ba..bf426c6 100755
--- a/depend-java-query
+++ b/depend-java-query
@@ -45,7 +45,8 @@ def is_sufficient(option, opt, value, parser):
sys.exit(1)
def get_vm(option, opt, value, parser):
- pass
+ vator = versionator()
+ printer._print(vator.get_vm(value))
def get_lowest(option, opt, value, parse):
vator = versionator()
diff --git a/src/EnvironmentManager.py b/src/EnvironmentManager.py
index a6734c3..32c0d6c 100644
--- a/src/EnvironmentManager.py
+++ b/src/EnvironmentManager.py
@@ -94,6 +94,13 @@ class EnvironmentManager:
def get_virtual_machines(self):
return self.virtual_machines
+ def find_vm(self, name):
+ found = []
+ for id, vm in self.virtual_machines.iteritems():
+ if vm.name().startswith(name):
+ found.append(vm)
+ return found
+
def get_packages(self):
return self.packages
diff --git a/src/PreferenceManager.py b/src/PreferenceManager.py
index aec6c9c..f61e9c4 100644
--- a/src/PreferenceManager.py
+++ b/src/PreferenceManager.py
@@ -12,101 +12,46 @@
# Saleem A. <compnerd@gentoo.org>
# April 19, 2005 - Initial Write
-import VM,Errors,versionator
+import VM,Errors
+from java_config.versionator import *
+from java_config.PrefsFileParser import *
+from java_config.EnvironmentManager import *
import os,glob,re
+import os.path
class PreferenceManager:
- def __init__(self):
- self.database = os.path.join('/', 'var', 'db', 'java')
- self.java_versions = [ '1.0', '1.1', '1.2', '1.3', '1.4', '1.5' ]
- self.prefs = {}
-
- load_database()
-
- def load_database(self):
- if not os.path.exists(self.database):
- create_database()
-
- for java_version in java_versions:
- file = os.path.join(self.database, java_version)
- self.prefs[version] = PrefsFileParser(file).get_prefs()
-
- def create_database(self):
- if not os.path.exists(self.database):
- try:
- os.makedirs(os.path.dirname(self.database))
- except IOError:
- raise PermissionError
-
- for java_version in java_versions:
- file = os.path.join(self.database, java_version)
- if not os.path.isfile(file):
- stream = open(file,'w')
- stream.write("# Java Virtual Machine Preferences")
- stream.close()
-
- def get_preferred_vm(self, version, level='0'):
- if not self.prefs.has_key(version):
- raise InvalidPrefsFileError
-
- if len(self.prefs[version]) is 0:
- raise PrefsUndefinedError
-
- return self.prefs[version][level]
-
- def set_preferred_vm(self, version, vm):
- file = os.path.join(self.database, version)
-
- if not self.prefs.has_key(version):
- raise InvalidPrefsFileError
-
- if len(self.prefs[version]) is 0:
- raise PrefsUndefinedError
-
- prefs = self.prefs[version]
-
- index = get_index(prefs, vm)
-
- if index not -1:
- while index > 0:
- prefs[index + 1] = prefs[index]
- index -= 1
- prefs[0] = vm
-
- write_prefs(file, prefs)
-
- def remove_preferred_vm(self, version, vm):
- file = os.path.join(self.database, version)
-
- if not self.prefs.has_key(version):
- raise InvalidPrefsFileError
-
- if len(self.prefs[version]) is 0:
- raise PrefsUndefinedError
-
- prefs = self.prefs[version]
-
- index = get_index(prefs, vm)
-
- if index not -1:
- while index < len(prefs) - 1:
- prefs[index] = prefs[index + 1]
- del prefs[len(prefs) - 1]
-
- write_prefs(file, prefs)
-
- def get_index(self, prefs, key_value):
- for key,value in prefs.iteritems():
- if value == key_value:
- return key
- return -1
-
- def write_prefs(self, file, prefs):
- stream = open(file, 'w')
- stream.write("# Java Virtual Machine Preferences")
-
- length = len(prefs)
- for i in range(0,length):
- stream.write("%i : %s" % (i,prefs[i]))
-
- stream.close()
+ def __init__(self):
+ self.pref_files = ['/etc/java-config/jdk.conf', '/usr/share/java-config/config/jdk-defaults.conf']
+ self.load()
+
+ def load(self):
+ self.prefs = []
+ for file in self.pref_files:
+ if os.path.exists(file):
+ self.prefs = self.prefs + PrefsFile(file).get_prefs()
+
+
+ def get_vm(self, version):
+ for pref in self.prefs:
+ if pref[0] == version:
+ for vm in pref[1]:
+ gvm = self.find_vm(vm,version)
+ if gvm is not None:
+ return gvm
+ return self.find_vm("", version)
+
+ def find_vm(self, vm, version):
+ vm_list = EnvironmentManager().find_vm(vm)
+ #print vm_list
+ vm_list.sort()
+ vm_list.reverse()
+ for vm in vm_list:
+ if vm.version() >= version:
+ return vm
+ return None
+
+
+#man=PreferenceManager()
+#print "1.3: " + str(man.get_vm("1.3"))
+#print "1.4: " + str(man.get_vm("1.4"))
+#print "1.5: " + str(man.get_vm("1.5"))
diff --git a/src/PrefsFileParser.py b/src/PrefsFileParser.py
index df607b3..b6e4697 100644
--- a/src/PrefsFileParser.py
+++ b/src/PrefsFileParser.py
@@ -6,42 +6,35 @@
# Author: Saleem Abdulrasool <compnerd@gentoo.org>
-# ChangeLog
-# Saleem A. <compnerd@gentoo.org>
-# April 19, 2005 - Initial Write
-
from Errors import *
import os
-class ConfigReader:
- config = {}
-
+class PrefsFile:
def __init__(self, file):
- self.config.clear()
+ self.file = file
+ self.config = []
if not os.path.isfile(self.file):
raise InvalidPath(self.file)
- if not os.access(file, os.R_OK):
+ if not os.access(self.file, os.R_OK):
raise PermissionError
stream = open(self.file, 'r')
- read = stream.readline()
-
- while read:
+
+ for line in stream:
# Ignore whitespace lines and comments
- if read.isspace() or read == '' or read.startswidth('#'):
+ if line.isspace() or line == '' or line.startswith('#'):
pass
else:
- read = read.split('\n')[0]
- name, value = read.split(':')
+ version, vms = line.split('=')
+ vms = vms.strip().split(' ')
- self.config[name] = value
-
- read = stream.readline()
+ self.config.append([ version, vms ])
stream.close()
def get_prefs(self):
- return self.config.copy()
+ return self.config
+
# vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3:
diff --git a/src/VM.py b/src/VM.py
index 450a804..7d80b78 100644
--- a/src/VM.py
+++ b/src/VM.py
@@ -27,6 +27,12 @@ class VM:
self.active = active
self.config = EnvFileParser.EnvFileParser(file).get_config()
+ def __cmp__(self, other):
+ return cmp(self.version(), other.version())
+
+ def __str__(self):
+ return self.name()
+
def get_config(self):
return self.config
@@ -73,7 +79,6 @@ class VM:
path = self.query('PATH')
paths = path.split(':')
- paths.remove("${PATH}")
for path in paths:
path = os.path.join(path, executable)
diff --git a/src/versionator.py b/src/versionator.py
index 97f33de..0aeae7a 100644
--- a/src/versionator.py
+++ b/src/versionator.py
@@ -14,6 +14,7 @@
import re
from string import upper
+from java_config.PreferenceManager import *
# Does not handle deps correctly in any way
# Does however do the right thing for the only types of deps we should see
@@ -74,4 +75,8 @@ class versionator:
lowest = version
return lowest
+ def get_vm(self, atoms):
+ lowest = self.get_lowest(atoms)
+ return PreferenceManager().get_vm(lowest)
+
# vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3: