diff options
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | setup.py | 6 | ||||
-rwxr-xr-x | src/java-config | 26 | ||||
-rw-r--r-- | src/java_config/EnvironmentManager.py | 78 |
4 files changed, 32 insertions, 79 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index e910148..243b009 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ recursive-include man/ * recursive-include config/ * +include src/env @@ -18,11 +18,13 @@ setup ( url = 'http://www.gentoo.org', packages = ['java_config'], package_dir = { 'java_config' : 'src/java_config' }, - scripts = ['src/java-config','src/depend-java-query'], + scripts = ['src/java-config','src/depend-java-query','src/run-java-tool'], data_files = [ ('man/man1', ["man/java-config.1"]), ('share/java-config/config', ["config/jdk-defaults.conf"]), - ('/etc/java-config/', ["config/jdk.conf"]) + ('/etc/java-config/', ["config/jdk.conf"]), + ('/etc/env.d/',["config/20java-config"]), + ('share/java-config/', ["config/symlink-tools", "src/env"]) ] ) diff --git a/src/java-config b/src/java-config index 936a080..c2cca4b 100755 --- a/src/java-config +++ b/src/java-config @@ -141,16 +141,13 @@ def print_environment(option, opt, value, parser): def set_system_vm(option, opt, value, parser): vm = manager.get_vm(value) - # TODO: MAKE THIS MODULAR!! - config = os.path.join('/', 'etc', 'env.d', '20java') if os.getuid() is 0: if vm.is_jre(): printer._printWarning("The specified VM is a JRE! It is suggested you use a JDK!") try: - manager.set_vm(vm, config, None) - update_env() + manager.set_system_vm(vm) except PermissionError: printer._printError("You do not have enough permissions to set the system VM!") except EnvironmentUndefinedError: @@ -160,24 +157,14 @@ def set_system_vm(option, opt, value, parser): def set_user_vm(option, opt, value, parser): vm = manager.get_vm(value) - # TODO: MAKE THIS MODULAR!! - config_sh = os.path.join(os.environ.get("HOME"), '.gentoo', 'java.sh') - config_csh = os.path.join(os.environ.get("HOME"), '.gentoo', 'java.csh') if os.getuid() is 0: printer._printError("The user 'root' should always use the System VM") else: - # TODO: MAKE THIS MODULAR!! - env_dir = os.path.join(os.environ.get("HOME"), '.gentoo') - - if os.path.exists(env_dir) and not os.path.isdir(env_dir): - printer._printError(os.path.join(os.environ.get("HOME"), '.gentoo') + " exists, but is not a directory!") - else: - try: - manager.set_vm(vm, config_sh, config_csh) - update_env() - except PermissionError: - printer._printError("You do not have enough permissions to set the VM!") + try: + manager.set_user_vm(vm) + except PermissionError: + printer._printError("You do not have enough permissions to set the VM!") def set_system_classpath(option, opt, value, parser): # TODO: MAKE THIS MODULAR!! @@ -219,7 +206,6 @@ def clean_system_classpath(option, opt, value, parser): if os.getuid() is 0: manager.clean_classpath(env_file) - update_env() else: printer._printError("You do not have enough permissions to clean the system classpath!") @@ -245,7 +231,7 @@ def select_vm(option, opt, value, parser): def update_env(): printer._print(getoutput("/usr/sbin/env-update")) - printer._printAlert("If you want to use java in your current session, you should update\nyour environment by running:\nsource /etc/profile") + printer._printAlert("If you want the changes too take effect in your current session, you should update\nyour environment by running:\nsource /etc/profile") diff --git a/src/java_config/EnvironmentManager.py b/src/java_config/EnvironmentManager.py index 6f7adf6..1376b50 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: @@ -51,32 +50,11 @@ class EnvironmentManager: 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 @@ -163,41 +141,27 @@ class EnvironmentManager: raise PermissionError except EnvironmentUndefinedError: raise EnvironmentUndefinedError + + def set_user_vm(self, vm): + self.set_vm(vm, self.user_vm_link()) - def set_vm(self, vm, sh_env_file, csh_env_file=None): - - # Create the SH environment file - if sh_env_file is not None: - try: - stream = open(sh_env_file, 'w') - except IOError: - raise PermissionError + def set_system_vm(self, vm): + self.set_vm(vm, 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 set_vm(self, vm, target): + if os.path.islink(target): + os.remove(target) + os.symlink(vm.name(),target) - stream.close() + def vm_links(self): + return [ self.user_vm_link(), self.system_vm_link() ] - # Create the CSH environment file - if csh_env_file is not None: - try: - stream = open(csh_env_file, 'w') - except IOError: - raise PermissionError + def user_vm_link(self): + return os.path.join(os.environ.get('HOME'), '.gentoo/user-vm') - try: - self.create_env_entry(vm, stream, "setenv %s %s\n") - except IOError: - stream.close() - raise PermissionError + def system_vm_link(self): + return '/usr/share/java-config/vms/system-vm' - stream.close() def clean_classpath(self, env_file): if os.path.isfile(env_file): |