From 00b7cf3e305e0ea2c4aa6996a545490d537aad3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrer=20=C3=96zen?= Date: Fri, 5 May 2006 12:31:44 +0000 Subject: [PATCH] =?UTF-8?q?m=C3=BCd=C3=BCrden=20son=20halini=20ald=C4=B1k?= =?UTF-8?q?=20gereksiz=20update=20yapm=C4=B1yor,=20daha=20d=C3=BCzg=C3=BCn?= =?UTF-8?q?=20falan=20filan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/environment.py | 126 ++++++++++++++++++++++++++++++++++++++++++++ pisi/util.py | 45 ++-------------- 2 files changed, 129 insertions(+), 42 deletions(-) create mode 100755 pisi/environment.py diff --git a/pisi/environment.py b/pisi/environment.py new file mode 100755 index 00000000..919a351a --- /dev/null +++ b/pisi/environment.py @@ -0,0 +1,126 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2006, TUBITAK/UEKAE +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. Please read the COPYING file. +# + +import sys +import os +import subprocess +import getopt + +header = "### This file is automatically generated by update-environment" + +header_note = """ +# +# Please do not edit this file directly. If you want to change +# anything, please take a look at the files in /etc/env.d +# and read the Pardus initialization system documentation. +# +# Bu otomatik olarak oluşturulmuş bir dosyadır. +# Lütfen bu dosyayı elle değiştirmeyin. Değiştirmek istediğiniz +# şeyler varsa, /etc/env.d dizinindeki dosyalara ve Pardus +# açılış sistemi belgesine bakın. +# +""" + +specials = ( + "KDEDIRS", + "PATH", + "CLASSPATH", + "LDPATH", + "MANPATH", + "INFOPATH", + "ROOTPATH", + "CONFIG_PROTECT", + "CONFIG_PROTECT_MASK", + "PRELINK_PATH", + "PRELINK_PATH_MASK", + "PYTHONPATH", + "ADA_INCLUDE_PATH", + "ADA_OBJECTS_PATH", +) + +def read_env_d(envdir): + dict = {} + + paths = [] + for name in os.listdir(envdir): + path = os.path.join(envdir, name) + # skip dirs (.svn, .cvs, etc) + if os.path.isdir(path): + continue + # skip backup and version control files + if name.endswith("~") or name.endswith(".bak") or name.endswith(",v"): + continue + # skip pisi's .oldconfig files + if name.endswith(".oldconfig"): + continue + paths.append(path) + paths.sort() + + for path in paths: + for line in file(path): + if line == "" or line.startswith("#"): + continue + + line = line.rstrip("\n") + if "=" in line: + key, value = line.split("=", 1) + key = key.strip() + value = value.strip() + if value.startswith('"') or value.startswith("'"): + value = value[1:-1] + + # Merge for special variables, override for others + if key in specials: + if dict.has_key(key): + dict[key].extend(value.split(":")) + else: + dict[key] = value.split(":") + else: + dict[key] = value + + return dict + +def generate_profile_env(envdict, format='export %s="%s"\n'): + profile = "" + keys = envdict.keys() + keys.sort() + for key in keys: + if key != "LDPATH": + tmp = envdict[key] + if isinstance(tmp, list): + tmp = ":".join(tmp) + profile += format % (key, tmp) + return header + header_note + profile + +def generate_ld_so_conf(envdict): + ldpaths = envdict["LDPATH"] + tmp = "\n".join(ldpaths) + return tmp + "\n" + +def update_file(path, content): + if os.path.exists(path): + data = file(path).read() + if data == content: + return False + f = file(path, "w") + f.write(content) + f.close() + return True + +def update_environment(prefix): + join = os.path.join + + env = read_env_d(join(prefix, "etc/env.d")) + update_file(join(prefix, "etc/profile.env"), generate_profile_env(env)) + update_file(join(prefix, "etc/csh.env"), generate_profile_env(env, 'setenv %s %s\n')) + if env.has_key("LDPATH"): + if update_file(join(prefix, "etc/ld.so.conf"), generate_ld_so_conf(env)): + subprocess.call(["/sbin/ldconfig", "-X", "-r", prefix]) diff --git a/pisi/util.py b/pisi/util.py index 2c5efe58..d4dd55b1 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -614,54 +614,15 @@ def is_package_name(fn, package_name = None): return False def env_update(): - + import pisi.environment ctx.ui.info(_('Updating environment...')) - env_dir = join_path(ctx.config.dest_dir(), "/etc/env.d") - profile_file = join_path(ctx.config.dest_dir(), "/etc/profile.env") - ldconf_file = join_path(ctx.config.dest_dir(), "/etc/ld.so.conf") + env_dir = join_path(ctx.config.dest_dir(), "/etc/env.d") if not os.path.exists(env_dir): os.makedirs(env_dir, 0755) - list = [] - for file in os.listdir(env_dir): - if not os.path.isdir(join_path(env_dir, file)): - list.append(file) + pisi.environment(ctx.config.dest_dir()) - list.sort() - - keys = {} - for file in list: - f = open(join_path(env_dir, file), "r") - for line in f: - if not re.search("^#", line.strip()): - currentLine = line.strip().split("=") - - try: - if keys.has_key(currentLine[0]): - keys[currentLine[0]] += ":" + currentLine[1].replace("\"", "") - else: - keys[currentLine[0]] = currentLine[1].replace("\"", "") - except IndexError: - pass - - # generate profile.env - f = open(profile_file, "w") - for key in keys: - f.write("export %s=\"%s\"\n" % (key, keys[key])) - f.close() - - # generate ld.so.conf - f = open(ldconf_file, "w") - if keys.has_key("LDPATH"): - for path in keys["LDPATH"].split(":"): - f.write("%s\n" % path) - f.close() - - # run ldconfig - if run_batch("/sbin/ldconfig -X -r %s" % ctx.config.dest_dir())[0]: - raise Error(_("ERROR: /sbin/ldconfig -X -r %s failed") % ctx.config.dest_dir()) - def pure_package_name(package_name): "return pure package name from given string" "ex: package_name=tasma-1.0.3-5-2.pisi, returns tasma"