From a1fa4c814cacdd8e8756bca57f70b84504ff9459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Tue, 21 Jun 2005 08:55:44 +0000 Subject: [PATCH] * archive icin gerekli birseyler yazildi --- pisi/util.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/pisi/util.py b/pisi/util.py index 91723112..c49b70a1 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -16,6 +16,53 @@ class FileError(Exception): class UtilError(Exception): pass +# string/list functions + +def strlist(l): + """concatenate string reps of l's elements""" + return string.join(map(lambda x: str(x) + ' ', l)) + +def same(l): + "check if all elements of a sequence are equal" + if len(l)==0: + return True + else: + last = l.pop() + for x in l: + if x!=last: + return False + return True + +def prefix(a, b): + "check if sequence a is a prefix of sequence b" + if len(a)>len(b): + return False + for i in [0:len(a)-1): + if a[i]!=b[i]: + return False + return True + +# path functions + +# I'm not sure how necessary this is. Ahem. +def commonprefix(l): + """an improved version of os.path.commonprefix, + returns a list of path components""" + common = [] + comps = map(os.path.split, l) + for i in [0:min(len,l)-1]: + compi = map(lambda x: x[i], comps) # get ith slice + if same(compi): + common.append(compi[0]) + return common + +# but this one is necessary +def under_path(a, b): + """find if path a is a descendant of b in the directory tree""" + return prefix(os.path.split(a), os.path.split(b)) + +# file/dir functions + def check_file(file, mode = os.F_OK): "shorthand to check if a file exists" if not os.access(file, mode): @@ -93,10 +140,6 @@ def run_batch(cmd): ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines)) return (successful,lines) -def strlist(l): - """concatenate string reps of l's elements""" - return string.join(map(lambda x: str(x) + ' ', l)) - def do_patch(patch, p=0): """simple function to apply patches..""" check_file(patch)