müdürden son halini aldık
gereksiz update yapmıyor, daha düzgün falan filan
This commit is contained in:
Executable
+126
@@ -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])
|
||||
+3
-42
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user