gmyth-stream/server/lib.py
author rosfran
Mon Apr 16 20:05:45 2007 +0100 (2007-04-16)
branchtrunk
changeset 554 3ddc53d45d68
parent 516 f353f0da6f07
permissions -rw-r--r--
[svn r559] Added SET_TIMEOU messagte, in order to optimize the FileTransfer download.
renatofilho@484
     1
import time
morphbr@511
     2
import logging
morphbr@511
     3
import os
morphbr@511
     4
import stat
renatofilho@484
     5
morphbr@533
     6
ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
morphbr@516
     7
renatofilho@484
     8
def now():
renatofilho@484
     9
    return time.strftime("%Y-%m-%d %H:%M:%S");
renatofilho@484
    10
renatofilho@484
    11
def log(msg):
morphbr@511
    12
    logging.log(logging.DEBUG, msg)
renatofilho@484
    13
    new_msg = "[%s] %s" % (now(), msg)
renatofilho@484
    14
    return new_msg
morphbr@511
    15
morphbr@511
    16
morphbr@511
    17
bin_path_list = os.environ["PATH"].split(os.pathsep)
morphbr@511
    18
def which(prg):
morphbr@511
    19
    for d in bin_path_list:
morphbr@511
    20
        path = os.path.join(d, prg)
morphbr@533
    21
        if os.path.exists(path):
morphbr@511
    22
            st = os.stat(path)
morphbr@511
    23
            if st[stat.ST_MODE] & 0111:
morphbr@511
    24
                return path
morphbr@511
    25
    return ""
morphbr@511
    26
morphbr@516
    27
def list_media_files(directory, file_list):
morphbr@516
    28
    for root, dirs, files in os.walk(directory):
morphbr@516
    29
        for name in files:
morphbr@516
    30
            if os.path.splitext(name)[1].strip(".") in ext:
morphbr@516
    31
                media = os.path.join(root,name)
morphbr@533
    32
                if media not in file_list:
morphbr@533
    33
                    file_list.append(os.path.join(root,name))
morphbr@511
    34
morphbr@516
    35
    return True
morphbr@516
    36