util fonksiyonlarını gruplandır.
Util içerisinde standard python kütüphanesi ile gerçekleştirilebilecek şeyler var. Onları teker teker düzelteceğim, herhangi birini geri almak istersek kolay olsun diye tek tek yapacağım... Bilginize...
This commit is contained in:
+31
-17
@@ -6,12 +6,14 @@
|
|||||||
# S. Caglar Onur <caglar@uludag.org.tr>
|
# S. Caglar Onur <caglar@uludag.org.tr>
|
||||||
# A. Murat Eren <meren@uludag.org.tr>
|
# A. Murat Eren <meren@uludag.org.tr>
|
||||||
|
|
||||||
|
# standard python modules
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import sha
|
import sha
|
||||||
import shutil
|
import shutil
|
||||||
import statvfs
|
import statvfs
|
||||||
|
|
||||||
|
# pisi modules
|
||||||
from ui import ui
|
from ui import ui
|
||||||
|
|
||||||
class FileError(Exception):
|
class FileError(Exception):
|
||||||
@@ -20,7 +22,10 @@ class FileError(Exception):
|
|||||||
class UtilError(Exception):
|
class UtilError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# string/list functions
|
|
||||||
|
#########################
|
||||||
|
# string/list functions #
|
||||||
|
#########################
|
||||||
|
|
||||||
def unzip(seq):
|
def unzip(seq):
|
||||||
return zip(*seq)
|
return zip(*seq)
|
||||||
@@ -65,7 +70,27 @@ def remove_prefix(a,b):
|
|||||||
assert prefix(a,b)
|
assert prefix(a,b)
|
||||||
return b[len(a):]
|
return b[len(a):]
|
||||||
|
|
||||||
# path functions
|
|
||||||
|
##############################
|
||||||
|
# Process Releated Functions #
|
||||||
|
##############################
|
||||||
|
|
||||||
|
def run_batch(cmd):
|
||||||
|
"""run command non-interactively and report return value and output"""
|
||||||
|
ui.info('running ' + cmd)
|
||||||
|
a = os.popen(cmd)
|
||||||
|
lines = a.readlines()
|
||||||
|
ret = a.close()
|
||||||
|
ui.debug('return value ' + ret)
|
||||||
|
successful = ret == None
|
||||||
|
if not successful:
|
||||||
|
ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines))
|
||||||
|
return (successful,lines)
|
||||||
|
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Path Processing Functions #
|
||||||
|
#############################
|
||||||
|
|
||||||
def splitpath(a):
|
def splitpath(a):
|
||||||
"""split path into components and return as a list
|
"""split path into components and return as a list
|
||||||
@@ -100,7 +125,10 @@ def removepathprefix(prefix, path):
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# file/dir functions
|
|
||||||
|
####################################
|
||||||
|
# File/Directory Related 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"
|
||||||
@@ -178,19 +206,6 @@ def sha1_file(filename):
|
|||||||
except IOError:
|
except IOError:
|
||||||
return "0"
|
return "0"
|
||||||
|
|
||||||
|
|
||||||
def run_batch(cmd):
|
|
||||||
"""run command non-interactively and report return value and output"""
|
|
||||||
ui.info('running ' + cmd)
|
|
||||||
a = os.popen(cmd)
|
|
||||||
lines = a.readlines()
|
|
||||||
ret = a.close()
|
|
||||||
ui.debug('return value ' + ret)
|
|
||||||
successful = ret == None
|
|
||||||
if not successful:
|
|
||||||
ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines))
|
|
||||||
return (successful,lines)
|
|
||||||
|
|
||||||
def uncompress(patchFile, compressType="gz", targetDir=None):
|
def uncompress(patchFile, compressType="gz", targetDir=None):
|
||||||
"""uncompresses a file and returns the path of the uncompressed
|
"""uncompresses a file and returns the path of the uncompressed
|
||||||
file"""
|
file"""
|
||||||
@@ -213,7 +228,6 @@ def uncompress(patchFile, compressType="gz", targetDir=None):
|
|||||||
|
|
||||||
def do_patch(sourceDir, patchFile, p=0):
|
def do_patch(sourceDir, patchFile, p=0):
|
||||||
"""simple function to apply patches.."""
|
"""simple function to apply patches.."""
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(sourceDir)
|
os.chdir(sourceDir)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user