aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/java_config/EnvironmentManager.py')
-rw-r--r--src/java_config/EnvironmentManager.py92
1 files changed, 21 insertions, 71 deletions
diff --git a/src/java_config/EnvironmentManager.py b/src/java_config/EnvironmentManager.py
index 6a8a0ab..47f6e31 100644
--- a/src/java_config/EnvironmentManager.py
+++ b/src/java_config/EnvironmentManager.py
@@ -30,9 +30,8 @@ class EnvironmentManager:
if os.path.isdir(self.vms_path):
count = 1
for file in os.listdir(self.vms_path):
- conf = os.path.join(self.vms_path, file)
-
if file.startswith("20"):
+ conf = os.path.join(self.vms_path,file)
vm = None
try:
@@ -47,36 +46,15 @@ class EnvironmentManager:
def load_packages(self):
self.packages = []
- for package in iter(glob(pkg_path)):
+ for package in iter(glob(self.pkg_path)):
self.packages.append(Package(package, basename(dirname(package))))
def load_active_vm(self):
- environ_path = [
- os.path.join(os.environ.get('HOME'), '.gentoo', 'java'),
- os.path.join('/', 'etc', 'env.d', '20java')
- ]
-
- java_home = None
-
- for file in environ_path:
- try:
- stream = open(file, 'r')
- except IOError:
- continue
-
- read = stream.readline()
- while read:
- if read.strip().startswith('JAVA_HOME'):
- stream.close()
- java_home = read.split('=', 1)[-1].strip()
- break
- else:
- read = stream.readline()
- stream.close()
-
- for vm in self.get_virtual_machines().itervalues():
- if vm.query('JAVA_HOME') == java_home:
- self.active = vm
+ for link in self.vm_links():
+ if os.path.islink(link):
+ vm_name = os.readlink(link)
+ vm = self.get_vm(vm_name)
+ self.active = vm
return vm
raise InvalidVMError
@@ -150,54 +128,26 @@ class EnvironmentManager:
else:
return None
- def create_env_entry(self, vm, stream, render="%s=%s\n"):
- stream.write("# Autogenerated by java-config\n")
- stream.write("# Java Virtual Machine: %s\n\n" % vm.query('VERSION'))
+ def set_user_vm(self, vm):
+ self.set_vm(vm, self.user_vm_link())
- try:
- ENV_VARS = vm.query('ENV_VARS')
- for (item, value) in vm.get_config().iteritems():
- if item in ENV_VARS:
- stream.write(render % (item, value))
- except IOError:
- raise PermissionError
- except EnvironmentUndefinedError:
- raise EnvironmentUndefinedError
+ def set_system_vm(self, vm):
+ self.set_vm(vm, self.system_vm_link())
- def set_vm(self, vm, sh_env_file, csh_env_file=None):
+ def set_vm(self, vm, target):
+ if os.path.islink(target):
+ os.remove(target)
+ os.symlink(vm.name(),target)
- # Create the SH environment file
- if sh_env_file is not None:
- try:
- stream = open(sh_env_file, 'w')
- except IOError:
- raise PermissionError
+ def vm_links(self):
+ return [ self.user_vm_link(), self.system_vm_link() ]
- try:
- self.create_env_entry(vm, stream, "%s=%s\n")
- except IOError:
- stream.close()
- raise PermissionError
- except EnvironmentUndefinedError:
- stream.close();
- raise EnvironmentUndefinedError
+ def user_vm_link(self):
+ return os.path.join(os.environ.get('HOME'), '.gentoo/user-vm')
- stream.close()
+ def system_vm_link(self):
+ return '/usr/share/java-config/vms/system-vm'
- # Create the CSH environment file
- if csh_env_file is not None:
- try:
- stream = open(csh_env_file, 'w')
- except IOError:
- raise PermissionError
-
- try:
- self.create_env_entry(vm, stream, "setenv %s %s\n")
- except IOError:
- stream.close()
- raise PermissionError
-
- stream.close()
def clean_classpath(self, env_file):
if os.path.isfile(env_file):