gmyth-stream/server/0.1/lib.py
author melunko
Wed May 16 13:35:11 2007 +0100 (2007-05-16)
branchtrunk
changeset 663 338476853df3
permissions -rw-r--r--
[svn r669] If local hostname is not found, we consider it as a default string
     1 import time
     2 import logging
     3 import os
     4 import stat
     5 
     6 ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
     7 
     8 def now():
     9     return time.strftime("%Y-%m-%d %H:%M:%S");
    10 
    11 def log(msg):
    12     logging.log(logging.DEBUG, msg)
    13     new_msg = "[%s] %s" % (now(), msg)
    14     return new_msg
    15 
    16 
    17 bin_path_list = os.environ["PATH"].split(os.pathsep)
    18 def which(prg):
    19     for d in bin_path_list:
    20         path = os.path.join(d, prg)
    21         if os.path.exists(path):
    22             st = os.stat(path)
    23             if st[stat.ST_MODE] & 0111:
    24                 return path
    25     return ""
    26 
    27 def list_media_files(directory, file_list):
    28     for root, dirs, files in os.walk(directory):
    29         for name in files:
    30             if os.path.splitext(name)[1].strip(".") in ext:
    31                 media = os.path.join(root,name)
    32                 if media not in file_list:
    33                     file_list.append(os.path.join(root,name))
    34 
    35     return True
    36