docstring fixes part II

This commit is contained in:
Gürer Özen
2006-12-07 17:07:31 +00:00
parent eee3145059
commit 2a51d2c3b9
+31 -22
View File
@@ -257,8 +257,11 @@ def absolute_path(path):
return comps[0] == '' return comps[0] == ''
def join_path(a, *p): def join_path(a, *p):
"""Join two or more pathname components, inserting '/' as needed""" """Join two or more pathname components.
"""The python original version has a silly logic"""
Python os.path.join cannot handle '/' at the start of latter components.
"""
path = a path = a
for b in p: for b in p:
b = b.lstrip('/') b = b.lstrip('/')
@@ -273,34 +276,33 @@ def join_path(a, *p):
#################################### ####################################
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):
raise FileError("File " + file + " not found") raise FileError("File " + file + " not found")
return True return True
# FIXME: check_dir is not a good name considering it can also create the dir
def check_dir(dir): def check_dir(dir):
"""check if directory exists, and create if it doesn't. """Make sure given directory path exists."""
works recursively""" # FIXME: What is first strip doing there?
dir = dir.strip().rstrip("/") dir = dir.strip().rstrip("/")
if not os.access(dir, os.F_OK): if not os.access(dir, os.F_OK):
os.makedirs(dir) os.makedirs(dir)
def clean_dir(path): def clean_dir(path):
"Remove all content of a directory (top)" """Remove all content of a directory."""
# don't reimplement the wheel
if os.path.exists(path): if os.path.exists(path):
shutil.rmtree(path) shutil.rmtree(path)
def creation_time(file): def creation_time(file):
"""returns the creation time of the given file""" """Return the creation time of the given file."""
if check_file(file): if check_file(file):
import time import time
st = os.stat(file) st = os.stat(file)
return time.localtime(st.st_ctime) return time.localtime(st.st_ctime)
def dir_size(dir): def dir_size(dir):
""" calculate the size of files under a dir """Calculate the size of files under a directory."""
based on the os module example"""
# It's really hard to give an approximate value for package's # It's really hard to give an approximate value for package's
# installed size. Gettin a sum of all files' sizes if far from # installed size. Gettin a sum of all files' sizes if far from
# being true. Using 'du' command (like Debian does) can be a # being true. Using 'du' command (like Debian does) can be a
@@ -323,7 +325,7 @@ def dir_size(dir):
return sum( sizes() ) return sum( sizes() )
def copy_file(src,dest): def copy_file(src,dest):
"""copy source file to destination file""" """Copy source file to the destination file."""
check_file(src) check_file(src)
check_dir(os.path.dirname(dest)) check_dir(os.path.dirname(dest))
shutil.copyfile(src, dest) shutil.copyfile(src, dest)
@@ -332,7 +334,7 @@ def is_ar_file(file_path):
return open(file_path).readline().strip() == '!<arch>' return open(file_path).readline().strip() == '!<arch>'
def clean_ar_timestamps(ar_file): def clean_ar_timestamps(ar_file):
"""clean the timestamps of the ar files""" """Zero all timestamps in the ar files."""
if not is_ar_file(ar_file): if not is_ar_file(ar_file):
return return
content = open(ar_file).readlines() content = open(ar_file).readlines()
@@ -348,12 +350,15 @@ def clean_ar_timestamps(ar_file):
# as it stands, it seems to be a kludge to solve # as it stands, it seems to be a kludge to solve
# an unrelated problem # an unrelated problem
def get_file_hashes(top, excludePrefix=None, removePrefix=None): def get_file_hashes(top, excludePrefix=None, removePrefix=None):
"""Generator function iterates over a toplevel path and returns the """Iterate over given path and return a list of file hashes.
Generator function iterates over a toplevel path and returns the
(filePath, sha1Hash) tuples for all files. If excludePrefixes list (filePath, sha1Hash) tuples for all files. If excludePrefixes list
is given as a parameter, function will exclude the filePaths is given as a parameter, function will exclude the filePaths
matching those prefixes. The removePrefix string parameter will be matching those prefixes. The removePrefix string parameter will be
used to remove prefix from filePath while matching excludes, if used to remove prefix from filePath while matching excludes, if
given.""" given.
"""
def sha1_sum(f, data=False): def sha1_sum(f, data=False):
if not data and f.endswith('.a'): if not data and f.endswith('.a'):
@@ -463,8 +468,7 @@ def sha1_data(data):
raise Error(_("Cannot calculate SHA1 hash of given data")) raise Error(_("Cannot calculate SHA1 hash of given data"))
def uncompress(patchFile, compressType="gz", targetDir=None): def uncompress(patchFile, compressType="gz", targetDir=None):
"""uncompresses a file and returns the path of the uncompressed """Uncompress the file and return the new path."""
file"""
if targetDir: if targetDir:
filePath = join_path(targetDir, filePath = join_path(targetDir,
os.path.basename(patchFile)) os.path.basename(patchFile))
@@ -600,8 +604,11 @@ def package_name(name, version, release, build, prependSuffix=True):
return fn return fn
def is_package_name(fn, package_name = None): def is_package_name(fn, package_name = None):
"check if fn is a valid filename for given package_name" """Check if fn is a valid filename for given package_name.
"if not given a package name, see if fn fits the package name rules"
If not given a package name, see if fn fits the package name rules
"""
if (package_name==None) or fn.startswith(package_name + '-'): if (package_name==None) or fn.startswith(package_name + '-'):
if fn.endswith(ctx.const.package_suffix): if fn.endswith(ctx.const.package_suffix):
# get version string, skip separator '-' # get version string, skip separator '-'
@@ -626,10 +633,12 @@ def env_update():
pisi.environment.update_environment(ctx.config.dest_dir()) pisi.environment.update_environment(ctx.config.dest_dir())
def parse_package_name(package_name): def parse_package_name(package_name):
"return package name and version string" """Separate package name and version string.
"ex: package_name=tasma-1.0.3-5-2, returns (tasma, 1.0.3-5-2)"
example: tasma-1.0.3-5-2 -> (tasma, 1.0.3-5-2)
# but we should handle package names like 855resolution
"""
# We should handle package names like 855resolution
name = [] name = []
for part in package_name.split("-"): for part in package_name.split("-"):
if name != [] and part[0] in string.digits: if name != [] and part[0] in string.digits: