Index: src/java-config-2 =================================================================== --- src/java-config-2 (revision 9031) +++ src/java-config-2 (working copy) @@ -181,21 +181,18 @@ def set_system_vm(option, opt, value, pa if not vm: fatalError("Could not find a vm matching: %s" % value) else: - if os.getuid() is 0: - try: - manager.set_system_vm(vm) - printer._print("Now using %s as your generation-2 system JVM" % (vm) ) - if vm.is_build_only(): - printer._printWarning("%s is marked as a build-only JVM. Using this vm is not recommended. " % (vm)) - printer._printWarning("Please see http://www.gentoo.org/doc/en/java.xml#build-only for more information.") - except PermissionError: - fatalError("You do not have enough permissions to set the system VM!") - except EnvironmentUndefinedError: - fatalError("The selected VM is missing critical environment variables.") - except InvalidConfigError as e: - fatalError("Target file already exists and is not a symlink: %s" % e.file) - else: + try: + manager.set_system_vm(vm) + printer._print("Now using %s as your generation-2 system JVM" % (vm) ) + if vm.is_build_only(): + printer._printWarning("%s is marked as a build-only JVM. Using this vm is not recommended. " % (vm)) + printer._printWarning("Please see http://www.gentoo.org/doc/en/java.xml#build-only for more information.") + except PermissionError: fatalError("You do not have enough permissions to set the system VM!") + except EnvironmentUndefinedError: + fatalError("The selected VM is missing critical environment variables.") + except InvalidConfigError as e: + fatalError("Target file already exists and is not a symlink: %s" % e.file) def set_user_vm(option, opt, value, parser): vm = manager.get_vm(value) @@ -231,16 +228,13 @@ def user_classpath_target(): # Deprecated def set_system_classpath(option, opt, value, parser): deprecation_notice() - if os.getuid() is 0: - pkgs = value.split(',') - manager.set_classpath(system_classpath_target(), pkgs) + pkgs = value.split(',') + manager.set_classpath(system_classpath_target(), pkgs) - for package in pkgs: - printer._printError("Package %s was not found!" % package) + for package in pkgs: + printer._printError("Package %s was not found!" % package) - update_env() - else: - fatalError("You do not have enough permissions to set the system classpath!") + update_env() # Deprecated def set_user_classpath(option, opt, value, parser): @@ -256,16 +250,13 @@ def set_user_classpath(option, opt, valu # Deprecated def append_system_classpath(option, opt, value, parser): deprecation_notice() - if os.getuid() is 0: - pkgs = value.split(',') - manager.append_classpath(system_classpath_target(), pkgs) + pkgs = value.split(',') + manager.append_classpath(system_classpath_target(), pkgs) - for package in pkgs: - printer._printError("Package %s was not found!" % package) + for package in pkgs: + printer._printError("Package %s was not found!" % package) - update_env() - else: - fatalError("You do not have enough permissioins to append to the system classpath!") + update_env() # Deprecated def append_user_classpath(option, opt, value, parser): @@ -281,11 +272,8 @@ def append_user_classpath(option, opt, v # Deprecated def clean_system_classpath(option, opt, value, parser): deprecation_notice() - if os.getuid() is 0: - manager.clean_classpath(system_classpath_target()) - update_env() - else: - fatalError("You do not have enough permissions to clean the system classpath!") + manager.clean_classpath(system_classpath_target()) + update_env() # Deprecated def clean_user_classpath(option, opt, value, parser): Index: src/java_config_2/EnvironmentManager.py =================================================================== --- src/java_config_2/EnvironmentManager.py (revision 9031) +++ src/java_config_2/EnvironmentManager.py (working copy) @@ -13,7 +13,7 @@ from itertools import chain from os.path import basename, dirname from glob import glob -import os, re, sys +import errno, os, re, sys class EnvironmentManager(object): """This is the central class, which manages all information from the 'environment'""" @@ -34,20 +34,27 @@ class EnvironmentManager(object): self.all_packages_loaded = False self.packages = {} self.virtuals = {} + self.root = os.environ.get('ROOT', '/') + if not self.root.endswith('/'): + self.root += '/' def __call__(self): return self + def root_path(self, path): + return os.path.join(self.root, path[1:]) + def load_vms(self): """Load all the vm files, and check for correctness""" self.virtual_machines = {} - if os.path.isdir(self.vms_path): + root_vms_path = self.root_path(self.vms_path) + if os.path.isdir(root_vms_path): count = 1 - filelist = os.listdir(self.vms_path) + filelist = os.listdir(root_vms_path) filelist.sort() for file in filelist: - conf = os.path.join(self.vms_path,file) + conf = os.path.join(root_vms_path, file) vm = None try: @@ -237,16 +244,23 @@ class EnvironmentManager(object): self.set_vm(vm, self.system_vm_link()) def set_vm(self, vm, target): - sym_dir = dirname(target) - if not os.path.isdir(sym_dir): - os.makedirs(sym_dir) - - if os.path.islink(target): - os.remove(target) - elif os.path.exists(target): - raise InvalidConfigError(target) + root_target = self.root_path(target) + sym_dir = dirname(root_target) + try: + if not os.path.isdir(sym_dir): + os.makedirs(sym_dir) - os.symlink('/usr/lib/jvm/'+vm.name(),target) + if os.path.islink(root_target): + os.remove(target) + elif os.path.exists(root_target): + raise InvalidConfigError(root_target) + + os.symlink('/usr/lib/jvm/' + vm.name(), root_target) + except OSError as ex: + if ex.errno == errno.EACCES: + raise PermissionError + else: + raise ex def vm_links(self): # Don't try to use user-vm if HOME is undefined @@ -270,9 +284,10 @@ class EnvironmentManager(object): def clean_classpath(self, targets): for target in targets: - if os.path.isfile(target['file']): + root_file = self.root_path(target['file']) + if os.path.isfile(root_file): try: - os.remove(target['file']) + os.remove(root_file) except IOError: raise PermissionError @@ -456,12 +471,13 @@ class EnvironmentManager(object): def write_classpath(self, targets, classpath): for target in targets: - dir = dirname(target['file']) + root_file = self.root_path(target['file']) + dir = dirname(root_file) if not os.path.isdir(dir): os.makedirs(dir) try: - stream = open(target['file'], 'w') + stream = open(root_file, 'w') except IOError: raise PermissionError