gmyth-stream/server/0.1/lib.py
author morphbr
Thu May 17 19:22:03 2007 +0100 (2007-05-17)
branchtrunk
changeset 684 cabd7221c449
permissions -rw-r--r--
[svn r690] * GMyth-Streamer
- Bug fix regarding transcoders status
morphbr@565
     1
import time
morphbr@565
     2
import logging
morphbr@565
     3
import os
morphbr@565
     4
import stat
morphbr@565
     5
morphbr@565
     6
ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
morphbr@565
     7
morphbr@565
     8
def now():
morphbr@565
     9
    return time.strftime("%Y-%m-%d %H:%M:%S");
morphbr@565
    10
morphbr@565
    11
def log(msg):
morphbr@565
    12
    logging.log(logging.DEBUG, msg)
morphbr@565
    13
    new_msg = "[%s] %s" % (now(), msg)
morphbr@565
    14
    return new_msg
morphbr@565
    15
morphbr@565
    16
morphbr@565
    17
bin_path_list = os.environ["PATH"].split(os.pathsep)
morphbr@565
    18
def which(prg):
morphbr@565
    19
    for d in bin_path_list:
morphbr@565
    20
        path = os.path.join(d, prg)
morphbr@565
    21
        if os.path.exists(path):
morphbr@565
    22
            st = os.stat(path)
morphbr@565
    23
            if st[stat.ST_MODE] & 0111:
morphbr@565
    24
                return path
morphbr@565
    25
    return ""
morphbr@565
    26
morphbr@565
    27
def list_media_files(directory, file_list):
morphbr@565
    28
    for root, dirs, files in os.walk(directory):
morphbr@565
    29
        for name in files:
morphbr@565
    30
            if os.path.splitext(name)[1].strip(".") in ext:
morphbr@565
    31
                media = os.path.join(root,name)
morphbr@565
    32
                if media not in file_list:
morphbr@565
    33
                    file_list.append(os.path.join(root,name))
morphbr@565
    34
morphbr@565
    35
    return True
morphbr@565
    36