+ resolveFilename(SCOPE_CONFIG, "userbouquet.favourites.radio")
+ resolveFilename(SCOPE_CONFIG, "bouquets.radio")
+
+# returns a list of tuples containing pathname and filename matching the given pattern
+# example-pattern: match all txt-files: ".*\.txt$"
+def crawlDirectory(directory, pattern):
+ expression = compile(pattern)
+ list = []
+ for root, dirs, files in walk(directory):
+ for file in files:
+ if expression.match(file) is not None:
+ list.append((root, file))
+ return list
+
+def copyfile(src, dst):
+ try:
+ f1 = open(src, "rb")
+ if os_path.isdir(dst):
+ dst = os_path.join(dst, os_path.basename(src))
+ f2 = open(dst, "w+b")
+ while True:
+ buf = f1.read(16*1024)
+ if not buf:
+ break
+ f2.write(buf)
+ st = os_stat(src)
+ mode = S_IMODE(st.st_mode)
+ if have_chmod:
+ chmod(dst, mode)
+ if have_utime:
+ utime(dst, (st.st_atime, st.st_mtime))
+ except:
+ print "copy", src, "to", dst, "failed!"
+ return -1
+ return 0
+
+def copytree(src, dst, symlinks=False):
+ names = listdir(src)
+ if os_path.isdir(dst):
+ dst = os_path.join(dst, os_path.basename(src))
+ if not os_path.isdir(dst):
+ mkdir(dst)
+ else:
+ makedirs(dst)
+ for name in names:
+ srcname = os_path.join(src, name)
+ dstname = os_path.join(dst, name)
+ try:
+ if symlinks and os_path.islink(srcname):
+ linkto = readlink(srcname)
+ symlink(linkto, dstname)
+ elif os_path.isdir(srcname):
+ copytree(srcname, dstname, symlinks)
+ else:
+ copyfile(srcname, dstname)
+ except:
+ print "dont copy srcname (no file or link or folder)"
+ try:
+ st = os_stat(src)
+ mode = S_IMODE(st.st_mode)
+ if have_chmod:
+ chmod(dst, mode)
+ if have_utime:
+ utime(dst, (st.st_atime, st.st_mtime))
+ except:
+ print "copy stats for", src, "failed!"
+
+def getSize(path, pattern=".*"):
+ path_size = 0
+ if os_path.isdir(path):
+ files = crawlDirectory(path, pattern)
+ for file in files:
+ filepath = os_path.join(file[0], file[1])
+ path_size += os_path.getsize(filepath)
+ elif os_path.isfile(path):
+ path_size = os_path.getsize(path)
+ return path_size