* archive icin gerekli birseyler yazildi
This commit is contained in:
+47
-4
@@ -16,6 +16,53 @@ class FileError(Exception):
|
|||||||
class UtilError(Exception):
|
class UtilError(Exception):
|
||||||
pass
|
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):
|
def check_file(file, mode = os.F_OK):
|
||||||
"shorthand to check if a file exists"
|
"shorthand to check if a file exists"
|
||||||
if not os.access(file, mode):
|
if not os.access(file, mode):
|
||||||
@@ -93,10 +140,6 @@ def run_batch(cmd):
|
|||||||
ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines))
|
ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines))
|
||||||
return (successful,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):
|
def do_patch(patch, p=0):
|
||||||
"""simple function to apply patches.."""
|
"""simple function to apply patches.."""
|
||||||
check_file(patch)
|
check_file(patch)
|
||||||
|
|||||||
Reference in New Issue
Block a user